Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you force AccountManager to show the "Access Request" screen after a user has already allowed access?

When using AccountManager::getAuthTokenByFeatures, an Access Request screen is shown for the user to allow or deny access to the account. After a user allows access, subsequent calls (with the same arguments) return the auth token without prompting the user.

How do you clear the state to make sure the Access Request prompt appears? (This would useful at the very least for development, testing, and demo purposes.)

like image 549
Russell Davis Avatar asked Jul 27 '11 23:07

Russell Davis


3 Answers

The only solution I've found is to manually clear out the data stored in the system's accounts.db. Run the following from the command line to clear out all account grants on the system.

For the emulator:

adb -e shell 'sqlite3 /data/system/accounts.db "delete from grants;"'

For a device (must be rooted and have the sqlite3 binary installed):

adb -d shell 'echo sqlite3 /data/system/accounts.db \"delete from grants\;\" | su'
like image 169
Russell Davis Avatar answered Oct 30 '22 08:10

Russell Davis


I have created a new account which I use for testing. A new account will always prompt for Access Request. Remember to NOT allow access.

To test for the login screen, change the password for the account from another device/PC.

like image 1
OferR Avatar answered Oct 30 '22 07:10

OferR


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.

like image 1
Benn Sandoval Avatar answered Oct 30 '22 08:10

Benn Sandoval