问题描述
我正在开发一个自托管的Chrome扩展,并按照
现在将您的扩展ID从 chrome:// extensions /
复制并粘贴到 detail /
然后点击创建客户端ID。您的客户ID将被生成,现在将此客户ID复制并粘贴到 manifest.json
中
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.
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
这篇关于对于自我托管的Chrome扩展,不会调用chrome.identity.getAuthToken的回调的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!