gpt4 book ai didi

javascript - 删除扩展程序的权限

转载 作者:数据小太阳 更新时间:2023-10-29 05:46:31 25 4
gpt4 key购买 nike

我有一个扩展程序,它首先请求访问 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')
});

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

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

最佳答案

为了删除权限,我必须添加另一个 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.

我不确定是什么意思。

关于javascript - 删除扩展程序的权限,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30491789/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com