Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google one tap sign-in does not return idToken

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: "[email protected]"
}

Has anyone managed to get this to work?

like image 370
edeboursetty Avatar asked Dec 18 '22 03:12

edeboursetty


2 Answers

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."

like image 199
jshaffer Avatar answered Jan 04 '23 03:01

jshaffer


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 [email protected]

like image 43
Steven Avatar answered Jan 04 '23 03:01

Steven