简体   繁体   English

Chrome上的Google Auth API Javascript idpiframe初始化错误

[英]Google Auth API Javascript idpiframe initialization error on Chrome

I use GSuite and I'm coding a very simple web app to use Google Auth API, and I get an exception "idpiframe_initialization_failed". 我使用GSuite,我正在编写一个非常简单的Web应用程序来使用Google Auth API,我得到一个例外“idpiframe_initialization_failed”。

Now I have the exact HTML as shown in the google Sample: https://developers.google.com/api-client-library/javascript/samples/samples 现在我有谷歌示例中显示的确切HTML: https//developers.google.com/api-client-library/javascript/samples/samples

1) I've created a project on the Google Developer Console 1)我在Google Developer Console上创建了一个项目

2) I setup the OAUTH authorization screen 2)我设置了OAUTH授权屏幕

3) I've created the client ID, creating restrictions and redirection URL 3)我已经创建了客户端ID,创建了限制和重定向URL

4) I've also created the API KEY 4)我还创建了API KEY

5) Finally I've enabled the People API, because discovery services was failing when setting the discoveryDocs parameter 5)最后我启用了People API,因为在设置discoveryDocs参数时发现服务失败了

With all of these steps, When I call the gapi.client.init, it raises an exception ONLY in chrome , I cannot understand why. 通过所有这些步骤,当我调用gapi.client.init时,它仅在chrome中引发异常,我无法理解为什么。

The code for initializing the API is: 初始化API的代码是:

    gapi.client.init({
        apiKey: 'MY_API_KEY',
        discoveryDocs: ["https://people.googleapis.com/$discovery/rest?version=v1"],
        clientId: 'MY_CLIENT_ID.apps.googleusercontent.com',
        scope: 'profile'
    }).then(function (response) {
      // Listen for sign-in state changes.
      gapi.auth2.getAuthInstance().isSignedIn.listen(updateSigninStatus);

      // Handle the initial sign-in state.
      updateSigninStatus(gapi.auth2.getAuthInstance().isSignedIn.get());
    },function(reason){
        console.log('onerror');
        console.log(reason);
      // Listen for sign-in state changes.
      gapi.auth2.getAuthInstance().isSignedIn.listen(updateSigninStatus);

      // Handle the initial sign-in state.
      updateSigninStatus(gapi.auth2.getAuthInstance().isSignedIn.get());

The code is running the error block, and the message is: 代码正在运行错误块,消息是:

details: "Failed to read the 'localStorage' property from 'Window': Access is denied for this document."
error:"idpiframe_initialization_failed"

Any ideas why I'm coming into this error? 有什么想法我为什么会遇到这个错误?

Thanks! 谢谢!

I encountered the same issue. 我遇到了同样的问题。 After investing some time, found the reason. 投资一段时间后,找到了原因。 This error is because in chrome settings, you have the Block third-party cookies and site data option enabled. 此错误是因为在Chrome设置中,您启用了阻止第三方Cookie和站点数据选项。

It can be resolved by disabling this option: "To find the setting, open Chrome settings, type "Content settings" in the search box, click the Content Settings button, and view the fourth item under Cookies." 可以通过停用此选项来解决此问题:“要查找设置,请打开Chrome设置,在搜索框中输入”内容设置“,然后点击内容设置按钮,然后查看Cookie下的第四项。” Uncheck the box "Block third-party cookies and site data". 取消选中“阻止第三方Cookie和网站数据”框。

Hopefully this helps you in resolving your issue. 希望这有助于您解决问题。

在此输入图像描述

In my case, I just had to wait a bit for Google to take the origin into account. 在我的情况下,我只需等待谷歌考虑原点。 I cannot tell exactly how long it took. 我不清楚它花了多长时间。 I waited ~30min. 我等了~30分钟。 I then went to sleep and it was working the following morning. 然后我去睡觉,第二天早上工作。

Edit: Ooops I just realized I was using http:// and not https:// . 编辑:Ooops我刚刚意识到我使用的是http://而不是https:// That was the actual problem. 这是实际问题。

The problem is with Google's API console and how it handles creating credentials. 问题在于Google的API控制台以及它如何处理创建凭据。 It only seems to work when I access it through the following url https://developers.google.com/identity/sign-in/web/sign-in#before_you_begin There is a link that lets you create your app and the OAuth credentials. 当我通过以下网址访问它时,它似乎才起作用https://developers.google.com/identity/sign-in/web/sign-in#before_you_begin有一个链接可让您创建应用和OAuth凭据。 When I go to the console and create it through that screen it doesn't seem to work. 当我进入控制台并通过该屏幕创建它似乎不起作用。 After trying and re-create again and test with a fresh app I found out that the URL you add to the Authorized Javascript Origins doesn't always get added. 在尝试并重新创建并使用新应用程序进行测试后,我发现您添加到授权Javascript起源的URL并不总是被添加。

If everything is good then the url should be available in the credentials page 如果一切都很好,那么URL应该在凭证页面中可用 看这里的截图

I had the same problem and I searched for 3 days: Resolve " popup_closed_by_user" Go to your console.google go to your API MANAGE : Credentials:modify your credentials: 我遇到了同样的问题,我搜索了3天:解析“popup_closed_by_user”转到您的console.google转到您的API管理:凭据:修改您的凭据:

Authorized Javascript origin ( http://localhost:port ); 授权的Javascript源( http://localhost:port ); authorized redirect URI( http://localhost:port/auth/google/callback ); 授权重定向URI( http://localhost:port/auth/google/callback );

Example:|| 例如:|| Authorized Javascript origin ( http://localhost:4200 ); 授权的Javascript源( http://localhost:4200 ); authorized redirect URI ( http://localhost:4200/auth/google/callback ) 授权重定向URI( http://localhost:4200/auth/google/callback

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

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