简体   繁体   English

Google gapi.auth2.getAuthInstance().isSignedIn().get() 在多个 google 帐户时始终为 false

[英]Google gapi.auth2.getAuthInstance().isSignedIn().get() is always false when multiple google accounts

I am having a weird problem with google gapi auth.我在使用 google gapi auth 时遇到了一个奇怪的问题。 For some reason, the value for gapi.auth2.getAuthInstance().isSignedIn().get() is always returning false.由于某种原因, gapi.auth2.getAuthInstance().isSignedIn().get()的值总是返回 false。 This is my setup:这是我的设置:

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

I have two google workspace accounts sign in the same chrome profile.我有两个 google 工作区帐户登录同一个 chrome 配置文件。 When I run this script, I get the prompt to select an account.当我运行此脚本时,我收到 select 帐户的提示。 No matter which one I choose, the flow just keeps looping.无论我选择哪一个,流程都在不断循环。 The reason for that is that the line const isSignedIn = googleAuth.isSignedIn.get();原因是const isSignedIn = googleAuth.isSignedIn.get(); is always returning false.总是返回假。

Things I've tried so far:到目前为止我尝试过的事情:

  1. I thought that maybe the client_id was corrupted so I generated a new one.我认为可能是 client_id 已损坏,所以我生成了一个新的。 Same behaviour.相同的行为。
  2. I though the GCP project was corrupted, so I created a new project with new credentials.我虽然 GCP 项目已损坏,所以我使用新凭据创建了一个新项目。 Same behaviour.相同的行为。
  3. Thought there was an issue with cookies, so I deleted and clear cookies and history.以为 cookies 有问题,所以我删除并清除了 cookies 和历史记录。 Same behaviour.相同的行为。
  4. Thought is was related only to localhost so I deployed to the web.以为只与本地主机有关,所以我部署到 web。 Same behaviour.相同的行为。

If I change the init options from ux_mode: "redirect" to ux_mode: "prompt" .如果我将初始化选项从ux_mode: "redirect"更改为ux_mode: "prompt" It works.有用。 However, that is not the desired experience.然而,这并不是我们想要的体验。 Also, if I only have one google workspace in the chrome profile, it works.此外,如果我在 chrome 配置文件中只有一个 google 工作区,它可以工作。 Even more interesting... if I use a client id from an older project... it works.更有趣的是……如果我使用旧项目中的客户 ID……它可以工作。 The problem is that the consent screen shows the wrong app name.问题是同意屏幕显示错误的应用名称。

I know this question is similar to this one , however I feel it's different because none of the above troubleshooting works.我知道这个问题与这个问题相似,但是我觉得它有所不同,因为上述故障排除都不起作用。 Any insights?有什么见解吗?

There is a case for the exact same problem here , it is most likely a bug in the api set 这里有一个完全相同的问题的案例,它很可能是 api 集中的错误

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM