4

我正在尝试按照本指南使新的谷歌一键登录工作:

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

我在承诺回调中得到响应,没有错误。但是 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"
}

有没有人设法让它工作?

4

2 回答 2

9

我遇到了同样的问题,但能够通过在https://console.developers.google.com/为我的项目添加正确的“授权的 JavaScript 来源”来解决它。我需要包含 URI,包括端口“ http://localhost:3000 ”,而不仅仅是“ http://localhost ”。

从谷歌页面 - “如果您使用的是非标准端口,则必须将其包含在原始 URI 中。”

于 2017-10-29T10:25:31.430 回答
2

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

最重要的检查事项如下:

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

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

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

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

于 2017-11-01T01:54:46.140 回答