chrome extension authentication identity api

时间:2015-09-29 20:11:17

标签: google-chrome google-chrome-extension oauth-2.0 google-chrome-devtools google-chrome-app

您好我正在开发Chrome扩展程序,我需要根据Google Plus帐户对用户进行身份验证。我用Oauth 2.0实现了。但是当我执行

时会出现一些问题

chrome.identity.getAuthToken({ 'interactive': true }

没有用于身份验证的弹出窗口,我选中了 chrome:// identity-internals / 。我的扩展程序 令牌状态未找到

我已按照Chrome身份验证API和用户身份验证过程的所有步骤进行操作

我的扩展程序的应用程序ID与Api凭据(Console.developer.google)中的相同

我在manifest.json

中复制了我的公钥

但仍然没有希望。我在扩展程序背景页面中手动尝试 chrome.identity.getAuthToken 我收到此错误

Unchecked runtime.lastError while running identity.getAuthToken: OAuth2 not granted or revoked.

我在这里粘贴我的代码

的manifest.json

{
  "name": "Tinpack",
  "manifest_version": 2,
  "version": "0.1",
  "permissions": [
    "identity",
    "tabs",
    "https://accounts.google.com/*",
    "https://www.googleapis.com/*"
  ],
  "background": {
    "scripts": ["scripts/background.js"]
  },
  "browser_action": {
    "default_icon": {
      "19": "images/icon.png",
      "38": "images/icon.png"
    },
    "default_title": "Tinpack",
    "default_popup": "index.html"
  },
  "oauth2": {
    "client_id": "my client id"
    "scopes": [
      "https://www.googleapis.com/auth/plus.login"
    ]
  },
  "key": "my public key"
  "content_security_policy": "script-src 'self' 'unsafe-eval' https://apis.google.com/; object-src 'self'"
}

Background.js

chrome.identity.getAuthToken({
  'interactive': true
}, function(token) {
  if (chrome.runtime.lastError) {
    alert("Error");
  } else {

    console.log(token);
    alert(token);
  }

});

1 个答案:

答案 0 :(得分:0)

有一个小错误。在Chrome webStore仪表板中创建的ID应与Oauth Conset屏幕中给出的ID相同。