1

I am developing a self hosted chrome extension and have generated the key and client_id as described here. My call to getAuthToken is (copied from the answer to this question)

chrome.identity.getAuthToken({
    interactive: true
}, function(token) {
    if (chrome.runtime.lastError) {
        alert(chrome.runtime.lastError.message);
        return;
    }
    var x = new XMLHttpRequest();
    x.open('GET', 'https://www.googleapis.com/oauth2/v1/userinfo?alt=json&access_token=' + token);
    x.onload = function() {
        alert(x.response);
    };
    x.send();
});

However I find that while the user is correctly directed to the google login page, my call back is never called after the user is correctly authenticated. My question: Is it the case that I have to register my application with Google (rather than use a self-generated key pair, key and client_id) for my callback to be called? For a test application registered with google, the same callback is correctly called.

My manifest file has

    "permissions": [
        "background",
        ...
        "identity",
        "*://*/*"
    ],
    "key" : "Long key here",
    "oauth2" : {
            "client_id" : "Id of length 32",
            "scopes" : [
                "https://www.googleapis.com/auth/plus.login"
            ]
    }

Thank you.

Community
  • 1
  • 1
Gurunandan Bhat
  • 3,544
  • 3
  • 31
  • 43
  • Post your manifest file – Siddharth Jul 29 '15 at 07:28
  • Posted above for your reference Thanks @Sid – Gurunandan Bhat Jul 29 '15 at 07:47
  • Are you trying to keep your ID constant? – Siddharth Jul 29 '15 at 07:59
  • Check out this : http://stackoverflow.com/questions/21497781/how-to-change-chrome-packaged-app-id-or-why-do-we-need-key-field-in-the-manifest – Siddharth Jul 29 '15 at 08:04
  • I am developing locally and yes, my app id is constant. I have the key field in my manifest (like your link above advises). The oauth2.client_id field is just the app id - and I wonder if that is the source of the problem. I tried to generate a separate client_id for OAuth2 requests and selected "Installed Application"->"Other" for the category. But that too failed. – Gurunandan Bhat Jul 29 '15 at 12:33

1 Answers1

4

You are using wrong client id. To generate a valid client id:

Go to https://console.developers.google.com and create a client id under credentials. Also make sure your product has a name which can be filled under consent screen. Select Installed application and Chrome Application:

enter image description here

Now copy your extension ID from chrome://extensions/ and paste it after detail/ then click create client ID. Your client ID will be generated, now copy and paste this client ID in your manifest.json

Siddharth
  • 6,966
  • 2
  • 19
  • 34
  • I did that and I find that the callback is now executed. However I have chrome.runtime.lastError now and its value is {message: "OAuth2 not granted or revoked."} – Gurunandan Bhat Jul 29 '15 at 13:33
  • 1
    Sincere apologies!! It works now - After implementing your suggestion I had changed interactive to false. I changed it to true and changed the client_id per your suggestion and it works. Sorry - once again and thanks – Gurunandan Bhat Jul 29 '15 at 13:41