Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

chrome.identity.getAuthToken not working

I am working with Chrome Identity API, to provide users with a Google Authentication on my Chrome Extension.

I followed the official tutorial of Google : link Chrome Identity API

  • i added permissions to manifest.json and Client ID and Scopes
  • to trigger the Authentification i added this code in my Background.js

chrome.identity.getAuthToken

The problem is when i execute the extension i am redirected to this login page

chrome://chrome-signin/?source=5

but after a successfull authentication i am redirected another time to the login page

what is the problem ?

Manifest.json

{
  "name": "My Extension",
  "short_name": "Ex App",
  "version": "0.1",
  "description": "description",
  "manifest_version": 2,
  "icons": { "128": "ICONE.png", "48": "ICONE1.png" },
  "permissions": ["contextMenus", "identity", "cookies", "http://*/*",   "https://*/*", "<all_urls>", "unlimitedStorage"],
  "browser_action": {
    "default_title": "Title",
    "default_icon": "imgIcone.png"
  },
  "oauth2": {
        "client_id": "xxxxxxx",
        "scopes": [
            "https://www.googleapis.com/auth/userinfo.email"
    ]   
},   

  "background": {
    "scripts": ["background.js"]
  },

    "content_scripts"   : [
{
  "matches": ["*://*.google.com/*"],
  "js": ["gadget/js/jquery.js","gadget/js/contactcard.js"],
  "css": ["gadget/css/contactcard.css"],
  "all_frames": true
  }],  

  "content_security_policy": "script-src 'self' 'unsafe-eval' https://apis.google.com/; object-src 'self'",
  "web_accessible_resources": ["img.png","gadget/css/contactcard.css","gadget/img/extension/crec.png"]
}

Background.js:

chrome.identity.getAuthToken({ 'interactive': true }, function(token) {
        // Use the token.
        console.log(token); 
            });
like image 838
user2602584 Avatar asked Jun 30 '15 14:06

user2602584


People also ask

How to implement OAuth in chrome extension?

# Create OAuth client ID Once ready, select Credentials in the sidebar, click Create credentials and choose OAuth client ID. On the Create client ID page, select Chrome App. Fill out the name of the extension and place the extension ID at the end of the URL in the Application ID field. Finish by clicking create.


1 Answers

Problem Resolved !

the app ID of my Chrome extension does not match with my app ID in Google Console Developpers To avoid this upload first your Extension then copy the ID from Chrome and set it in the Google Console Developpers ! you must update it in Google console everytime you change it in Google Chrome

enter image description here

like image 87
user2602584 Avatar answered Sep 24 '22 03:09

user2602584