对不起另一个可能是noob的问题,通常我不会放弃,直到我自己找到一个解决方案,但这个让我去了3天,现在是时候承认我被卡住了...
我正在尝试通过OAuth2验证Chrome扩展程序以使用PushBullet用户数据:
background.js
var client_id = '<32 DIGIT CLIENT ID>';
var redirectUri = "chrome-extension://lgekckejcpodobwpelekldnhcbenimbe/oauth2";
var auth_url = "https://www.pushbullet.com/authorize?client_id=" + client_id + "&redirect_uri=" + encodeURIComponent(redirectUri) + "&response_type=token";
chrome.identity.launchWebAuthFlow({'url':auth_url,'interactive':true}, function(redirect_url){
console.log(redirect_url)
});
Run Code Online (Sandbox Code Playgroud)
manifest.json的:
"permissions": [
"identity",
"*://*.google.com/*",
"*://*.pushbullet.com/*",
"storage"
],
"web_accessible_resources": [
"/oauth2/*"
Run Code Online (Sandbox Code Playgroud)
当我加载扩展时:
镀铬的扩展://lgekckejcpodobwpelekldnhcbenimbe/oauth2#access_token=o.zrrWrDozxMu6kftrMHb89siYJQhRVcoL
我没想到会打开一个空页面,而是让launchWebAuthFlow捕获了URI并将其写入控制台日志中,就像在回调函数中编码一样......但它似乎在等待......
现在唯一的选择是关闭此空白页面以查看以下记录:
运行identity.launchWebAuthFlow时未经检查的runtime.lastError:用户未批准访问权限.
很明显我错过了一些重要的东西...我需要在"某个地方"使用额外的代码来获取我的background.js中的回调URI吗?
谢谢,真的很高兴帮助.
暗影猎手
javascript identity callback google-chrome-extension oauth-2.0