Google Sign-In API Hang with uncaught error Failed to get parent origin from URL hash

断了今生、忘了曾经 提交于 2019-11-28 17:18:14

I can confirm we are experiencing the same problems at my company since recently. It seems a bit erratic, not 100% of the time. But for some users, some time, they are met with an empty sign-in popup with the url pointing to "https://accounts.google.com/o/oauth2/iframe" but nothing happens.

Not a complete answer yet, but this may be a reasonable workaround for some. I updated the ux_mode to use redirect and it is partially working now.

auth2 = gapi.auth2.init({
    client_id: '1234.apps.googleusercontent.com',
    scope: 'profile email',
    ux_mode: 'redirect',
    redirect_uri: 'https://blahblah.io/oauth2callback'
})

NOTE: it seems redirect_uri is required, contrary to Google's docs. This isn't a perfect drop-in replacement, but it solves the "URL hash!" error

This blog post and the Git Repo in it could also be helpful for anyone attempting to use redirect

My electron app started to fail today for the same reason. Been debugging quite a lot and I think found the reason, but don't know how to solve it, why it happened, or if it is electron or google's fault.

In my electron app, I have 2 webviews, one for the main content and another one for google popup dialogs.

So when google needs to open the authentication, it generates this IFRAME:

    <iframe id="ssIFrame_google" 
                sandbox="allow-scripts allow-same-origin" aria-hidden="true" 
                src="https://accounts.google.com/o/oauth2/iframe#origin=https%3A%2F%2Fxxxx.com&amp;rpcToken=dxxd318480305.4777704" 
                style="... display: none;"></iframe>

Mind that the URL has HASH parameters: your origin and the token.

However, when on the electron side I capture the new-window event in order to open the URL myself in another webview, the event I receive LACKS the hash parameters:

event { 
  type : "new-window",
  url:"https://accounts.google.com/o/oauth2/iframe",
  .
  .
}

So what google's iframe is complaining about (I debugged it) is exactly that it can't find the origin and rpctoken parameters that should be in the hash parameters.

For a reason I don't understand (I haven't updated electron) the new-window event does not receive the full url anymore.

Using @howMuchCheeseIsTooMuchCheese answer below I have changed the flow to use the redirect callback, then capture that callback myself and restart the application. It is not ideal, but at least I can login into my applications.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!