【问题标题】:Removing permissions of the extensions删除扩展的权限
【发布时间】:2015-08-10 02:08:52
【问题描述】:

我有一个扩展程序,它首先请求访问 Google 云端硬盘文件的权限。扩展几乎是空的,除了在我加载这个 js 的弹出窗口中:

chrome.identity.getAuthToken({ 'interactive': true }, function(token) {
  // Use the token.
  console.log('Request Token')
  console.log(token)
  chrome.identity.removeCachedAuthToken(
              { 'token': token }, function () {})
  console.log('Removed token')
});

在我的清单中,我有有效的密钥、oauth2 客户端 ID 和 "scopes":["https://www.googleapis.com/auth/drive"] 除了其他用于 chrome 扩展的标准键。

它工作正常,它首先请求许可,然后记录我的访问令牌。但是,当我重新安装扩展程序(删除/修改/添加)时,它并没有征求我的许可,只是写了相同的访问令牌。我想再次请求许可。我怎样才能做到这一点?

【问题讨论】:

    标签: javascript google-chrome-extension google-drive-api access-token


    【解决方案1】:

    为了删除权限,我必须添加另一个 GET 请求来撤销权限:

    chrome.identity.getAuthToken({ 'interactive': true }, function(token) {
      // Use the token.
      if (token) {
            // Make a request to revoke token
            var xhr = new XMLHttpRequest();
            xhr.open('GET', 'https://accounts.google.com/o/oauth2/revoke?token=' +
                 token);
            xhr.send();
       }
      chrome.identity.removeCachedAuthToken(
                  { 'token': token }, function () {})
    });
    

    这就是诀窍,现在每次我打开弹出窗口时都会提示许可。

    还有另一个问题:当我授予权限时,我得到了

    XMLHttpRequest cannot load https://accounts.google.com/o/oauth2/revoke?token=... 
    No 'Access-Control-Allow-Origin' header is present on the requested resource. 
    Origin 'chrome-extension://acfnd...' is therefore not allowed access.
    

    我不确定是什么意思。

    【讨论】:

      【解决方案2】:

      在开发过程中,您可以前往chrome://identity-internals 撤销特定令牌。下次您授权该用户时,权限对话框将再次显示。记录在User Authentication: Caching

      【讨论】:

        【解决方案3】:

        一旦您授予权限,您当然不会再收到提示。您需要进入您的 Google 帐户页面并撤消该权限。

        【讨论】:

        • 是的,这是最好的方法,因为它与所有其他 oauth 流程一样。但答案是缺少更好的细节和链接。
        猜你喜欢
        • 2012-11-23
        • 1970-01-01
        • 2018-10-08
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2023-03-24
        相关资源
        最近更新 更多