Question

I wish to authenticate users of my android application whith the oauth2 protocole, so as to the user don't need to create a login and password for my app.

To do that, I follow the following tutorial : http://android-developers.blogspot.fr/2013/01/verifying-back-end-calls-from-android.html

I've import the google play service sdk sample (in AndroidSDK\extras\google\google_play_services\samples\auth), and I have change the scope value.

However, I don't manage to get authentication token... While I've correctly configure my google console API.

Here is the function calling getToken method :

  protected String fetchToken() throws IOException {
      try {
          return GoogleAuthUtil.getToken(mActivity, mEmail, mScope);
      } catch (GooglePlayServicesAvailabilityException playEx) {
          // GooglePlayServices.apk is either old, disabled, or not present.
          mActivity.showErrorDialog(playEx.getConnectionStatusCode());
      } catch (UserRecoverableAuthException userRecoverableException) {
          // Unable to authenticate, but the user can fix this.
          // Forward the user to the appropriate activity.
          mActivity.startActivityForResult(userRecoverableException.getIntent(), mRequestCode);
      } catch (GoogleAuthException fatalException) {
          onError("Unrecoverable error " + fatalException.getMessage(), fatalException);
      } 
      return null;
  }

And here is my scope : audience:server:client_id:MY_CLIENT_ID.apps.googleusercontent.com

When I try that, I get the following exceptions :

08-16 17:22:08.471: E/TokenInfoTask(16546): Exception: 
08-16 17:22:08.471: E/TokenInfoTask(16546): com.google.android.gms.auth.GoogleAuthException: Unknown
08-16 17:22:08.471: E/TokenInfoTask(16546):     at com.google.android.gms.auth.GoogleAuthUtil.getToken(Unknown Source)
Was it helpful?

Solution

You should be using Google+ Sign-In, which Google released in February, because this will get you cross-client authorization and access to more data that you can use to personalize your app. Behind the scenes, this authorization library uses OAuth 2 to connect to Google services.

Some resources to get you started:

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top