javascript - Chrome 扩展失败,chrome.identity.launchWebAuthFlow 'Authorization page could not be loaded.'

标签 javascript google-chrome google-chrome-extension

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

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

当前目录结构

current directory structure

list .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);
  }
});

安装运行后,输出日志'Authorization page could not be loaded.'。

launchWebAuthFlow 中的

redirect_url 未定义。

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

最佳答案

您没有 the key在你的 list 中。

您需要copy your extension's key到 list 。

When you register your application in the Google OAuth console, you'll provide your application's ID, which will be checked during token requests. Therefore it's important to have a consistent application ID during development.

To keep your application ID constant, you need to copy the key in the installed manifest.json to your source manifest.

关于javascript - Chrome 扩展失败,chrome.identity.launchWebAuthFlow 'Authorization page could not be loaded.',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44017814/

相关文章:

javascript - 根据单选选择在多个 DIV 中显示切换的 DIV

css - 禁止将字体渲染为表情符号

javascript - Codecademy 上的石头剪刀布 Javascript 练习

javascript - JQuery Lipsum 生成器不生成单词

css - chrome 缓存 bootstrap css 吗?

google-chrome - 如何使用 Chrome 扩展程序分发 native 消息传递主机

javascript - Chrome 扩展程序 : DNS resolve with chrome. webRequest.onBeforeRequest

javascript - 如何在 JavaScript 中使用变量作为对象初始值设定项内的属性键?

google-chrome - 如何在 Google Chrome 中为扩展设置 "Alarms & Clocks"类别?

javascript - 解决嵌套 Promise 后运行函数