Google登录错误:“popup_closed_by_user”

问题描述 投票:5回答:4

在设置并运行我自己的客户端ID后,我将完成登录过程并在弹出窗口中选择所需的Google帐户。

选择此选项后,登录失败,控制台中的错误为:

err = {error: "popup_closed_by_user"}

任何人都可以帮我解决这个问题

google-login
4个回答
3
投票

如果您正在使用端口测试localhost,那么我们应该在google开发者控制台上的add port number上授权的JavaScript起源部分,如下所示

http://localhost:3000

希望这能解决问题。


2
投票

当我想使用angular4-social-login登录时,即使我遇到同样的问题。这是因为浏览器中的cookie和弹出设置。它可以在IE中正常运行而不会出错。在Chrome设置中,转到更改Cookie设置中的内容设置并允许弹出窗口。然后清除缓存并重新加载。该应用程序。


0
投票

加载脚本后('//apis.google.com/js/platform.js'),在DOM中也会插入iframe,例如:

<body>
  ...
  <iframe aria-hidden="true" id="ssIFrame_google" sandbox="allow-scripts allow-same-origin" src="https://accounts.google.com/o/oauth2/iframe#origin=http%3A%2F%2Flocalhost%3A4200&amp;rpcToken=902946799.4541115&amp;clearCache=1" style="position: absolute; width: 1px; height: 1px; left: -9999px; display: none;"></iframe>
</body>

起初,我不明白谷歌为什么会这样做,所以我刚刚删除了这个元素:

const iframeElem = document.getElementById('ssIFrame_google');
if (iframeElem) {
  iframeElem.remove();
}

但是当我到达处理成功身份验证响应的阶段时,我遇到了您所描述的错误:popup_closed_by_user。 当我注释掉我的代码以删除iframe时 - 登录成功。

- 我可以假设您的浏览器会过滤内容并删除此iframe。


0
投票

更改端口号并再次运行应用程序。要更改端口号,您需要更新package.json文件下的端口号:

"scripts": {
    "start": "set PORT=3006 && react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test",
    "eject": "react-scripts eject"
 }

注意:此处端口号更改为3006。

现在,使用npm start运行应用程序。

© www.soinside.com 2019 - 2024. All rights reserved.