如何通过弹出窗口中的OAuth 2.0与Google进行身份验证? [英] How to authenticate with Google via OAuth 2.0 in a popup?

查看:194
本文介绍了如何通过弹出窗口中的OAuth 2.0与Google进行身份验证?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

很抱歉要进行大量修改。我正在重新开始,因为我没有正确地陈述我的问题。

Sorry for a big edit. I am starting over as I am not stating my question correctly.

我正在尝试用HTML5编写客户端应用程序。我不希望它被托管在网站上。我甚至不确定这是否可行,我对这种类型的应用程序还不熟悉。

I am trying to write a client side app in HTML5. I do not want it to be hosted on a website. I am not even sure this is possible, I am fairly new to this type of application.

无论如何,我想访问Google服务,这需要验证OAuth等身份验证。因为它是javascript,听起来像OAuth2是我需要的。

Anyway, I want to access Google services, which requires authenticate such as OAuth. Being that it is javascript, it sounds like OAuth2 is what I need.

我试图在弹出窗口中打开google身份验证(我有这个部分),让用户允许访问,然后将流程传回我的应用程序,这可以然后查询Google服务。问题是1.它要求用户在我使用 response_type = code 时将令牌复制/粘贴到应用程序中,但如果我使用 response_type =令牌它要求我重定向回一个有效的URL,因为它没有托管在网络服务器上,所以没有。

I am trying to open up the google authentication in a popup (I have this part), let the user allow access, and then pass flow back to my application which can then query Google services. Problem is either 1. it asks the user to copy/paste a token into the app whenever I use response_type=code, but if I use response_type=token it requires that I redirect back to a valid URL which, since this is not hosted on a webserver, there is none.

那么如何我可以使用OAuth,并让用户无缝授予访问权限吗?

So how can I use OAuth, and let the user grant access seamlessly?

推荐答案

您应该为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.

这篇关于如何通过弹出窗口中的OAuth 2.0与Google进行身份验证?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆