16

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); 
            });
Xan
  • 74,770
  • 16
  • 179
  • 206
user2602584
  • 737
  • 2
  • 7
  • 25
  • possible duplicate of [Error: origin\_mismatch for Chrome extension](http://stackoverflow.com/questions/31134738/error-origin-mismatch-for-chrome-extension) – Madhan Jun 30 '15 at 18:37
  • No need to alter your question's title; everyone can see that there's an answer, and you can mark answers as accepted (though there may be a time delay before you can do this) further indicating that it does not need answering. – Xan Jul 01 '15 at 09:57
  • @Xan thanks for your info ! – user2602584 Jul 01 '15 at 10:18
  • 1
    I am facing the same issue but my app id is same as my id in chrome console – Sandeep Chikhale Jan 20 '18 at 08:29
  • I have this problem and it's killing me: https://stackoverflow.com/questions/48615964/xmlhttprequest-in-chrome-locks-up-browser – Alexander Mills Feb 05 '18 at 05:16

4 Answers4

14

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

user2602584
  • 737
  • 2
  • 7
  • 25
6

The accepted answer is incorrect. You can upload it to the webstore, publish it, then install it from the webstore. After installing, find the installed extension app dir (~/Library/Application\ Support/Google/Chrome/Default/Extensions/<ext id> on a mac), and copy the key key from the installed manifest.json into your source code manifest.json. After adding the key field to your manifest.json, your app id will not change during local development.

Source: https://developer.chrome.com/apps/app_identity#copy_key

austinheiman
  • 939
  • 1
  • 12
  • 17
  • 1
    That does not make any of the accepted answer invalid. Yes, you can prevent it from changing (and you described one of the ways), but the answer does not contain _any_ incorrect statements. – Xan Sep 03 '15 at 20:16
  • ok, the accepted answer is not the *ideal* solution. Just add your app to the webstore and publish it. You can publish it privately so its only available to you, or select email addresses to be able to download it. – austinheiman Sep 04 '15 at 21:49
  • 1
    i agree with @web-student-ksu ! since we are talking abt development, say i want to integrate a google + login then i need check it on the development environment bfr uploading it to webstore. i need key to make identity work. Xan accepted answer doesn't make any sense. – Rafique Mohammed Sep 26 '15 at 09:10
0

For other user, who might face the problem that chrome.identify.getauthtoken is not firing or you log in and nothing happens.

Check your manifest and reduce it to the bare minimum. For example the "oauth2": { "client.id": "alongstring" , "scopes": ["bla","openid", "bla"]}. Having openid in the array, the callback simply did not fire, no alert, no nothing.

Having openid inside my scopes inside oauth2 blocked in someway the callback from being fired.

0

If the callback in chrome.identity.getAuthToken is not firing at all for you, make sure you are using "browser_action" in your manifest.json and not "page_action".

umarniz
  • 21
  • 5