首页 > 解决方案 > 无法使用 identity.getAuthToken 在 chrome 扩展 chrome 中获取令牌

问题描述

我无法使用

chrome.identity.getAuthToken({interactive: true}, token => {
...
}

我收到此错误:

Unchecked runtime.lastError: OAuth2 request failed: Connection failed (-2).

我为 ChromeApp 设置了 OAuth 2.0 客户端并指定了我的扩展程序的应用程序 ID。还要设置一个同意页面。我的清单如下所示:

  "permissions": [
    "storage",
    "identity"
  ],
  "key": "<my application key>",
  "oauth2": {
      "client_id": "<my client id>.apps.googleusercontent.com", 
      "scopes": [
          "openid", "email", "profile"
      ]
  }

如何修复或至少调试此问题?

标签: google-chrome-extensionoauth

解决方案


我也遇到了这个问题,我注意到我一开始并没有使用 Chrome,我使用的是 Microsoft Edge。

确保您使用的是 Chrome。


推荐阅读