且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何通过弹出窗口中的OAuth 2.0与Google进行身份验证?

更新时间:2021-09-27 09:25:32

您应该为Google定义一些重定向网址以重定向到身份验证完成后。如果您无法在任何网站上托管您的网页,您可以很好地将其托管在本地主机上。

You should have some Redirect URL defined for Google to redirect to after the authentication is done. If you cant host your pages on any web site, you can very well host it in local host.

关于将访问令牌从弹出窗口获取到主父窗口,您可以在父窗口中设置一个计时器,它会继续检查弹出窗口的文档位置。一旦文档位置与重定向URL匹配,您就可以解析将在URL本身中的访问令牌。

Regarding getting the access token from the popup to the main parent window, you can setup a timer in parent window which keeps on checking the document location of the popup. Once the document location matches the Redirect URL, u can parse the access token which will will be in the URL itself.

我写了一个关于完全相同问题的教程(使用昨天,这里是链接:
http://www.gethugames.in/2012/04/authentication-and-authorization-for-google-apis-in-javascript-popup-window-tutorial.html

I wrote a tutorial on exactly the same problem (using local host) yesterday and here is the link: http://www.gethugames.in/2012/04/authentication-and-authorization-for-google-apis-in-javascript-popup-window-tutorial.html

希望您会发现它很有用。

Hope you will find it useful.