google / google-api-javascript-client

Google APIs Client Library for browser JavaScript, aka gapi.
Apache License 2.0
3.21k stars 1.06k forks source link

window.gapi.auth2.getAuthInstance().signIn doesn't send callback in Chrome #571

Open Serginho opened 4 years ago

Serginho commented 4 years ago

I tested this with different browsers, operative systems and google accounts. We conclude:

When code fails is because window.gapi.auth2.getAuthInstance().signIn callback is not called after google login window/tab is closed.

It seems the client library isn't able to communicate with the window/tab.

SergeMakDev commented 4 years ago

We have the same problem on Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.29 Safari/537.36

.signIn({prompt: 'consent'}).then(function() {...}) doesn't call the code in .then() block after google login window is closed.

Further research showed that the problem appears on other builds of Chrome/79: "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.29 Safari/537.36" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.16 Safari/537.36" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/79.0.3945.0 Safari/537.36"

Chrome/78 and earlier works correctly.

steveetm commented 4 years ago

Run this code in console before pressing your login button: window.addEventListener('message',(...args)=>console.log(args))

You may see some relevant errors in the console afterwards.

Serginho commented 4 years ago

@steveetm Yes 3 event from dpi iframe.

"{"method":"fireIdpEvent","params":{"type":"sessionSelectorChanged","newValue":{"hint":... "{"method":"fireIdpEvent","params":{"type":"authResult","clientId":... "{"id":"xxx-xxxxxxxxxxx","result":{"error":"user_logged_out"},"rpcToken":...

In firefox works properly and send 4 messages.

SergeMakDev commented 4 years ago

Our further research showed that the problem has been fixed starting the build 79.0.3945.36

Serginho commented 4 years ago

@SergeMakDev In Chrome Canary OSX 80.0.3966.0's still not working and neither Chrome beta android 79.0.3945.36

Serginho commented 4 years ago

@grant Maybe could you please give us some additional information about this? We don't know if this issue will be fixed quickly or we have to make a fix using OAuth 2 REST api.

jordan-thoms commented 4 years ago

We're seeing this issue also, even with 79.0.3945.36. As it seems like a Chrome bug, has anyone reported it on the chromium bug tracker yet? I did some searching but couldn't find it.

Serginho commented 4 years ago

@jordan-thoms No we didn't report it cause we are not sure if it's actually a chrome bug, we know it doesn't work in chrome, but... what's the problem? the library is obfuscated so it's impossible to debug.

jordan-thoms commented 4 years ago

I've reported this at https://bugs.chromium.org/p/chromium/issues/detail?id=1024992 now, please add any additional information there and star the bug. It seems most likely that it's a Chrome issue as it is platform specific and worked in earlier versions.

steveetm commented 4 years ago

It is a duplicate of #561 . Just try to disable same-site cookies in chrome, and it will work. Check that thread and the report date.

steveetm commented 4 years ago

In a chrome thread I was told make sure that all third-party apis ready for this. And the third(?:D)-party api in this case is google-apis. Honestly, I don't know what is going on.

jordan-thoms commented 4 years ago

@steveetm Yeah you're right, disabling the flag fixes it. So the inconsistent behaviour here will just be depending on if you have the flag on/off as they are doing a partial rollout. I'm assuming Google will make sure this doesn't hit stable without at least updating their own services to be compatible!

Serginho commented 4 years ago

Any update on this? The problem still exists

iisa commented 3 years ago

Hello,

I am experiencing the same issue with not having the resolve callback fire after calling .signIn(options) -- I tested this with different browsers on Mac:

I've looked at the related issues around this promise not resolving properly, is there any update to chrome desktop experience?

I tried to circumvent the whole thing by using the signIn2.render button generator, but the success callback on load will fire too early, sometimes.

thanks in advance, looking forward to hearing from you. Best, Isa

felixmeziere commented 3 years ago

I have this exact same issue, still in mid-2021. On chrome for ios (only), the signin promise does not resolve most of the time (but sometimes it does). It works on all other platforms/browsers.

felixmeziere commented 3 years ago

@steveetm Yes 3 event from dpi iframe.

"{"method":"fireIdpEvent","params":{"type":"sessionSelectorChanged","newValue":{"hint":... "{"method":"fireIdpEvent","params":{"type":"authResult","clientId":... "{"id":"xxx-xxxxxxxxxxx","result":{"error":"user_logged_out"},"rpcToken":...

In firefox works properly and send 4 messages.

More specifically, I have this exact same probleme, with sessionSelectorChanged and "error":"user_logged_out"

ariccio commented 3 years ago

More specifically, I have this exact same probleme, with sessionSelectorChanged and "error":"user_logged_out"

I've was investigating this same problem yesterday, seeing the same user_logged_out error, and I was able to trace that to some weird issues with magic strings missing in cookies: https://github.com/anthonyjgrove/react-google-login/issues/451#issuecomment-858148763

ariccio commented 3 years ago

In my case, it was on an android device.

ariccio commented 3 years ago

x-ref: https://github.com/google/google-api-javascript-client/issues/367