feat: authentication module refactor + added CAS module
This commit is contained in:
@@ -110,6 +110,7 @@
|
|||||||
"passport": "0.4.0",
|
"passport": "0.4.0",
|
||||||
"passport-auth0": "0.6.1",
|
"passport-auth0": "0.6.1",
|
||||||
"passport-azure-ad-oauth2": "0.0.4",
|
"passport-azure-ad-oauth2": "0.0.4",
|
||||||
|
"passport-cas": "0.1.1",
|
||||||
"passport-discord": "0.1.3",
|
"passport-discord": "0.1.3",
|
||||||
"passport-dropbox-oauth2": "1.1.0",
|
"passport-dropbox-oauth2": "1.1.0",
|
||||||
"passport-facebook": "2.1.1",
|
"passport-facebook": "2.1.1",
|
||||||
|
|||||||
+1
-1
@@ -45,7 +45,7 @@ module.exports = {
|
|||||||
const stg = enabledStrategies[idx]
|
const stg = enabledStrategies[idx]
|
||||||
if (!stg.isEnabled) { continue }
|
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
|
stg.config.callbackURL = `${WIKI.config.host}/login/${stg.key}/callback` // TODO: config.host
|
||||||
strategy.init(passport, stg.config)
|
strategy.init(passport, stg.config)
|
||||||
|
|||||||
@@ -1,7 +1,9 @@
|
|||||||
const Model = require('objection').Model
|
const Model = require('objection').Model
|
||||||
const autoload = require('auto-load')
|
const fs = require('fs-extra')
|
||||||
const path = require('path')
|
const path = require('path')
|
||||||
const _ = require('lodash')
|
const _ = require('lodash')
|
||||||
|
const yaml = require('js-yaml')
|
||||||
|
const commonHelper = require('../../helpers/common')
|
||||||
|
|
||||||
/* global WIKI */
|
/* global WIKI */
|
||||||
|
|
||||||
@@ -42,9 +44,17 @@ module.exports = class Authentication extends Model {
|
|||||||
static async refreshStrategiesFromDisk() {
|
static async refreshStrategiesFromDisk() {
|
||||||
try {
|
try {
|
||||||
const dbStrategies = await WIKI.db.authentication.query()
|
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 = []
|
let newStrategies = []
|
||||||
_.forOwn(diskStrategies, (strategy, strategyKey) => {
|
_.forEach(diskStrategies, strategy => {
|
||||||
if (!_.some(dbStrategies, ['key', strategy.key])) {
|
if (!_.some(dbStrategies, ['key', strategy.key])) {
|
||||||
newStrategies.push({
|
newStrategies.push({
|
||||||
key: strategy.key,
|
key: strategy.key,
|
||||||
@@ -54,8 +64,8 @@ module.exports = class Authentication extends Model {
|
|||||||
config: _.transform(strategy.props, (result, value, key) => {
|
config: _.transform(strategy.props, (result, value, key) => {
|
||||||
if (_.isPlainObject(value)) {
|
if (_.isPlainObject(value)) {
|
||||||
let cfgValue = {
|
let cfgValue = {
|
||||||
type: typeof value.type(),
|
type: value.type.toLowerCase(),
|
||||||
value: !_.isNil(value.default) ? value.default : new value() // eslint-disable-line new-cap
|
value: !_.isNil(value.default) ? value.default : commonHelper.getTypeDefaultValue(value.type)
|
||||||
}
|
}
|
||||||
if (_.isArray(value.enum)) {
|
if (_.isArray(value.enum)) {
|
||||||
cfgValue.enum = value.enum
|
cfgValue.enum = value.enum
|
||||||
@@ -63,8 +73,8 @@ module.exports = class Authentication extends Model {
|
|||||||
_.set(result, key, cfgValue)
|
_.set(result, key, cfgValue)
|
||||||
} else {
|
} else {
|
||||||
_.set(result, key, {
|
_.set(result, key, {
|
||||||
type: typeof value(),
|
type: value.toLowerCase(),
|
||||||
value: new value() // eslint-disable-line new-cap
|
value: commonHelper.getTypeDefaultValue(value)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
return result
|
return result
|
||||||
|
|||||||
-8
@@ -7,14 +7,6 @@
|
|||||||
const Auth0Strategy = require('passport-auth0').Strategy
|
const Auth0Strategy = require('passport-auth0').Strategy
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
key: 'auth0',
|
|
||||||
title: 'Auth0',
|
|
||||||
useForm: false,
|
|
||||||
props: {
|
|
||||||
domain: String,
|
|
||||||
clientId: String,
|
|
||||||
clientSecret: String
|
|
||||||
},
|
|
||||||
init (passport, conf) {
|
init (passport, conf) {
|
||||||
passport.use('auth0',
|
passport.use('auth0',
|
||||||
new Auth0Strategy({
|
new Auth0Strategy({
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
key: auth0
|
||||||
|
title: Auth0
|
||||||
|
author: requarks.io
|
||||||
|
useForm: false
|
||||||
|
props:
|
||||||
|
domain: String
|
||||||
|
clientId: String
|
||||||
|
clientSecret: String
|
||||||
-15
@@ -7,21 +7,6 @@
|
|||||||
const AzureAdOAuth2Strategy = require('passport-azure-ad-oauth2').Strategy
|
const AzureAdOAuth2Strategy = require('passport-azure-ad-oauth2').Strategy
|
||||||
|
|
||||||
module.exports = {
|
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) {
|
init (passport, conf) {
|
||||||
const jwt = require('jsonwebtoken')
|
const jwt = require('jsonwebtoken')
|
||||||
passport.use('azure_ad_oauth2',
|
passport.use('azure_ad_oauth2',
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
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
|
||||||
@@ -0,0 +1,24 @@
|
|||||||
|
/* 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
|
||||||
|
})
|
||||||
|
}
|
||||||
|
))
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
key: cas
|
||||||
|
title: CAS
|
||||||
|
author: requarks.io
|
||||||
|
useForm: false
|
||||||
|
props:
|
||||||
|
ssoBaseURL: String
|
||||||
|
serverBaseURL: String
|
||||||
-7
@@ -7,13 +7,6 @@
|
|||||||
const DiscordStrategy = require('passport-discord').Strategy
|
const DiscordStrategy = require('passport-discord').Strategy
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
key: 'discord',
|
|
||||||
title: 'Discord',
|
|
||||||
useForm: false,
|
|
||||||
props: {
|
|
||||||
clientId: String,
|
|
||||||
clientSecret: String
|
|
||||||
},
|
|
||||||
init (passport, conf) {
|
init (passport, conf) {
|
||||||
passport.use('discord',
|
passport.use('discord',
|
||||||
new DiscordStrategy({
|
new DiscordStrategy({
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
key: discord
|
||||||
|
title: Discord
|
||||||
|
author: requarks.io
|
||||||
|
useForm: false
|
||||||
|
props:
|
||||||
|
clientId: String
|
||||||
|
clientSecret: String
|
||||||
-7
@@ -7,13 +7,6 @@
|
|||||||
const DropboxStrategy = require('passport-dropbox-oauth2').Strategy
|
const DropboxStrategy = require('passport-dropbox-oauth2').Strategy
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
key: 'dropbox',
|
|
||||||
title: 'Dropbox',
|
|
||||||
useForm: false,
|
|
||||||
props: {
|
|
||||||
clientId: String,
|
|
||||||
clientSecret: String
|
|
||||||
},
|
|
||||||
init (passport, conf) {
|
init (passport, conf) {
|
||||||
passport.use('dropbox',
|
passport.use('dropbox',
|
||||||
new DropboxStrategy({
|
new DropboxStrategy({
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
key: dropbox
|
||||||
|
title: Dropbox
|
||||||
|
author: requarks.io
|
||||||
|
useForm: false
|
||||||
|
props:
|
||||||
|
clientId: String
|
||||||
|
clientSecret: String
|
||||||
-7
@@ -7,13 +7,6 @@
|
|||||||
const FacebookStrategy = require('passport-facebook').Strategy
|
const FacebookStrategy = require('passport-facebook').Strategy
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
key: 'facebook',
|
|
||||||
title: 'Facebook',
|
|
||||||
useForm: false,
|
|
||||||
props: {
|
|
||||||
clientId: String,
|
|
||||||
clientSecret: String
|
|
||||||
},
|
|
||||||
init (passport, conf) {
|
init (passport, conf) {
|
||||||
passport.use('facebook',
|
passport.use('facebook',
|
||||||
new FacebookStrategy({
|
new FacebookStrategy({
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
key: facebook
|
||||||
|
title: Facebook
|
||||||
|
author: requarks.io
|
||||||
|
useForm: false
|
||||||
|
props:
|
||||||
|
clientId: String
|
||||||
|
clientSecret: String
|
||||||
-7
@@ -7,13 +7,6 @@
|
|||||||
const GitHubStrategy = require('passport-github2').Strategy
|
const GitHubStrategy = require('passport-github2').Strategy
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
key: 'github',
|
|
||||||
title: 'GitHub',
|
|
||||||
useForm: false,
|
|
||||||
props: {
|
|
||||||
clientId: String,
|
|
||||||
clientSecret: String
|
|
||||||
},
|
|
||||||
init (passport, conf) {
|
init (passport, conf) {
|
||||||
passport.use('github',
|
passport.use('github',
|
||||||
new GitHubStrategy({
|
new GitHubStrategy({
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
key: github
|
||||||
|
title: GitHub
|
||||||
|
author: requarks.io
|
||||||
|
useForm: false
|
||||||
|
props:
|
||||||
|
clientId: String
|
||||||
|
clientSecret: String
|
||||||
-7
@@ -7,13 +7,6 @@
|
|||||||
const GoogleStrategy = require('passport-google-oauth20').Strategy
|
const GoogleStrategy = require('passport-google-oauth20').Strategy
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
key: 'google',
|
|
||||||
title: 'Google',
|
|
||||||
useForm: false,
|
|
||||||
props: {
|
|
||||||
clientId: String,
|
|
||||||
clientSecret: String
|
|
||||||
},
|
|
||||||
init (passport, conf) {
|
init (passport, conf) {
|
||||||
passport.use('google',
|
passport.use('google',
|
||||||
new GoogleStrategy({
|
new GoogleStrategy({
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
key: google
|
||||||
|
title: Google
|
||||||
|
author: requarks.io
|
||||||
|
useForm: false
|
||||||
|
props:
|
||||||
|
clientId: String
|
||||||
|
clientSecret: String
|
||||||
-27
@@ -8,33 +8,6 @@ const LdapStrategy = require('passport-ldapauth').Strategy
|
|||||||
const fs = require('fs')
|
const fs = require('fs')
|
||||||
|
|
||||||
module.exports = {
|
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) {
|
init (passport, conf) {
|
||||||
passport.use('ldapauth',
|
passport.use('ldapauth',
|
||||||
new LdapStrategy({
|
new LdapStrategy({
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
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
|
||||||
-4
@@ -7,10 +7,6 @@
|
|||||||
const LocalStrategy = require('passport-local').Strategy
|
const LocalStrategy = require('passport-local').Strategy
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
key: 'local',
|
|
||||||
title: 'Local',
|
|
||||||
useForm: true,
|
|
||||||
props: {},
|
|
||||||
init (passport, conf) {
|
init (passport, conf) {
|
||||||
passport.use('local',
|
passport.use('local',
|
||||||
new LocalStrategy({
|
new LocalStrategy({
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
key: local
|
||||||
|
title: Local
|
||||||
|
author: requarks.io
|
||||||
|
useForm: true
|
||||||
|
props: {}
|
||||||
-7
@@ -7,13 +7,6 @@
|
|||||||
const WindowsLiveStrategy = require('passport-windowslive').Strategy
|
const WindowsLiveStrategy = require('passport-windowslive').Strategy
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
key: 'microsoft',
|
|
||||||
title: 'Microsoft Account',
|
|
||||||
useForm: false,
|
|
||||||
props: {
|
|
||||||
clientId: String,
|
|
||||||
clientSecret: String
|
|
||||||
},
|
|
||||||
init (passport, conf) {
|
init (passport, conf) {
|
||||||
passport.use('microsoft',
|
passport.use('microsoft',
|
||||||
new WindowsLiveStrategy({
|
new WindowsLiveStrategy({
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
key: microsoft
|
||||||
|
title: Microsoft Account
|
||||||
|
author: requarks.io
|
||||||
|
useForm: false
|
||||||
|
props:
|
||||||
|
clientId: String
|
||||||
|
clientSecret: String
|
||||||
-9
@@ -7,15 +7,6 @@
|
|||||||
const OAuth2Strategy = require('passport-oauth2').Strategy
|
const OAuth2Strategy = require('passport-oauth2').Strategy
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
key: 'oauth2',
|
|
||||||
title: 'OAuth2',
|
|
||||||
useForm: false,
|
|
||||||
props: {
|
|
||||||
clientId: String,
|
|
||||||
clientSecret: String,
|
|
||||||
authorizationURL: String,
|
|
||||||
tokenURL: String
|
|
||||||
},
|
|
||||||
init (passport, conf) {
|
init (passport, conf) {
|
||||||
passport.use('oauth2',
|
passport.use('oauth2',
|
||||||
new OAuth2Strategy({
|
new OAuth2Strategy({
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
key: oauth2
|
||||||
|
title: OAuth2
|
||||||
|
author: requarks.io
|
||||||
|
useForm: false
|
||||||
|
props:
|
||||||
|
clientId: String
|
||||||
|
clientSecret: String
|
||||||
|
authorizationURL: String
|
||||||
|
tokenURL: String
|
||||||
-7
@@ -7,13 +7,6 @@
|
|||||||
const SlackStrategy = require('passport-slack').Strategy
|
const SlackStrategy = require('passport-slack').Strategy
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
key: 'slack',
|
|
||||||
title: 'Slack',
|
|
||||||
useForm: false,
|
|
||||||
props: {
|
|
||||||
clientId: String,
|
|
||||||
clientSecret: String
|
|
||||||
},
|
|
||||||
init (passport, conf) {
|
init (passport, conf) {
|
||||||
passport.use('slack',
|
passport.use('slack',
|
||||||
new SlackStrategy({
|
new SlackStrategy({
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
key: slack
|
||||||
|
title: Slack
|
||||||
|
author: requarks.io
|
||||||
|
useForm: false
|
||||||
|
props:
|
||||||
|
clientId: String
|
||||||
|
clientSecret: String
|
||||||
-7
@@ -7,13 +7,6 @@
|
|||||||
const TwitchStrategy = require('passport-twitch').Strategy
|
const TwitchStrategy = require('passport-twitch').Strategy
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
key: 'twitch',
|
|
||||||
title: 'Twitch',
|
|
||||||
useForm: false,
|
|
||||||
props: {
|
|
||||||
clientId: String,
|
|
||||||
clientSecret: String
|
|
||||||
},
|
|
||||||
init (passport, conf) {
|
init (passport, conf) {
|
||||||
passport.use('twitch',
|
passport.use('twitch',
|
||||||
new TwitchStrategy({
|
new TwitchStrategy({
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
key: twitch
|
||||||
|
title: Twitch
|
||||||
|
author: requarks.io
|
||||||
|
useForm: false
|
||||||
|
props:
|
||||||
|
clientId: String
|
||||||
|
clientSecret: String
|
||||||
Reference in New Issue
Block a user