From 489e470d7bbd6c407e8448e915326906c4029846 Mon Sep 17 00:00:00 2001 From: Thibaut Patel Date: Tue, 20 Jul 2021 23:16:49 +0200 Subject: [PATCH] Added a feature flag to the oauth login feature issue https://github.com/TryGhost/Team/issues/614 - The feature flag was called `oauthLogin` instead of simply `oauth` to avoid clashes in the frontend `feature` service as it is merging the config and labs properties. --- core/server/services/public-config/site.js | 3 ++- core/server/web/oauth/app.js | 12 ++++++++---- core/shared/labs.js | 3 ++- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/core/server/services/public-config/site.js b/core/server/services/public-config/site.js index 0195ff6b09..3d6e677e4e 100644 --- a/core/server/services/public-config/site.js +++ b/core/server/services/public-config/site.js @@ -2,6 +2,7 @@ const ghostVersion = require('@tryghost/version'); const settingsCache = require('../../../shared/settings-cache'); const config = require('../../../shared/config'); const urlUtils = require('../../../shared/url-utils'); +const labs = require('../../../shared/labs'); module.exports = function getSiteProperties() { const siteProperties = { @@ -14,7 +15,7 @@ module.exports = function getSiteProperties() { version: ghostVersion.safe }; - if (settingsCache.get('oauth_client_id') && settingsCache.get('oauth_client_secret')) { + if (labs.isSet('oauthLogin') && settingsCache.get('oauth_client_id') && settingsCache.get('oauth_client_secret')) { // Only set the oauth flag if oauth is enabled to avoid API changes siteProperties.oauth = true; } diff --git a/core/server/web/oauth/app.js b/core/server/web/oauth/app.js index 65a470e68b..77a1ffb77c 100644 --- a/core/server/web/oauth/app.js +++ b/core/server/web/oauth/app.js @@ -5,10 +5,10 @@ const GoogleStrategy = require('passport-google-oauth20').Strategy; const express = require('../../../shared/express'); const urlUtils = require('../../../shared/url-utils'); const shared = require('../shared'); -const config = require('../../../shared/config'); const settingsCache = require('../../../shared/settings-cache'); const models = require('../../models'); const auth = require('../../services/auth'); +const labs = require('../../../shared/labs'); function randomPassword() { return require('crypto').randomBytes(128).toString('hex'); @@ -17,10 +17,14 @@ function randomPassword() { module.exports = function setupOAuthApp() { debug('OAuth App setup start'); const oauthApp = express('oauth'); - if (!config.get('enableDeveloperExperiments')) { - debug('OAuth App setup skipped'); - return oauthApp; + + function labsMiddleware(req, res, next) { + if (labs.isSet('oauthLogin')) { + return next(); + } + res.sendStatus(404); } + oauthApp.use(labsMiddleware); // send 503 json response in case of maintenance oauthApp.use(shared.middlewares.maintenance); diff --git a/core/shared/labs.js b/core/shared/labs.js index 701bf634ac..98a15d1702 100644 --- a/core/shared/labs.js +++ b/core/shared/labs.js @@ -26,7 +26,8 @@ const ALPHA_FEATURES = [ 'multipleProducts', 'savedIndicator', 'featureImgDragDrop', - 'checkEmailList' + 'checkEmailList', + 'oauthLogin' ]; module.exports.WRITABLE_KEYS_ALLOWLIST = [...BETA_FEATURES, ...ALPHA_FEATURES];