Google one tap sign-in does not return idToken

瘦欲@ 提交于 2019-12-07 13:09:09

问题


I am trying to make the new google one tap sign in work following this guide:

https://developers.google.com/identity/one-tap/web/get-started

When I call :

const hintPromise = googleyolo.hint({
  supportedAuthMethods: [
    "https://accounts.google.com"
  ],
  supportedIdTokenProviders: [
    // Google can provide ID tokens -- signed assertions of a user's
    // identity -- which you can use to create more streamlined sign-in
    // and sign-up experiences.
    {
      uri: "https://accounts.google.com",
      clientId: "YOUR_GOOGLE_CLIENT_ID"
    }
  ]
});

I get a response in the promise callback, with no error. But the idToken is empty...

hintPromise.then((credential) => {
    if (credential.idToken) {                       // <= THIS IS ALWAYS FALSE!!!
        // Send the token to your auth backend.
        loginWithGoogleIdToken(credential.idToken);
    }
}, (error) => { console.log(error); });

the credential object looks like this:

{
  authDomain: "http://localhost:3000",
  authMethod: "https://accounts.google.com",
  displayName: "testName",
  id: "testEmail@gmail.com"
}

Has anyone managed to get this to work?


回答1:


I had the same issue, but was able to resolve it by adding the correct "Authorized JavaScript origins" at https://console.developers.google.com/ for my project. I needed to include the URI including the port "http://localhost:3000" rather than just "http://localhost".

From the google page - "If you're using a nonstandard port, you must include it in the origin URI."




回答2:


We just published some troubleshooting guidance: https://developers.google.com/identity/one-tap/web/troubleshooting

The most important things to check are the following:

  • make sure that you supply a Google client ID in any requests and that the domain you are running the code is an authorized origin, including the port. See documentation for details

  • ensure that you have an active Google Account and that the Smart Lock feature is enabled. Try with a regular gmail account with default settings

  • check that you are using a supported user-agent. Importantly, the iOS emulation modes in Chrome Dev Tools are out-of-date (fix pending)

If you still cannot get it working, or have any feedback at all, we'd love to hear from you: reach out to sso@google.com



来源:https://stackoverflow.com/questions/46977458/google-one-tap-sign-in-does-not-return-idtoken

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