From 0e6fb73b9e5131e44605149f4c93e54aaa65c855 Mon Sep 17 00:00:00 2001 From: Peter Clement Date: Mon, 5 Jul 2021 14:27:19 +0100 Subject: [PATCH] Add validation to backend for OIDC configuration --- packages/auth/src/constants.js | 1 + .../worker/src/api/controllers/admin/configs.js | 6 ++++++ packages/worker/src/api/routes/admin/configs.js | 16 +++++++++++++++- packages/worker/src/constants/index.js | 1 + 4 files changed, 23 insertions(+), 1 deletion(-) diff --git a/packages/auth/src/constants.js b/packages/auth/src/constants.js index 230c80b609..ace9464e9d 100644 --- a/packages/auth/src/constants.js +++ b/packages/auth/src/constants.js @@ -20,4 +20,5 @@ exports.Configs = { ACCOUNT: "account", SMTP: "smtp", GOOGLE: "google", + OIDC: "oidc" } diff --git a/packages/worker/src/api/controllers/admin/configs.js b/packages/worker/src/api/controllers/admin/configs.js index b93bd22c80..ffd85e98e9 100644 --- a/packages/worker/src/api/controllers/admin/configs.js +++ b/packages/worker/src/api/controllers/admin/configs.js @@ -188,6 +188,12 @@ exports.configChecklist = async function (ctx) { type: Configs.GOOGLE, }) + // They have set up OIDC + const oidcConfig = await getScopedFullConfig(db, { + type: Configs.OIDC, + }) + + // They have set up an admin user const users = await db.allDocs( getGlobalUserParams(null, { diff --git a/packages/worker/src/api/routes/admin/configs.js b/packages/worker/src/api/routes/admin/configs.js index 8056ad8cbd..83eec20cf3 100644 --- a/packages/worker/src/api/routes/admin/configs.js +++ b/packages/worker/src/api/routes/admin/configs.js @@ -41,6 +41,19 @@ function googleValidation() { }).unknown(true) } +function OidcValidation() { + // prettier-ignore + return Joi.object({ + clientID: Joi.string().required(), + authUrl: Joi.string().required(), + tokenUrl: Joi.string().required(), + userInfoUrl: Joi.string().required(), + clientId: Joi.string().required(), + clientSecret: Joi.string().required(), + callbackUrl: Joi.string().required(), + }).unknown(true) +} + function buildConfigSaveValidation() { // prettier-ignore return joiValidator.body(Joi.object({ @@ -54,7 +67,8 @@ function buildConfigSaveValidation() { { is: Configs.SMTP, then: smtpValidation() }, { is: Configs.SETTINGS, then: settingValidation() }, { is: Configs.ACCOUNT, then: Joi.object().unknown(true) }, - { is: Configs.GOOGLE, then: googleValidation() } + { is: Configs.GOOGLE, then: googleValidation() }, + { is: Configs.OIDC, then: Joi.object().unknown(true) } ], }), }).required(), diff --git a/packages/worker/src/constants/index.js b/packages/worker/src/constants/index.js index b40446cc89..70c61cd6b0 100644 --- a/packages/worker/src/constants/index.js +++ b/packages/worker/src/constants/index.js @@ -16,6 +16,7 @@ exports.Configs = Configs exports.ConfigUploads = { LOGO: "logo", + OIDC_LOGO: "oidc_logo" } const TemplateTypes = {