简体   繁体   中英

How to provide redirect URL for OAuth2 in Chrome extension?

I use the oauth2-extension to be able to access google-data from within a chrome-extension http://smus.com/oauth2-chrome-extensions/

I modified the manifest.json, entered the data in the JS and try to authenticate but get a error-response:

redirect_uri_mismatch [...] redirect_uri= http://www.google.com/robots.txt

I would love to add that url to the allowed redirect-urls but there is no such option when using a "native application" or "chrome application" I just cannot add Redirect URIs on the dev console in Google.

Any way to get around this?

Part of my manifest.Json:

"permissions": [
        "http://ajax.googleapis.com/",
        "storage",
        "https://accounts.google.com/o/oauth2/token"
    ],
    "content_scripts":
            [{
                    "matches": ["https://plus.google.com/*"],
                    "js": [
                        "setup/js/jquery-1.10.2.min.js",                        
                        "date.js"]
                },
                {
                    "matches": ["http://www.google.com/robots.txt*"],
                    "js": ["oauth2/oauth2_inject.js"],
                    "run_at": "document_start"
                }],

My JS-code:

var googleAuth = new OAuth2('google', {
  client_id: 'WHATEVER.apps.googleusercontent.com',
  client_secret: 'HIDDEN',
  api_scope: 'https://www.googleapis.com/auth/tasks'
});


function GetAuth()
{
    googleAuth.authorize(function() {
        alert('yippee ki yay!');
    });
}

(of course "HIDDEN" and "WHATEVER" contain the valid values)

There is an oauth example in the google extension samples that works fine, ive used it. But you should really migrate to chrome identity which does it all for you.

I had the same proble with, oauth2-extensions! I tried editing the adapter files adapters/google.js , as follows

 redirectURL: function(config) {
    return 'your-redirect-url'; // here default redirect URL is http://www.google.com/robots.txt
  }

This worked for me, however I am not sure, if there are any issues with this API modification, since in the documentation for oauth2-extensions nothing of this sort is mentioned.

Also, chrome.identity is the easiest option for this task!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM