代码之家  ›  专栏  ›  技术社区  ›  edeboursetty

Google one tap登录不返回idToken

  •  4
  • edeboursetty  · 技术社区  · 8 年前

    我正在努力使新的谷歌一键登录工作遵循以下指南:

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

    2 回复  |  直到 8 年前
        1
  •  9
  •   jshaffer    8 年前

    我也有同样的问题,但通过在上添加正确的“授权JavaScript源代码”解决了这个问题 https://console.developers.google.com/ 对于我的项目。我需要包含包含端口的URI“ http://localhost:3000 “而不仅仅是” http://localhost ".

    在google页面上,“如果您使用的是非标准端口,则必须将其包含在源URI中。”

        2
  •  2
  •   Steven    8 年前

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

    需要检查的最重要事项如下:

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

    • 确保您有一个活动的谷歌帐户,并且启用了智能锁功能。尝试使用默认设置的常规gmail帐户

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

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