From 52a35970d9ce83ce4b51e7126c08ae13e0a18864 Mon Sep 17 00:00:00 2001 From: Sam Macbeth Date: Fri, 30 Oct 2020 10:08:12 +0100 Subject: [PATCH] Fixes for auth on staging. --- src/background.js | 5 ++--- src/config.js | 8 ++++++-- src/manifest.json | 3 +++ 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/background.js b/src/background.js index 6b28f56..bd44b29 100644 --- a/src/background.js +++ b/src/background.js @@ -40,8 +40,7 @@ function parseJwt(token) { const cookieListener = (changeInfo) => { const { cookie, removed } = changeInfo; - - if (cookie.domain !== ".ghostery.com") { + if (cookie.domain !== AUTH_DOMAIN) { return; } @@ -60,7 +59,7 @@ const cookieListener = (changeInfo) => { const lookForAccessToken = async () => { browser.cookies.onChanged.addListener(cookieListener); const cookie = await browser.cookies.get({ - url: "https://www.ghostery.com/", + url: `https://www${AUTH_DOMAIN}/`, name: "access_token", }); if (cookie) { diff --git a/src/config.js b/src/config.js index c012ecc..80ccbc3 100644 --- a/src/config.js +++ b/src/config.js @@ -1,14 +1,18 @@ let DEBUG = false; const STAGING_BASE_URL = 'https://staging.ghosterysearch.com'; const PROD_BASE_URL = 'https://ghosterysearch.com'; +const STAGING_AUTH_DOMAIN = '.ghosterystage.com'; +const PROD_AUTH_DOMAIN = '.ghostery.com'; let API_BASE_URL = DEBUG ? 'http://localhost:5000' : PROD_BASE_URL; let SERP_BASE_URL = DEBUG ? 'http://localhost' : PROD_BASE_URL; -let AUTH_BASE_URL = 'https://consumerapi.ghostery.com/api/v2'; +let AUTH_DOMAIN = PROD_AUTH_DOMAIN; +let AUTH_BASE_URL = `https://consumerapi${PROD_AUTH_DOMAIN}/api/v2`; const setupEndpoints = (async function() { const USE_STAGING = (await browser.storage.local.get('USE_STAGING'))['USE_STAGING']; if (USE_STAGING) { - AUTH_BASE_URL = AUTH_BASE_URL.replace('.ghostery.com', '.ghosterystage.com'); + AUTH_DOMAIN = STAGING_AUTH_DOMAIN; + AUTH_BASE_URL = AUTH_BASE_URL.replace(PROD_AUTH_DOMAIN, STAGING_AUTH_DOMAIN); console.log(`USING_STAGING: AUTH_BASE_URL=${AUTH_BASE_URL}`) // only switch to staging search if DEBUG is disabled if (!DEBUG) { diff --git a/src/manifest.json b/src/manifest.json index fe3059c..974639b 100644 --- a/src/manifest.json +++ b/src/manifest.json @@ -30,7 +30,10 @@ "webRequestBlocking", "https://www.ghostery.com/*", "https://consumerapi.ghostery.com/*", + "https://www.ghosterystage.com/*", + "https://consumerapi.ghosterystage.com/*", "https://ghosterysearch.com/*", + "https://staging.ghosterysearch.com/*", "http://localhost/*" ], "icons": {