chrome.identity.getAuthToken不起作用 [英] chrome.identity.getAuthToken not working

查看:422
本文介绍了chrome.identity.getAuthToken不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Chrome身份验证API,为我的Chrome扩展程序向用户提供Google身份验证。

I am working with Chrome Identity API, to provide users with a Google Authentication on my Chrome Extension.

我遵循Google官方教程:链接Chrome身份验证API

I followed the official tutorial of Google : link Chrome Identity API


  • 我将权限添加到 manifest.json 客户端ID 范围

  • 触发验证我在我的 Background.js

  • i added permissions to manifest.json and Client ID and Scopes
  • to trigger the Authentification i added this code in my Background.js

chrome.identity。 getAuthToken

chrome.identity.getAuthToken

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

The problem is when i execute the extension i am redirected to this login page


chrome:// chrome-signin /?source = 5

chrome://chrome-signin/?source=5

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

but after a successfull authentication i am redirected another time to the login page

有什么问题?

M anifest.json

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"]
}

Background.js:

Background.js:

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


推荐答案

/ strong>

Problem Resolved !

我的 Chrome扩展程序应用程序ID 与我的在 Google控制台开发人员
中的应用程序ID 要避免此上传,请先将您的扩展程序从Chrome复制并将其设置到Google控制台开发者!
您必须每次在Google Chrome中更改它时,都必须在Google控制台中进行更新

the app ID of my Chrome extension does not match with my app ID in Google Console Developpers To avoid this upload first your Extension then copy the ID from Chrome and set it in the Google Console Developpers ! you must update it in Google console everytime you change it in Google Chrome

这篇关于chrome.identity.getAuthToken不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆