Google一键登录不返回idToken [英] Google one tap sign-in does not return idToken

查看:658
本文介绍了Google一键登录不返回idToken的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在按照此指南使新的Google一键式登录工作:

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

https://developers.google.com/identity/one -tap/web/入门

当我打电话时:

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"
    }
  ]
});

我在promise回调中得到一个响应,没有错误.但是idToken为空...

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); });

credential对象如下所示:

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

有人设法使它起作用吗?

Has anyone managed to get this to work?

推荐答案

我遇到了同样的问题,但是能够通过在 http://localhost:3000 "的URI,而不仅仅是"

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

在google页面上-如果您使用的是非标准端口,则必须将其包含在原始URI中."

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

这篇关于Google一键登录不返回idToken的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆