chrome.identity.getAuthToken不起作用

use*_*584 14 google-chrome-extension google-oauth google-chrome-app

我正在使用Chrome Identity API,以便在Chrome扩展程序中为用户提供Google身份验证.

我按照谷歌的官方教程: 链接Chrome Identity API

  • 我添加了manifest.json客户端ID范围的权限
  • 为了触发Authentification,我在Background.js中添加了这段代码

chrome.identity.getAuthToken

问题是,当我执行扩展时,我被重定向到此登录页面

铬://铬登入/源= 5

但在成功验证后,我又被重定向到登录页面

问题是什么 ?

的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"]
}
Run Code Online (Sandbox Code Playgroud)

Background.js:

chrome.identity.getAuthToken({ 'interactive': true }, function(token) {
        // Use the token.
        console.log(token); 
            });
Run Code Online (Sandbox Code Playgroud)

use*_*584 13

问题已解决!

应用程序ID我的Chrome extension不匹配我的应用程序IDGoogle Console Developpers 要先避免这种上传您的扩展,则ID从Chrome中复制,并将其设置在谷歌控制台Developpers!每次在Google Chrome中更改时,您都必须在Google控制台中更新它

在此输入图像描述


aus*_*man 5

接受的答案是不正确的.您可以将其上传到Webstore,发布它,然后从Webstore安装它.安装后,找到已安装的扩展应用程序目录(~/Library/Application\ Support/Google/Chrome/Default/Extensions/<ext id>在Mac上),然后将key安装的密钥复制manifest.json到源代码中manifest.json.key向您添加字段后manifest.json,您的应用ID在本地开发期间不会更改.

资料来源:https://developer.chrome.com/apps/app_identity#copy_key