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

前端 未结 4 1459
一生所求
一生所求 2020-12-03 05:52

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, subsequ

4条回答
  •  攒了一身酷
    2020-12-03 06:08

    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, "xxxx@gmail.com", scope);
    

    OR "brute force"

    Intent res = new Intent();
    res.addCategory("account:xxxx@gmail.com");
    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","xxxx@gmail.com");
    
    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.

提交回复
热议问题