Callback not called for chrome.identity.getAuthToken for self hosted chrome extension

て烟熏妆下的殇ゞ 提交于 2019-12-13 02:35:38

问题


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.


回答1:


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:

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



来源:https://stackoverflow.com/questions/31693754/callback-not-called-for-chrome-identity-getauthtoken-for-self-hosted-chrome-exte

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!