我可以使用Android的AccountManager获取AppEngine的OAuth访问令牌吗?

Dav*_*vra 14 authentication google-app-engine android login oauth

我有Android客户端到我的AppEngine服务器,都使用Google帐户.我想使用AccountManager获取OAuth的accessToken.到目前为止,我正在使用ClientLogin,但我想切换到OAuth.

在AppEngine上设置OAuth很简单 - 我遵循了这篇文章.但客户端是一个谜,特别是我不知道用于范围的内容,在AccountManager术语authTokenType中.对于ClientLogin,我使用"ah"表示authTokenType.但OAuth呢?

Pat*_*ick 10

截至今天,您可以在Android上使用Google Play Services API在Android上进行Oauth 2.0身份验证.然后,您可以使用@nivco描述的方法获取appengine上的userinfo.我还没有这样做,但我计划完全按照你的说法去做.

https://developers.google.com/android/google-play-services/authentication


Nic*_*ier 6

我不确定您要通过您所指的文章中使用的App Engine OAuthService来做什么.另外,据说AppEngine OAuthService仅支持OAuth 1,但Android仅支持OAuth 2 :)所以你搞砸了.

如果你想跨Android - App Engine身份验证,我会做的是:

  1. 在Android中:从AccountManager 获取UserInfo API(scope = https://www.googleapis.com/auth/userinfo.emailhttps://www.googleapis.com/auth/userinfo.profile)的访问令牌.
  2. 在从Android到AppEngine的请求的URL参数中将访问令牌传递给App Engine(确保使用HTTPS以避免拦截!).
  3. 在App Engine端:使用访问令牌使用UserInfo API读取用户的身份.这基本上是使用OpenID Connect!
  4. 然后,您可以使用从UserInfo API获取的信息来验证用户身份.您将从UserInfo API获得的电子邮件和用户ID等同于您从AppEngine的UserService获得的电子邮件和用户ID =>您可以信任它!

PS:我在本文中描述了使用Android AccountManager获取OAuth 2令牌.它写在冰淇淋三明治之前,但我跳的它仍然有效.基本上authTokenType需要oauth2:{scopes},例如oauth2:https://www.googleapis.com/auth/tasks对于Tasks API.现在可能有更好的方法可以做到这一点.