【问题标题】:Google gapi.auth2.getAuthInstance().isSignedIn().get() is always false when multiple google accounts谷歌 gapi.auth2.getAuthInstance().isSignedIn().get() 在多个谷歌账户时总是假的
【发布时间】:2021-04-29 14:22:27
【问题描述】:

我在使用 google gapi auth 时遇到了一个奇怪的问题。出于某种原因,gapi.auth2.getAuthInstance().isSignedIn().get() 的值总是返回 false。这是我的设置:

gapi.load("auth2", initAuth2);

initAuth2(){
    gapi.auth2.init({
      client_id: "xxxxx-yyyyy.apps.googleusercontent.com",
      hosted_domain: "domain.com",
      redirect_uri: "http://localhost:4200",
      ux_mode: "redirect",
    }).then(performAuth, error=>{
      console.error(`Error initiating gapi auth2: ${error.details}`);
    });
}

performAuth(googleAuth){
    const isSignedIn = googleAuth.isSignedIn.get();
    if(!isSignedIn){
      googleAuth.signIn();
      return;
    }
    const user = googleAuth.currentUser.get();
    console.log(user);
}

我有两个 google 工作区帐户登录同一个 chrome 配置文件。当我运行此脚本时,我会收到选择帐户的提示。无论我选择哪一个,流程都在不断循环。原因是 const isSignedIn = googleAuth.isSignedIn.get(); 行总是返回 false。

到目前为止我尝试过的事情:

  1. 我认为可能是 client_id 已损坏,因此我生成了一个新的。同样的行为。
  2. 虽然 GCP 项目已损坏,但我使用新凭据创建了一个新项目。同样的行为。
  3. 认为 cookie 有问题,所以我删除并清除了 cookie 和历史记录。同样的行为。
  4. Thought 仅与 localhost 相关,因此我将其部署到 Web。同样的行为。

如果我将初始化选项从 ux_mode: "redirect" 更改为 ux_mode: "prompt"。有用。然而,这并不是我们想要的体验。此外,如果我在 chrome 配置文件中只有一个 google 工作区,它可以工作。更有趣的是……如果我使用旧项目中的客户 ID……它可以工作!问题是同意屏幕显示错误的应用名称。

我知道这个问题类似于this one,但我觉得它有所不同,因为上述故障排除都不起作用。有什么见解吗?

【问题讨论】:

    标签: google-api google-signin google-api-js-client


    【解决方案1】:

    同样的问题here有一个案例,很可能是api集中的一个bug

    【讨论】:

      猜你喜欢
      • 2018-05-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-04-03
      • 1970-01-01
      • 2015-02-21
      • 1970-01-01
      • 2020-09-07
      相关资源
      最近更新 更多