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.
This commit is contained in:
Thibaut Patel 2021-07-20 23:16:49 +02:00
parent 1eef1e9781
commit 489e470d7b
3 changed files with 12 additions and 6 deletions

View File

@ -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;
}

View File

@ -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);

View File

@ -26,7 +26,8 @@ const ALPHA_FEATURES = [
'multipleProducts',
'savedIndicator',
'featureImgDragDrop',
'checkEmailList'
'checkEmailList',
'oauthLogin'
];
module.exports.WRITABLE_KEYS_ALLOWLIST = [...BETA_FEATURES, ...ALPHA_FEATURES];