Reputation: 3121
I'm using Google Play Services in my apps but lately I found something strange and I don't know how to deal with it.
If you are using Google Play Services you know that for the fist time, before you'll generate token you need to give your app permission (grant access) to use selected API.
After that, your app will be visible here: https://accounts.google.com/IssuedAuthSubTokens
And my app is there. Everything was working. I wanted to test it from the scratch, I revoke access to my app and ... it stops working. I can't force Google Play Services to show this window after revoking access to my app. I don't have permission to Google API but Google should show me permission window to re-add it.
Is there a way to show this window again?
I'm using GoogleAccountCredential.usingOAuth2 function to get user token and data (with all exceptions like UserRecoverableAuthIOException, startActivityForResult(e.getIntent(), REQUEST_AUTHORIZATION) ...).
As I understand, GoogleAccountCredential uses the Google Play Services to manage the OAuth2 flow and all you need to provide is the username. After revoking access it's not working.
Upvotes: 1
Views: 1406
Reputation: 903
Using Google Play Services:
http://developer.android.com/reference/com/google/android/gms/auth/GoogleAuthUtil.html
Add https://www.googleapis.com/auth/userinfo.profile to your scope.
Example:
String scope="oauth2:https://www.googleapis.com/auth/userinfo.email https://www.googleapis.com/auth/userinfo.profile"
final String token = GoogleAuthUtil.getToken(context, "[email protected]", scope);
OR "brute force"
Intent res = new Intent();
res.addCategory("account:[email protected]");
res.addCategory("scope:oauth2:https://www.googleapis.com/auth/userinfo.email https://www.googleapis.com/auth/userinfo.profile");
res.putExtra("service", "oauth2:https://www.googleapis.com/auth/userinfo.email https://www.googleapis.com/auth/userinfo.profile");
Bundle extra= new Bundle();
extra.putString("androidPackageName","com.your.package");
res.putExtra("callerExtras",extra);
res.putExtra("androidPackageName","com.your.package");
res.putExtra("authAccount","[email protected]");
String mPackage = "com.google.android.gms";
String mClass = "com.google.android.gms.auth.TokenActivity";
res.setComponent(new ComponentName(mPackage,mClass));
startActivityForResult(res,100);
Now, when you revoke the access here https://accounts.google.com/IssuedAuthSubTokens the application shows you the window for permission again in the device.
Upvotes: 3