Commit fd8bf4db authored by NGPixel's avatar NGPixel

feat: authentication module refactor + added CAS module

parent 9e2f1caa
......@@ -110,6 +110,7 @@
"passport": "0.4.0",
"passport-auth0": "0.6.1",
"passport-azure-ad-oauth2": "0.0.4",
"passport-cas": "0.1.1",
"passport-discord": "0.1.3",
"passport-dropbox-oauth2": "1.1.0",
"passport-facebook": "2.1.1",
......
......@@ -45,7 +45,7 @@ module.exports = {
const stg = enabledStrategies[idx]
if (!stg.isEnabled) { continue }
const strategy = require(`../modules/authentication/${stg.key}`)
const strategy = require(`../modules/authentication/${stg.key}/authentication.js`)
stg.config.callbackURL = `${WIKI.config.host}/login/${stg.key}/callback` // TODO: config.host
strategy.init(passport, stg.config)
......
const Model = require('objection').Model
const autoload = require('auto-load')
const fs = require('fs-extra')
const path = require('path')
const _ = require('lodash')
const yaml = require('js-yaml')
const commonHelper = require('../../helpers/common')
/* global WIKI */
......@@ -42,9 +44,17 @@ module.exports = class Authentication extends Model {
static async refreshStrategiesFromDisk() {
try {
const dbStrategies = await WIKI.db.authentication.query()
const diskStrategies = autoload(path.join(WIKI.SERVERPATH, 'modules/authentication'))
// -> Fetch definitions from disk
const authDirs = await fs.readdir(path.join(WIKI.SERVERPATH, 'modules/authentication'))
let diskStrategies = []
for (let dir of authDirs) {
const def = await fs.readFile(path.join(WIKI.SERVERPATH, 'modules/authentication', dir, 'definition.yml'), 'utf8')
diskStrategies.push(yaml.safeLoad(def))
}
let newStrategies = []
_.forOwn(diskStrategies, (strategy, strategyKey) => {
_.forEach(diskStrategies, strategy => {
if (!_.some(dbStrategies, ['key', strategy.key])) {
newStrategies.push({
key: strategy.key,
......@@ -54,8 +64,8 @@ module.exports = class Authentication extends Model {
config: _.transform(strategy.props, (result, value, key) => {
if (_.isPlainObject(value)) {
let cfgValue = {
type: typeof value.type(),
value: !_.isNil(value.default) ? value.default : new value() // eslint-disable-line new-cap
type: value.type.toLowerCase(),
value: !_.isNil(value.default) ? value.default : commonHelper.getTypeDefaultValue(value.type)
}
if (_.isArray(value.enum)) {
cfgValue.enum = value.enum
......@@ -63,8 +73,8 @@ module.exports = class Authentication extends Model {
_.set(result, key, cfgValue)
} else {
_.set(result, key, {
type: typeof value(),
value: new value() // eslint-disable-line new-cap
type: value.toLowerCase(),
value: commonHelper.getTypeDefaultValue(value)
})
}
return result
......
......@@ -7,14 +7,6 @@
const Auth0Strategy = require('passport-auth0').Strategy
module.exports = {
key: 'auth0',
title: 'Auth0',
useForm: false,
props: {
domain: String,
clientId: String,
clientSecret: String
},
init (passport, conf) {
passport.use('auth0',
new Auth0Strategy({
......
key: auth0
title: Auth0
author: requarks.io
useForm: false
props:
domain: String
clientId: String
clientSecret: String
......@@ -7,21 +7,6 @@
const AzureAdOAuth2Strategy = require('passport-azure-ad-oauth2').Strategy
module.exports = {
key: 'azure',
title: 'Azure Active Directory',
useForm: false,
props: {
clientId: String,
clientSecret: String,
resource: {
type: String,
default: '00000002-0000-0000-c000-000000000000'
},
tenant: {
type: String,
default: 'YOUR_TENANT.onmicrosoft.com'
}
},
init (passport, conf) {
const jwt = require('jsonwebtoken')
passport.use('azure_ad_oauth2',
......
key: azure
title: Azure Active Directory
author: requarks.io
useForm: false
props:
clientId: String
clientSecret: String
resource:
type: String,
default: '00000002-0000-0000-c000-000000000000'
tenant:
type: String,
default: YOUR_TENANT.onmicrosoft.com
/* global WIKI */
// ------------------------------------
// CAS Account
// ------------------------------------
const CASStrategy = require('passport-cas').Strategy
module.exports = {
init (passport, conf) {
passport.use('cas',
new CASStrategy({
ssoBaseURL: conf.ssoBaseURL,
serverBaseURL: conf.serverBaseURL
}, (profile, cb) => {
WIKI.db.users.processProfile(profile).then((user) => {
return cb(null, user) || true
}).catch((err) => {
return cb(err, null) || true
})
}
))
}
}
key: cas
title: CAS
author: requarks.io
useForm: false
props:
ssoBaseURL: String
serverBaseURL: String
......@@ -7,13 +7,6 @@
const DiscordStrategy = require('passport-discord').Strategy
module.exports = {
key: 'discord',
title: 'Discord',
useForm: false,
props: {
clientId: String,
clientSecret: String
},
init (passport, conf) {
passport.use('discord',
new DiscordStrategy({
......
key: discord
title: Discord
author: requarks.io
useForm: false
props:
clientId: String
clientSecret: String
......@@ -7,13 +7,6 @@
const DropboxStrategy = require('passport-dropbox-oauth2').Strategy
module.exports = {
key: 'dropbox',
title: 'Dropbox',
useForm: false,
props: {
clientId: String,
clientSecret: String
},
init (passport, conf) {
passport.use('dropbox',
new DropboxStrategy({
......
key: dropbox
title: Dropbox
author: requarks.io
useForm: false
props:
clientId: String
clientSecret: String
......@@ -7,13 +7,6 @@
const FacebookStrategy = require('passport-facebook').Strategy
module.exports = {
key: 'facebook',
title: 'Facebook',
useForm: false,
props: {
clientId: String,
clientSecret: String
},
init (passport, conf) {
passport.use('facebook',
new FacebookStrategy({
......
key: facebook
title: Facebook
author: requarks.io
useForm: false
props:
clientId: String
clientSecret: String
......@@ -7,13 +7,6 @@
const GitHubStrategy = require('passport-github2').Strategy
module.exports = {
key: 'github',
title: 'GitHub',
useForm: false,
props: {
clientId: String,
clientSecret: String
},
init (passport, conf) {
passport.use('github',
new GitHubStrategy({
......
key: github
title: GitHub
author: requarks.io
useForm: false
props:
clientId: String
clientSecret: String
......@@ -7,13 +7,6 @@
const GoogleStrategy = require('passport-google-oauth20').Strategy
module.exports = {
key: 'google',
title: 'Google',
useForm: false,
props: {
clientId: String,
clientSecret: String
},
init (passport, conf) {
passport.use('google',
new GoogleStrategy({
......
key: google
title: Google
author: requarks.io
useForm: false
props:
clientId: String
clientSecret: String
......@@ -8,33 +8,6 @@ const LdapStrategy = require('passport-ldapauth').Strategy
const fs = require('fs')
module.exports = {
key: 'ldap',
title: 'LDAP / Active Directory',
useForm: true,
props: {
url: {
type: String,
default: 'ldap://serverhost:389'
},
bindDn: {
type: String,
default: `cn='root'`
},
bindCredentials: String,
searchBase: {
type: String,
default: 'o=users,o=example.com'
},
searchFilter: {
type: String,
default: '(uid={{username}})'
},
tlsEnabled: {
type: Boolean,
default: false
},
tlsCertPath: String
},
init (passport, conf) {
passport.use('ldapauth',
new LdapStrategy({
......
key: ldap
title: LDAP / Active Directory
author: requarks.io
useForm: true
props:
url:
type: String
default: 'ldap://serverhost:389'
bindDn:
type: String
default: cn='root'
bindCredentials: String
searchBase:
type: String
default: 'o=users,o=example.com'
searchFilter:
type: String
default: '(uid={{username}})'
tlsEnabled:
type: Boolean
default: false
tlsCertPath: String
......@@ -7,10 +7,6 @@
const LocalStrategy = require('passport-local').Strategy
module.exports = {
key: 'local',
title: 'Local',
useForm: true,
props: {},
init (passport, conf) {
passport.use('local',
new LocalStrategy({
......
key: local
title: Local
author: requarks.io
useForm: true
props: {}
......@@ -7,13 +7,6 @@
const WindowsLiveStrategy = require('passport-windowslive').Strategy
module.exports = {
key: 'microsoft',
title: 'Microsoft Account',
useForm: false,
props: {
clientId: String,
clientSecret: String
},
init (passport, conf) {
passport.use('microsoft',
new WindowsLiveStrategy({
......
key: microsoft
title: Microsoft Account
author: requarks.io
useForm: false
props:
clientId: String
clientSecret: String
......@@ -7,15 +7,6 @@
const OAuth2Strategy = require('passport-oauth2').Strategy
module.exports = {
key: 'oauth2',
title: 'OAuth2',
useForm: false,
props: {
clientId: String,
clientSecret: String,
authorizationURL: String,
tokenURL: String
},
init (passport, conf) {
passport.use('oauth2',
new OAuth2Strategy({
......
key: oauth2
title: OAuth2
author: requarks.io
useForm: false
props:
clientId: String
clientSecret: String
authorizationURL: String
tokenURL: String
......@@ -7,13 +7,6 @@
const SlackStrategy = require('passport-slack').Strategy
module.exports = {
key: 'slack',
title: 'Slack',
useForm: false,
props: {
clientId: String,
clientSecret: String
},
init (passport, conf) {
passport.use('slack',
new SlackStrategy({
......
key: slack
title: Slack
author: requarks.io
useForm: false
props:
clientId: String
clientSecret: String
......@@ -7,13 +7,6 @@
const TwitchStrategy = require('passport-twitch').Strategy
module.exports = {
key: 'twitch',
title: 'Twitch',
useForm: false,
props: {
clientId: String,
clientSecret: String
},
init (passport, conf) {
passport.use('twitch',
new TwitchStrategy({
......
key: twitch
title: Twitch
author: requarks.io
useForm: false
props:
clientId: String
clientSecret: String
This diff was suppressed by a .gitattributes entry.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment