Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Chrome Extension failed with chrome.identity.launchWebAuthFlow 'Authorization page could not be loaded.'

I want to authorize with Google after start extension.

I write manifest.json and background.js as below.

current directory structure

current directory structure

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

After install and run, output log 'Authorization page could not be loaded.'.

redirect_url inside of launchWebAuthFlow is undefined.

If you know my mistake, please teach me.

like image 413
Masahiro Yanou Avatar asked Oct 16 '25 00:10

Masahiro Yanou


1 Answers

You don't have the key in your manifest.

You need to copy your extension's key to the manifest.

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.

like image 192
user7607751 Avatar answered Oct 18 '25 15:10

user7607751