Chrome.identity.getAuthToken返回无效凭证?

问题描述 投票:0回答:1

我按照外面的一些教程进行了操作。

https:/developer.chrome.comappsapp_identity

https:/github.comGoogleDeveloperExpertschrome-extension-google-apis。

https:/mashe.hawksey.info201705使用google-apps-script-execution-api-in-chrome-extensions。

让我的chrome扩展与谷歌API项目认证,但这个代码。

chrome.identity.getAuthToken({ 'interactive': false }, function (token) {

    // Catch chrome error if user is not authorized.
    if (chrome.runtime.lastError) {

        $("#__sample_support_logarea").text(chrome.runtime.lastError.message);
        console.log('No token aquired');
        console.log(chrome.runtime.lastError.message);

        sampleSupport.log('No token aquired');
        sampleSupport.log(chrome.runtime.lastError.message);


    } else {
        console.log('Token acquired');
        console.log(token);
    }

});

总是返回。

OAuth2 request failed: Invalid credentials (credentials rejected by client).

这是我的manifest.json。

{
  "manifest_version": 2,

  "name": "Shopify Partners",
  "description": "Automate Proposal Creation",
  "version": "1.0",
  "background": {
    "scripts": [
      "background.js"
    ]
  },
  "content_scripts": [
    {
      "js": [ "jquery.min.js", "main.js" ],
      "matches": [ "http://*/*", "https://*/*" ]
    }
  ],
  "browser_action": {
    "default_icon": "icon.png",
    "default_popup": "popup.html"
  },
  "permissions": [
    "activeTab",
    "identity",
    "https://accounts.google.com/*",
    "https://www.googleapis.com/*"
  ],
  "oauth2": {
    "client_id": "..sr1t2ass4f9a0.apps.googleusercontent.com",
    "scopes": [
      "https://www.googleapis.com/auth/spreadsheets"
    ]
  },
  "key": "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAp8Cj7TI9toe9nK0Pw8FFk1hOlSCPUwJ/GUmWUgzyO3XBP2KoIFv+ISpOoPO++itYsDaXBgZzjk/EUeFMPUWbmuL6+lfs6orq39mMzQKLZEMV05bRaVVsj7gMtBGrsuOJm83Ugw+2tUVszH/yCzMFYNGqJe+ZaEPyUDVqeOfbZoo+JDleDveu0j+HTKDa6wVdDxndT+N86IEoPKCWfXdzMZ6+22ZTSPKYIvQbaHalqEQ9YAc80eHaL0eQNq/+aEv3oNWm2rbB8fy79koQKkZBuWJqgWmznWe6NzPkEpsiE+ilaUCKzWzFDFpiIC0A5Eq3KpWQdnQYDF1A2gmTh9vgkQIDAQAB",
  "content_security_policy": "script-src 'self' https://apis.google.com https://ajax.googleapis.com; object-src 'self'"
}

请注意,出于安全考虑,我在这里省略了完整的客户端ID。

我怀疑唯一的原因是,我在chrome开发模式下运行的是一个未打包的扩展,它的id是这样的:gcnonhfkghlloailceiddfmlmdeajlkl。

而在Api Console中,当为客户端创建凭证时,我也指定了同样的内容。

enter image description here

因此我怀疑作为一个未打包的扩展可能是由它组成的。但是在Chrome商店中发布一个扩展是一个漫长的过程,肯定不是这样一个简单的任务所期望的。

google-chrome google-chrome-extension google-oauth google-api-client
1个回答
0
投票

我想你的扩展ID已经改变了。同样的事情发生在我身上。

为了解决这个问题,我又创建了google OAuth 2.0 Client ID 并已修复。

© www.soinside.com 2019 - 2024. All rights reserved.