chrome extension authentication identity api

不打扰是莪最后的温柔 提交于 2020-01-05 08:42:35

问题


Hi i am developing a chrome extension and i need to authenticate user based on Google Plus account. I have implemented with Oauth 2.0 . But there is some issue when i execute

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

There is no popup window appears for authentication and i checked chrome://identity-internals/. Token Status Not Found for my extension.

I have followed all the steps for Chrome identity api and User authentication process

The Application id of my extension is same as in Api Credentials (Console.developer.google)

I have copied my Public key in manifest.json

But still no hope . i manually tried chrome.identity.getAuthToken in extension background page i got this error

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

Ill paste my code here

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:


There was a small mistake. The Id created in Chrome webStore Dashboard should be same as the ID given in the Oauth Conset Screen .



来源:https://stackoverflow.com/questions/32852920/chrome-extension-authentication-identity-api

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