簡體   English   中英

我可以使用Android的AccountManager獲取AppEngine的OAuth訪問令牌嗎?

[英]Can I use Android's AccountManager for getting OAuth access token for AppEngine?

我有Android客戶端到我的AppEngine服務器,都使用Google帳戶。 我想使用AccountManager獲取OAuth的accessToken 到目前為止,我正在使用ClientLogin,但我想切換到OAuth。

在AppEngine上設置OAuth很簡單 - 我遵循了這篇文章 但客戶端是一個謎,特別是我不知道用於范圍的內容,在AccountManager術語authTokenType中 對於ClientLogin,我使用“ah”表示authTokenType 但OAuth呢?

截至今天,您可以在Android上使用Google Play Services API在Android上進行Oauth 2.0身份驗證。 然后,您可以使用@nivco描述的方法獲取appengine上的userinfo。 我還沒有這樣做,但我計划完全按照你的說法去做。

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

我不確定您要通過您所指的文章中使用的App Engine OAuthService來做什么。 另外,據說AppEngine OAuthService僅支持OAuth 1,但Android僅支持OAuth 2 :)所以你搞砸了。

如果你想跨Android - App Engine身份驗證,我會做的是:

  1. 在Android中:從AccountManager獲取UserInfo API的訪問令牌(范圍= 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用於任務API。 現在可能有更好的方法可以做到這一點。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM