I think I need to take some aspirin... banging my head to the wall... 3 days and still getting nowhere... I just don't get it...
From a Chrome extension I'm calling getAuthToken from background.js, it is probably the most basic script ever written:
function getAuthToken(){
chrome.identity.getAuthToken(
{'interactive': true},
function(token){
console.log(token);
}
);
};
Manifest snippet:
"content_security_policy": "script-src https://*.google.com 'unsafe-eval'; object-src 'self'",
"oauth2": {
"client_id": "<client_id>.apps.googleusercontent.com",
"scopes": ["https://www.googleapis.com/auth/gmail.modify"]
}
This is what happens:
- Load the extension
- OAuth2 is started, access to GMail is asked (pop-up) and granted
- Console log: token = undefined and Unchecked runtime.lastError while running identity.getAuthToken: Authorization page could not be loaded (lastError 133)
- In Chrome tokencache I see a new, but not present token (no token string)
- Reload the extension
- No Gmail access is asked
- Token is now correctly received
Why do I need to run getAuthToken twice? I use step 2 authentication for GMail but understood this only applies to the front end.
Please if you ran into something similar share it with me, it is so frustrating not getting any further than 5 lines of code.