Google一键登录不returnidToken

Google one tap sign-in does not return idToken

我正在尝试按照本指南使用新的 google 一键登录:

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

当我打电话时:

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是空的...

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

有没有人设法让它工作?

我遇到了同样的问题,但可以通过在 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 处添加正确的 "Authorized JavaScript origins" 来解决。

来自 google 页面 - "If you're using a nonstandard port, you must include it in the origin URI."

我们刚刚发布了一些故障排除指南:https://developers.google.com/identity/one-tap/web/troubleshooting

要检查的最重要的事情如下:

  • 确保您在任何请求中提供 Google 客户端 ID,并且您所在的域 运行 代码是授权来源,包括端口。有关详细信息,请参阅文档

  • 确保您有一个有效的 Google 帐户并且启用了 Smart Lock 功能。尝试使用默认设置的常规 gmail 帐户

  • 检查您使用的是受支持的用户代理。重要的是,Chrome 开发工具中的 iOS 模拟模式已过时(待修复)

如果您仍然无法正常工作,或者有任何反馈,我们很乐意听取您的意见:联系 sso@google.com