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

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/ 为我的项目添加正确的“Authorized JavaScript origins”来解决它。我需要包含包含端口“http://localhost:3000”的URI,而不仅仅是“http://localhost”。

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

10-08 03:11