Revoke access granted to my app Google Drive API

霸气de小男生 提交于 2020-08-21 06:13:53

问题


How do I revoke access that has been granted to my Google Drive web application so that upon the user's next use he is asked for permissions afresh?


回答1:


If you clobbered all the refresh tokens in your DB, adding the query parameter approval_prompt=force to the auth request will fix that. It'll result in the refresh tokens getting reissued when the user next approves the request.




回答2:


For revoking your access token, you need to "GET" (!) this url: https://accounts.google.com/o/oauth2/revoke?token={token} where {token} is the value of your token, as explained here: https://developers.google.com/accounts/docs/OAuth2WebServer#tokenrevoke

For Java API (don't know for other languages), as of 9th of Sept 2012, there is no API for this. I managed to revoke a token with this code:

class myGoogleApi {
    private static final HttpTransport HTTP_TRANSPORT = new NetHttpTransport();

    ...

    public revoke(String token) {
        HttpRequestFactory factory = HTTP_TRANSPORT.createRequestFactory();
        GoogleUrl url = new GoogleUrl("https://accounts.google.com/o/oauth2/revoke?token="+token);
        HttpRequest request = factory.buildGetRequest(url);
        HttpResponse response = request.execute();
        ...
    }



回答3:


Visit https://accounts.google.com/b/0/IssuedAuthSubTokens?hl=en for the list of applications and sites that you granted access to. Next to each of them you'll find a Revoke Access button.

The instructions to get to that page are at http://support.google.com/accounts/bin/answer.py?hl=en&answer=41236




回答4:


In order to revoke the access go to the below url

https://security.google.com/settings/security/permissions?pli=1

Choose your apps that you need to revoke and click on remove.




回答5:


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.



来源:https://stackoverflow.com/questions/12017445/revoke-access-granted-to-my-app-google-drive-api

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!