2

I'm using the code as explained in Authenticating against App Engine from an Android app to enable Google accounts auth on my GAE application. The problem is that once I've allowed my android app to access an account I'm not being able to repeat the process again (for testing) using the same account. I've tried:

  • invalidateAuthToken()
  • Clear data (Settings => Applications => Manage applications)
  • Uninstalling that app

But the app is still gaining access to that account. Below is the code snippet i use show the intent for user confirmation:

private class GetAuthTokenCallback implements AccountManagerCallback<Bundle> {
    public void run(AccountManagerFuture<Bundle> result) {
        Bundle bundle;
        try {
            bundle = result.getResult();
            Intent intent = (Intent)bundle.get(AccountManager.KEY_INTENT);
            if(intent != null) {
                // User input required
                startActivity(intent);
            } else {
                onGetAuthToken(bundle);
            }
        } catch (OperationCanceledException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (AuthenticatorException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
};

Have anyone faced this? Any idea how to force confirmation on the next run?

blue
  • 209
  • 1
  • 7

2 Answers2

1

Those permissions are kept in a system database. Your app should be removed after you uninstall it, but clearing the app data doesn't have any effect. If it is not working, might be a bug. Try on a different device and/or the emulator. The extreme measure that would probably work is factory reset :)

Nikolay Elenkov
  • 52,576
  • 10
  • 84
  • 84
  • I'm linking to these questions *[How do you force AccountManager to show the “Access Request” screen after a user has already allowed access?](http://stackoverflow.com/questions/6852256/how-do-you-force-accountmanager-to-show-the-access-request-screen-after-a-user) *[Unauthorize and App from AccountManager Credential Access](http://stackoverflow.com/questions/8206036/unauthorize-and-app-from-accountmanager-credential-access) , one of them has your answer. Thanks – blue May 14 '12 at 07:29
  • Right, if you have a rooted device (or running on the emulator) clearing the grants table will work. You could be a bit more subtle and delete only the entry(s) for your own app though. – Nikolay Elenkov May 14 '12 at 07:33
0

I've found a way cleaner solution. And a bit faster I think. You only need to perform 2 steps (1 & 2 from below; detailed steps are shown):

0) I don't think this extra step is necessary (haven't tried it without), but I've added it anyway. Just disconnect from the PlusClient in your app.

mPlusClient.clearDefaultAccount();
mPlusClient.disconnect();

1) Clear Data from the Google Play services app in the All apps screen (or Downloaded screen) from Settings on your device.

2) Revoke the permission for your app from the Connected applications and sites screen in the Privacy section from your Google Account on the web.

3) Well, connect again. It should work now. Repeat steps when needed.

Note: Steps 1 and 2 are crucial. If you only do step 1, it will just log in your app as usual, also displaying a Toast saying Welcome back to <app_name>. You're signed in as <account_name>

Bogdan Zurac
  • 6,348
  • 11
  • 48
  • 96