如何撤消已授予我的 Google Drive Web 应用程序的访问权限,以便在用户下次使用时重新要求他授予权限?
5 回答
要撤销您的访问令牌,您需要“获取”(!)此网址: https ://accounts.google.com/o/oauth2/revoke?token= {token} 其中 {token} 是您的令牌的值,如此处所述: https ://developers.google.com/accounts/docs/OAuth2WebServer#tokenrevoke
对于 Java API(不知道其他语言),截至 2012 年 9 月 9 日,没有用于此的 API。我设法用这段代码撤销了一个令牌:
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();
...
}
如果您破坏了数据库中的所有刷新令牌,将查询参数approval_prompt=force 添加到身份验证请求将解决该问题。当用户下一次批准请求时,它将导致重新发出刷新令牌。
要撤销访问权限,请访问以下网址
https://security.google.com/settings/security/permissions?pli=1
选择您需要撤消的应用程序,然后单击删除。
访问https://accounts.google.com/b/0/IssuedAuthSubTokens?hl=en以获取您授予访问权限的应用程序和网站的列表。在它们旁边,您会找到一个撤销访问按钮。
访问该页面的说明位于http://support.google.com/accounts/bin/answer.py?hl=en&answer=41236
使用 Google Play 服务:
http://developer.android.com/reference/com/google/android/gms/auth/GoogleAuthUtil.html
将https://www.googleapis.com/auth/userinfo.profile添加到您的范围。
例子:
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);
或“蛮力”
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);
现在,当您在此处撤销访问https://accounts.google.com/IssuedAuthSubTokens时,应用程序会再次在设备中向您显示权限窗口。