Authenticate chrome extension api
Hi I am developing a chrome extension and I need to authenticate a user based on a Google Plus account. I have implemented with Oauth 2.0. But there are some problems when I execute
chrome.identity.getAuthToken({ 'interactive': true }
No popup for authentication and I checked chrome: // identity-internals / . No token status found for my extension.
I followed all the steps for Chrome authentication and user authentication process
My extension's app id is the same as in Api Credentials (Console.developer.google)
I copied my public key to manifest.json
But there is no hope yet. i manually tried chrome.identity.getAuthToken on advanced background page, i got this error
Unchecked runtime.lastError while running identity.getAuthToken: OAuth2 not granted or revoked.
Copy my code here
manifest.json
{
"name": "Tinpack",
"manifest_version": 2,
"version": "0.1",
"permissions": [
"identity",
"tabs",
"https://accounts.google.com/*",
"https://www.googleapis.com/*"
],
"background": {
"scripts": ["scripts/background.js"]
},
"browser_action": {
"default_icon": {
"19": "images/icon.png",
"38": "images/icon.png"
},
"default_title": "Tinpack",
"default_popup": "index.html"
},
"oauth2": {
"client_id": "my client id"
"scopes": [
"https://www.googleapis.com/auth/plus.login"
]
},
"key": "my public key"
"content_security_policy": "script-src 'self' 'unsafe-eval' https://apis.google.com/; object-src 'self'"
}
Background.js
chrome.identity.getAuthToken({
'interactive': true
}, function(token) {
if (chrome.runtime.lastError) {
alert("Error");
} else {
console.log(token);
alert(token);
}
});
source to share