【问题标题】:Chrome Extension failed with chrome.identity.launchWebAuthFlow 'Authorization page could not be loaded.'Chrome 扩展因 chrome.identity.launchWebAuthFlow '无法加载授权页面'而失败。
【发布时间】:2017-10-01 18:58:30
【问题描述】:

我想在开始扩展后向 Google 授权。

我写 manifest.json 和 background.js 如下。

当前目录结构

ma​​nifest.json

{
  "manifest_version": 2,
  "name": "***************",
  "short_name": "DSBOT",
  "version": "0.0.1.0",
  "description": "**************************",
  "icons": {
    "16": "images/icon_16.png",
    "48": "images/icon_48.png",
    "128": "images/icon_128.png"
  },
  "background": {
    "scripts": [
      "background.js"
    ]
  },
  "browser_action": {
    "default_icon": {
      "19": "images/icon_19.png"
    },
    "default_popup": "popup.html"
  },
  "permissions": [
    "identity",
    "http://*/*",
    "https://*/*",
    "storage"
  ],
  "oauth2": {
    "client_id": **************,
    "scopes": ["openid", "email", "profile"],
    "hd": "zabuton.co.jp"
  }
}

background.js

var clientId = "********************";
var redirectURL = chrome.identity.getRedirectURL();
var url = "https://accounts.google.com/o/oauth2/v2/auth?" +
  "scope=email&" +
  "response_type=token&" +
  "client_id=" + encodeURIComponent(clientId) + "&" +
  "redirect_uri=" + encodeURIComponent(redirectURL) + "&" +
  "prompt=consent";;

chrome.identity.launchWebAuthFlow({ url: url, interactive: true }, function(redirect_url) {
  console.log('redirect_url = ' + redirect_url);

  if (chrome.runtime.lastError) {
    console.error(chrome.runtime.lastError.message);
  }
});

安装运行后,输出日志“无法加载授权页面”。

launchWebAuthFlow 内部的redirect_url 未定义。

如果你知道我的错误,请教我。

【问题讨论】:

  • 您确定该网站没有被屏蔽?换句话说,您是否在 devtools 网络面板或 Fiddler、WireShark 等独立流量嗅探器中看到正在发送的网络请求和收到的响应?

标签: javascript google-chrome google-chrome-extension


【解决方案1】:

您的清单中没有the key

您需要 copy your extension's key 到清单。

当您在 Google OAuth 控制台中注册您的应用程序时,您将 提供您的应用程序的 ID,这将在令牌期间检查 要求。因此,拥有一致的应用程序 ID 很重要 在开发过程中。

要保持您的应用程序 ID 不变,您需要将密钥复制到 将 manifest.json 安装到您的源清单中。

【讨论】:

  • 同意屏幕出现并立即消失,后台js有错误授权页面无法加载。我已经正确输入了密钥,它在我的电脑上工作,但在任何其他电脑上都不能工作?任何想法
  • 修复:如果 youtube 在您的网络中被阻止,您将收到错误授权页面无法加载。
猜你喜欢
  • 2021-01-14
  • 2020-06-13
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-08-31
  • 1970-01-01
相关资源
最近更新 更多