On Google App Engine, can I relate a Google OAuth

2019-03-20 06:00发布

I am writing a Google App Engine application along with a CLI client, an Android client and a Javascript client. The purpose of this application is to allow one to control an Android phone on which the Android client is installed, by using either the CLI or the Javascript client.

Authentication plays a crucial role as a bug might allow a malicious user to control others' phones.

The Android client is written and works. It authenticates the user using this method. Basically, this give me a so-called SACSID token I can store in a cookie. When this cookie is set App Engine recognizes my user. The server application can then call the UserService to get a User on which to call getUserId(). getUserId() returns me an opaque string that identifies my user. So far so good.

Now I am writing the JS and CLI clients. Because the CLI client has no reliable way of displaying a CAPTCHA or opening a browser, I suppose that it needs to use the Device API ("Client login" is not an option). This API requires using OAuth 2 for authentication. Also, I want the JS client to access the user's contacts, which also seems to indicates that OAuth 2 would be suitable.

If my user authenticates using OAuth 2, will I be hable to somehow transform this Google OAuth 2 token into the same opaque String that I get when the Android client connects ? If not, can I modifiy my Android Application so that it uses OAuth instead of a Sacsid token ?

To be more specific, I see three things that would solve my problem :

  1. A way of getting an OAuth 2 token from the Account Manager
  2. A way of exchanging the OAuth 2 token for a SACSID token
  3. A way of getting the same opaque UserID both with the SACSID token and the OAuth2, but only if I can have both authentication system on the same application.

Something that seems similar to the third possible solution is to get the user's email address from both OAuth and the SACSID token, and to use that as the user ID. This however looks a bit clumsy to me :

  • Every time I receive an OAuth 2 request, I would need to call Google APIs to retrieve the user's email address (or build my own system of tokens which seems insecure and introduces many other difficulties).
  • The email address of a given user can change, making me lose the association between the user and his previous data.

1条回答
The star\"
2楼-- · 2019-03-20 06:17

Use End Points instead:

https://developers.google.com/appengine/docs/java/endpoints/

They use oauth2, they are easy to implement and have support for android IOS and Web.

查看更多
登录 后发表回答