"OAuth2 not granted or revoked" when trying to evaluate free trial in Chrome extension -
i'm attempting offer free trial period chrome extension , have been following chrome documentation how can accomplished.
when extension loads, though, background script logging following error console:
unchecked runtime.lasterror while running identity.getauthtoken: oauth2 not granted or revoked.
the console pointing @ call chrome.identity.getauthtoken
culprit. here's relevant code in background script:
var cws_license_api_url = 'https://www.googleapis.com/chromewebstore/v1.1/userlicenses/'; chrome.identity.getauthtoken({ 'interactive': false }, function(token) { console.log('token', token); var req = new xmlhttprequest(); req.open('get', cws_license_api_url + chrome.runtime.id); req.setrequestheader('authorization', 'bearer ' + token); req.onreadystatechange = function() { if (req.readystate == 4) { var license = json.parse(req.responsetext); console.log('license', license); } }; req.send(); });
my manifest setup (some pieces omitted brevity):
"manifest_version": 2, "key": "kkkkkkkkkkkkkkk", "background": { "scripts": [ "background.js" ] }, "permissions": [ "storage", "identity", "https://www.googleapis.com/" ], "oauth2": { "client_id": "cccccccccc.apps.googleusercontent.com", "scopes": [ "https://www.googleapis.com/auth/chromewebstore.readonly" ] }
here's i've tried or confirmed:
- the client id matches value in google developer console generated using extension's id.
- the chrome web store api enabled in google developer console (it api enabled).
- the key in manifest matches value generated after put extension on web store.
- calling
getauthtoken
interactive mode enabled results in same error. - i compared code this example , nothing jumps out @ me being substantially different (although pair of eyes confirm wouldn't hurt).
in case matters, i'm using chrome 42.0.2311.135 (64-bit) on mac os x.
any ideas causing error , need change make go away can lookup auth token , license?
code-wise, change needed enable interactive mode:
chrome.identity.getauthtoken({ 'interactive': true }, function(token) { ... });
there couple of pebcak issues going on. namely:
- it can take few seconds interactive auth page appear. seems bandwidth issue. may part of why documentation suggests triggering auth request on kind of user interaction , not when extension first loads.
- flipping interactive between
false
,true
, reloading extension not sufficient test of functionality. result ofgetauthtoken
cached. when revoke auth , refresh or delete , re-add extension same token continues returned amount of time. restarting chrome interactive mode enabled got me solution.
Comments
Post a Comment