-
Notifications
You must be signed in to change notification settings - Fork 1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
gapi.auth.authorize callback doesn't get called when user closes window #25
Comments
From obr...@google.com on May 07, 2012 11:47:56 Status: Accepted |
From 0xED....@gmail.com on July 20, 2012 09:54:21 This is just to be polite and say goodbye to a customer who just slammed the door - I mean "closed the window". |
From obr...@google.com on August 02, 2012 09:52:38 Labels: Milestone-GA |
From tableYou...@gmail.com on September 30, 2013 02:36:25 There are 2 issues here:
Someone at google willing to help and get this fixed after over a year? Or where is the source code of this stuff? BTW: the docs are 'a bit' outdated and referring to this blog here (?) http://google-api-javascript-client.blogspot.de/ |
From vishal.4...@gmail.com on November 23, 2013 15:24:00 I think issue |
From KingRobe...@gmail.com on May 29, 2014 20:36:14 2 years later and no word. |
From rafalfel...@gmail.com on May 30, 2014 00:06:06 I would rather say that this future is nice to have. Why do some workarounds, not always nice and often not giving what we really want to achieve. |
This doesn't make for a great experience. Would be awesome to see this one fixed. |
Currently you can detect when the user clicks cancel by checking the error message in the authorization response. Demo here: http://wheresgus.com/secondchance/ You cannot detect when the user closes the window. |
Checking whether the window has closed turns out to be pretty trivial. Here's a demo: http://jsbin.com/wuxinoruze/1/ |
And here's a workaround. It'll fire whenever any opened window is closed. It works in the You could check the url contains
|
Hi @broady, I appreciate the help here! Its great that we can detect the window close though Im not sure if this can detect the difference between a successful closing of the dialog when auth succeeds or when the user closes the page. |
I have enhanced the workaround by @broady to match @i386 's issue. var authorizeDeferred;
function onClickLogin() {
(function(wrapped) {
window.open = function() {
// re-assign the original window.open after one usage
window.open = wrapped;
var win = wrapped.apply(this, arguments);
var i = setInterval(function() {
if (win.closed) {
clearInterval(i);
// cancel has no effect when the promise is already resolved, e.g. by the success handler
// see http://docs.closure-library.googlecode.com/git/class_goog_Promise.html#goog.Promise.prototype.cancel
authorizeDeferred.cancel();
}
}, 100);
return win;
};
})(window.open);
authorizeDeferred = gapi.auth.authorize({
// ...
}).then(onAuthResult, onRejected);
} |
@lukx the problem with that approach is that it assumes a successful authorization from Google gets back to us before the interval timer is run. So basically the code has two issues: First, we check at a resolution of 100ms but there is no guarantee that we check 100ms after the window closes. Second, it assumes Google gets back to us quickly. The solution for first is to debounce the The solution to the second would require some internal knowledge of when user successfully clicks before the network reqs to Google happens for the authorization. |
This issue still exists in the auth2 client (https://developers.google.com/identity/sign-in/web/reference), which uses promises. I would expect that clicking 'deny' or closing the window would resolve the promise with an error. However, neither the success or error methods of the promise are called. FWIW, @lukx's workaround seems to work pretty well. |
Yea, why fix bugs when we can just bloat our code with workarounds! |
The bug is still present :( |
Please try the newer gapi.auth2 API and let us know whether the problem persists |
@bsittler yep, the problem persists :(
On click event handler:
No matter what I do (click Deny button, close window) error handler never fires so as onSignIn. If I click Approve button onSignIn fires as expected. |
Thanks for the report, I've passed it on to those working on |
Just noticed exactly the same behavior as @DarkSilence |
Hi @DarkSilence, we are working on a fix, I will update this thread when it is released. |
Hi @DarkSilence @renarsvilnis @neilsoult @alalonde @Hengjie @lukx @i386 @broady @gguuss, the fix has now been released for
Thanks for your patience! Could one of you make sure you observe that it works, so I can close this issue? |
Hello @TMSCH I don't see this working for me. GoogleAuth.grantOfflineAccess()
.then( response => {
dispatch( signUp() )
})
.catch( error => console.log(`ERROR —— GAPI AUTH —— ${error}`) ) I get an error saying that there's no catch function. is that normal? |
@bernatfortet it is not normal, the |
Dispatch is part of Redux, it returns a promise, could that be problematic? I've solved the issue by doing the following: GoogleAuth.grantOfflineAccess()
.then( response => {
myFunction()
}, error => {
console.log(`ERROR —— GAPI AUTH —— ${error}`)
}) |
@bernatfortet it could be... The best way to know would be to not use it in the resolution callback of the |
From phenome on March 27, 2012 11:47:59
What steps will reproduce the problem? 1. Fire gapi.auth.authorize(). Wait for popup to open
2. Close the window What is the expected output? What do you see instead? Callback should be called with null parameter, or a token object with error, as per API.
When you DENY the authorization, the callback gets called with null.
::: Reading the API I assumed it would get called with a token object with the error parameter set. Is it really misleading or my interpretation is lacking?
I actually have no problem with it being called with null, but since there are two cases (the user actively DENYING authorization, or simply closing the window), it would be nice to get a token object with an error describing what happened.
Original issue: http://code.google.com/p/google-api-javascript-client/issues/detail?id=23
The text was updated successfully, but these errors were encountered: