vjain27
vjain27

Reputation: 3674

Oauth authentication error in chrome extension

I am trying to implement Oauth in a chrome extension by following this article - https://developer.chrome.com/extensions/tut_oauth

My background html looks like this -

<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>

And background.js looks like below :

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);
        });
    });
})();

All I need is the user's name and profile pic. However, whenever I click the Allow Access button on the authorization page it hangs and I see the following error in devtools console :

Denying load of chrome-extension://bdbfmncpogdjadbpjblpnffkoemdbdkc/chrome_ex_oauth.html? ch…-kwZoT0nwJa-lHnl_23BvUpjrdbjVBBIk0&oauth_verifier=rOR3c-1m8HDSN-v84BH_fr37. Resources must be listed in the web_accessible_resources manifest key in order to be loaded by pages outside the extension.

I am not sure how to fix it. Is there another way of implementing Oauth in an extension?

Upvotes: 1

Views: 501

Answers (1)

Dayton Wang
Dayton Wang

Reputation: 2352

You need to put "web_accessible_resources" in your manifest and without "chrome-extension://" prefix like:

"web_accessible_resources": [

    "chrome_ex_oauth.html"

  ],

Upvotes: 3

Related Questions