Authenticating with OAuth2 for an app *and* a website
===

I'm developing a website that is primarily accessed via an app, and I want to use OAuth2 for user registration and authentication. Since it is an Android app I will start using Google's OAuth2 stuff, since it provides a decent UI on Android.

Google states that ["You can choose to use Google's authentication system as a way to outsource user authentication for your application. This can remove the need to create, maintain, and secure a username and password store."](https://developers.google.com/accounts/docs/OAuth2Login) which is what I want to do. *However* when I go through all their examples and whatnot, I can only find stuff about having a website *or* an app authenticate a user against Google's services.

And indeed, when I go to register my app ("client") with Google's OAuth2 there are options for website clients and "installed" clients (i.e. a mobile app) but not both. I can create two separate clients but I read the OAuth2 draft and I think there will be a problem, which I will now explain.

Here's how I did envisage it working:

![OAuth2 flow diagram][1]

1. User asks MyApp to access his private data.
2. App uses Android's `AccountManager` class to request an access token for Google's APIs.
3. Android says to used "The app 'MyApp' wants access to your Basic Information on Google. Is this ok?"
4. User says yes.
5. `AccountManager` connects to Google's OAuth2 server using the credentials stored on the phone, and asks for an access token.
6. Access token (which follows the green lines) is returned.
7. `AccountManager` returns the access token to MyApp.
8. MyApp sends a request to MySite for the user's private data, including the access token.
9. MySite needs to verify the user, using the access token. It validates the token [as described here](https://developers.google.com/accounts/docs/OAuth2Login#validatingtoken), with Google - "Google, is this token valid?".
10. Now, what I *want* to happen is that Google says "Yes, whoever gave it to you is indeed that user.", but what I think will actually happen (based on the OAuth2 draft and Google's documentation) is that it will say "No way! That token is only valid for MyApp, and you're MySite. GTFO!".

So how should I do this? And PLEASE don't say "Use OpenID" or "Don't use OAuth2" or other similarly unhelpful answers.

  [1]: http://i.stack.imgur.com/3oDJt.png