我试图通过以下文章在chrome扩展中实现Oauth - https://developer.chrome.com/extensions/tut_oauth
我的背景HTML看起来像这样 -
<html>
<head>
<script type="text/javascript" src="chrome_ex_oauthsimple.js"></script>
<script type="text/javascript" src="chrome_ex_oauth.js"></script>
<script type="text/javascript" src="background.js"></script>
</head>
</html>
background.js如下所示:
var oauth = ChromeExOAuth.initBackgroundPage({
'request_url': 'https://www.google.com/accounts/OAuthGetRequestToken',
'authorize_url': 'https://www.google.com/accounts/OAuthAuthorizeToken',
'access_url': 'https://www.google.com/accounts/OAuthGetAccessToken',
'consumer_key': 'anonymous',
'consumer_secret': 'anonymous',
'scope': 'https://www.googleapis.com/auth/userinfo.profile',
'app_name': 'Chrome Extension Sample - Accessing Google Docs with OAuth'
});
(function(){
console.log('Getting posts');
oauth.authorize(function(){
console.log('authorizing....');
var url = 'https://www.googleapis.com/auth/userinfo.profile';
oauth.sendSignedRequest(url, function(text, xhr){
console.log(text);
});
});
})();
我需要的只是用户的姓名和个人资料照片。但是,每当我单击授权页面上的“允许访问”按钮时,它就会挂起,我在devtools控制台中看到以下错误:
拒绝加载chrome-extension://bdbfmncpogdjadbpjblpnffkoemdbdkc/chrome_ex_oauth.html? CH ... -kwZoT0nwJa-lHnl_23BvUpjrdbjVBBIk0和放大器; oauth_verifier = rOR3c-1m8HDSN-v84BH_fr37。 资源必须列在web_accessible_resources清单键中,以便由扩展名外的页面加载。
我不确定如何修复它。是否有另一种在扩展中实现Oauth的方法?
答案 0 :(得分:3)
您需要在清单中加上“web_accessible_resources”,而不使用“chrome-extension://”前缀,如:
"web_accessible_resources": [
"chrome_ex_oauth.html"
],