Ser*_*nov 5 javascript google-chrome-extension access-token google-drive-api
我有一个扩展,首先要求访问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')
});
Run Code Online (Sandbox Code Playgroud)
在我的清单中,我有有效的密钥,oauth2客户端ID,以及
"scopes":["https://www.googleapis.com/auth/drive"]chrome扩展的其他标准密钥.
它正常工作,它首先被要求许可,然后记录我的访问令牌.但是,当我重新安装扩展(删除/修改/添加)时,它没有请求我的许可,只是写了相同的访问令牌.我想再次请求许可.我怎样才能做到这一点?
为了删除权限,我必须添加另一个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 () {})
});
Run Code Online (Sandbox Code Playgroud)
这就是诀窍,现在每次打开弹出窗口时都会有提示许可.
但是还有另一个问题:当我获得许可时,我会得到
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.
Run Code Online (Sandbox Code Playgroud)
我不确定是什么意思.
| 归档时间: |
|
| 查看次数: |
760 次 |
| 最近记录: |