From 628c72ea169045e1f1dd2121cf32e761867dbf45 Mon Sep 17 00:00:00 2001 From: Mirco T Date: Sun, 17 Jul 2022 01:41:41 +0200 Subject: [PATCH] feat: CAS authentication module (#5452) Co-authored-by: SeaLife --- .../authentication/cas/authentication.js | 16 +++++++-- .../modules/authentication/cas/definition.yml | 35 +++++++++++++++++-- 2 files changed, 46 insertions(+), 5 deletions(-) diff --git a/server/modules/authentication/cas/authentication.js b/server/modules/authentication/cas/authentication.js index eae89aff..9255d02e 100644 --- a/server/modules/authentication/cas/authentication.js +++ b/server/modules/authentication/cas/authentication.js @@ -1,3 +1,4 @@ +const _ = require('lodash') /* global WIKI */ // ------------------------------------ @@ -10,15 +11,24 @@ module.exports = { init (passport, conf) { passport.use(conf.key, new CASStrategy({ - ssoBaseURL: conf.ssoBaseURL, - serverBaseURL: conf.serverBaseURL, + version: conf.casVersion, + ssoBaseURL: conf.casUrl, + serverBaseURL: conf.baseUrl, + serviceURL: conf.callbackURL, passReqToCallback: true }, async (req, profile, cb) => { try { const user = await WIKI.models.users.processProfile({ providerKey: req.params.strategy, - profile + profile: { + ...profile, + id: _.get(profile.attributes, conf.uniqueIdAttribute, profile.user), + email: _.get(profile.attributes, conf.emailAttribute), + name: _.get(profile.attributes, conf.displayNameAttribute, profile.user), + picture: '' + } }) + cb(null, user) } catch (err) { cb(err, null) diff --git a/server/modules/authentication/cas/definition.yml b/server/modules/authentication/cas/definition.yml index 912840eb..a8c6e4fd 100644 --- a/server/modules/authentication/cas/definition.yml +++ b/server/modules/authentication/cas/definition.yml @@ -6,6 +6,37 @@ logo: https://static.requarks.io/logo/cas.svg color: green darken-2 website: https://apereo.github.io/cas/ useForm: false +isAvailable: true props: - ssoBaseURL: String - serverBaseURL: String + baseUrl: + type: String + title: Base URL + hint: 'Base-URL of your WikiJS (for example: https://wiki.example.com)' + order: 1 + casUrl: + type: String + title: URL to the CAS Server + hint: 'Base-URL of the CAS server, including context path. (for example: https://login.company.com/cas)' + order: 2 + casVersion: + type: String + title: CAS Version + hint: 'The version of CAS to use' + order: 3 + enum: + - CAS3.0 + - CAS1.0 + default: 'CAS3.0' + emailAttribute: + type: String + title: Attribute key which contains the users email + default: email + order: 4 + displayNameAttribute: + type: String + title: Attribute key which contains the users display name (leave empty if there is none) + order: 5 + uniqueIdAttribute: + type: String + title: Attribute key which contains the unique identifier of a user. (if empty, username will be used) + order: 6