javascript - Connecting Chrome Extension to StackExchange oAuth API -


tl;dr -- trying build chrome extension displays number of current notifications user stackoverflow.

i following chrome extension tutorial on creating extension utilizes oauth. swapping out google oauth bits (what think are) stackexchange api bits, end following in background.js file:

var oauth = chromeexoauth.initbackgroundpage({     //es6 template strings!     'request_url'   : `https://stackexchange.com/oauth?client_id=${stack_app.id}&scope=read_inbox,no_expiry`,       'authorize_url' : 'https://stackexchange.com/oauth/login_success',     'access_url'    : 'https://stackexchange.com/oauth/access_token',      'consumer_key'    : stack_app.key,     'consumer_secret' : stack_app.secret,      //'scope'    : '', //not sure need this...      'app_name' : 'stackoverflow notifications (chrome extension)' });  oauth.authorize(function () {     console.log('authorize...'); }); 

when run extension locally, attempts open new browser tab complete oauth handshake -- great, except end @ following url: https://stackexchange.com/oauth/login_success?oauth_token=undefined

the browser tab gets stuck here.enter image description here

i'm not sure problem - don't know if have wrong urls listed in initbackgroundpage() call, or if stackapp has wrong oauth domain (since it's chrome extension... this question didn't answer things me).

any ideas appreciated!

from can tell, oauth tutorial mentioned in op outdated -- no longer need of that, can use chrome.identity instead.

to clear, there few things had do:

stack_app = {     id           : 1234,     scope        : 'read_inbox,no_expiry',      request_uri  : 'https://stackexchange.com/oauth/dialog',     redirect_uri : chrome.identity.getredirecturl("oauth2") };  //es6 template string! var requesturl = `${stack_app.request_uri}?client_id=${stack_app.id}&scope=${stack_app.scope}&redirect_uri=${stack_app.redirect_uri}`;   //https://developer.chrome.com/extensions/identity //https://developer.chrome.com/extensions/app_identity#update_manifest chrome.identity.launchwebauthflow({     url         : requesturl,     interactive : true }, function (url) {     console.log('redirected to: ' + url); }); 

note redirect_uri -- ends being subdomain of chromiumapp.org, need list in stackapps domain app (allowing oauth continue).


Comments

Popular posts from this blog

OpenCV OpenCL: Convert Mat to Bitmap in JNI Layer for Android -

android - org.xmlpull.v1.XmlPullParserException: expected: START_TAG {http://schemas.xmlsoap.org/soap/envelope/}Envelope -

python - How to remove the Xframe Options header in django? -