从获得的AccountManager一个基本的谷歌身份验证令牌 [英] Obtaining a basic google auth-token from AccountManager

查看:603
本文介绍了从获得的AccountManager一个基本的谷歌身份验证令牌的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从我可以发到我的web服务(而不是托管在App Engine)的的AccountManager获得谷歌的authToken认证用户(我只需要电子邮件地址,并最终他的名字,是否需要为这个没有权限)。

I want to obtain a Google Authtoken from the AccountManager that I can send to my Webservice (not hosted on App Engine) to authenticate the User (I just need the email address and eventually his name, if no permission is required for this).

我有什么用getAuthToken的方法,为authTokenType放慢参数?

What do I have to use for the "authTokenType" Paramter of the "getAuthToken" method?

和其中谷歌的API这样我必须使用来获取用户的电子邮件吗?

And which google Api do I have to use to get the Users Email?

推荐答案

这是可行的使用OpenID登录连接,但是这有点实验性的,所以细节可能会在未来改变。如果你得到一个OAuth的标记为'https://www.googleapis.com/auth/userinfo.email或https://www.googleapis.com/auth/userinfo.profile'的范围,你可以用它来获得从 https://www.googleapis.com/oauth2/v1/userinfo 用户信息(包括电子邮件)。当然,用户需要授权此。

This is doable using OpenID Connect, however it's sort of experimental, so details could change in the future. If you get an OAuth token for the 'https://www.googleapis.com/auth/userinfo.email' or 'https://www.googleapis.com/auth/userinfo.profile' scope you can use it to get user info from https://www.googleapis.com/oauth2/v1/userinfo (including email). Of course the user needs to authorize this.

您应该在理论上可以使用oauth2如下:https://www.googleapis.com/auth/userinfo.profile来从 AcccountManager 令牌作为标记类型,但是这似乎并没有工作,我的设备(Galaxy Nexus的与股票4.0.4)上。由于通过的AccountManager 不起作用得到一个令牌(至少目前如此),唯一可靠的方法是使用一个web视图,并通过浏览器得到一个如下所述: https://developers.google.com/accounts/docs/MobileApps

You should theoretically be able to get the token from AcccountManager using the "oauth2:https://www.googleapis.com/auth/userinfo.profile" as the token type, but that doesn't appear to work on my device (Galaxy Nexus with stock 4.0.4). Since getting a token via the AccountManager doesn't work (at least for now), the only reliable way is to use a WebView and get one via the browser as described here: https://developers.google.com/accounts/docs/MobileApps

这里有一个演示Web应用程序,这是否: https://oauthssodemo.appspot.com

There is a demo web app here that does this: https://oauthssodemo.appspot.com

(晚)更新:谷歌播放服务已经发布,它是preferred的方式来获得一个OAuth的令牌。它应该可以与Android 2.2及更高版本的所有设备。获取配置文件标记并使用它,其实他们使用它在演示程序

(late) Update: Google Play Services has been released and it is the preferred way to get an OAuth token. It should be available on all devices with Android 2.2 and later. Getting a profile token does work with it, in fact they use it in the demo app

这篇关于从获得的AccountManager一个基本的谷歌身份验证令牌的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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