IITCm for Android: gapi.auth2.authorize limitation
See original GitHub issuegapi.auth2.authorize
looks ok to be used in IITC, using either the google ingress account or another google account.
But, on android device, the webview seems to break the gapi auth process as long as we ask the user for a prompt (consent
or select_account
).
Apparently, the google popup is forbidden to close itself nor to send data back to the original window.
I don’t know if this is some absolute limitation of android + gapi or if a solution exists. (android code or javascript). I explored javascript side without finding answer.
Example of authentication script (ask for a token)
// @author jaiperdu
// @name Authentication test
// @category Misc
// @version 0.1.0
// @description Simple authentication test
// use own namespace for plugin
window.plugin.authTest = function() {};
window.plugin.authTest.dialogHTML = null;
// web app client id with auth screen allowing https://intel.ingress.com as origin
window.plugin.authTest.CLIENT_ID = 'CLIENTID.apps.googleusercontent.com';
window.plugin.authTest.SCOPES = 'openid profile email';
window.plugin.authTest.TYPE = 'id_token permission';
window.plugin.authTest.authorize = function() {
const options = {
prompt: 'select_account', // or 'consent' (use 'none' for implicit auth if possible)
client_id: this.CLIENT_ID,
scope: this.SCOPES,
response_type: this.TYPE
};
window.gapi.auth2.authorize(options, response => {
if (response.error) {
const err = `error: ${response.error}: ${response.error_subtype}`;
alert(err);
console.log(err);
return;
}
alert(response.access_token);
console.log(response.id_token, response.access_token);
});
};
window.plugin.authTest.setupDialog = function() {
$('#toolbox').append('<a id="authTest-authorize" onclick="window.plugin.authTest.authorize();">AuthTest</a> ');
};
var setup = function() {
if (typeof window.gapi !== "undefined") {
window.gapi.load("auth2", () => {
window.gapi.auth2.enableDebugLogs(true);
});
}
else {
const script = document.createElement("script");
script.type = "text/javascript";
script.async = true;
script.defer = true;
script.src = "https://apis.google.com/js/platform.js";
script.onload = () => {
window.gapi.load("auth2", () => {
window.gapi.auth2.enableDebugLogs(true);
});
};
(document.body || document.head || document.documentElement).appendChild(
script
);
}
window.plugin.authTest.setupDialog();
};
Issue Analytics
- State:
- Created 3 years ago
- Comments:5 (5 by maintainers)
Top Results From Across the Web
Sync's method for G-authorize causes conflicts #334 - GitHub
The sync plugin was changed from using gapi.auth2.authorize() to ... IITCm for Android: gapi.auth2.authorize limitation #362.
Read more >Google Sign-In JavaScript client reference | Authentication
gapi.auth2.authorize( params , callback ). Performs a one time OAuth 2.0 authorization. Depending on the parameters used ...
Read more >Release IITC-CE v0.31.1 - Reddit
On the first day of new year, we present you big update of IITC-CE, containing many accumulated improvements and fixes.
Read more >gapi authorize returns access_denied from website on mobile ...
checkAuth: function () { var self = this; gapi.auth2.authorize({ ... API restrictions: 'Gmail API'; Application restrictions: none.
Read more >Setting up OAuth 2.0 - Google Cloud Platform Console Help
To use OAuth 2.0 in your application, you need an OAuth 2.0 client ID, which your application uses when requesting an OAuth 2.0...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I found a workaround for android source. From https://stackoverflow.com/questions/23308601/android-open-pop-up-window-in-my-webview and https://stackoverflow.com/questions/23211722/window-close-not-working-in-android-webview (and some other I lost the track)
This is a PoC and aims simplicity (with the cost of safety). I almost have no idea what I am doing, but it works so far.
I don’t know, I didn’t test against this It’s a weak relation
IITC is blocking popup while google uses ones in some cases.
after a second reading, the “Advenced Protection” looks like it needs the webview to access some device key that out of scope of this issue