feat: auth self-registration config + gql grouping
This commit is contained in:
@@ -39,12 +39,14 @@ module.exports = {
|
||||
_.pull(currentStrategies, 'session')
|
||||
_.forEach(currentStrategies, stg => { passport.unuse(stg) })
|
||||
|
||||
// Load enable strategies
|
||||
const enabledStrategies = await WIKI.db.authentication.getEnabledStrategies()
|
||||
console.info(enabledStrategies)
|
||||
// Load enabled strategies
|
||||
const enabledStrategies = await WIKI.db.authentication.getStrategies()
|
||||
for (let idx in enabledStrategies) {
|
||||
const stg = enabledStrategies[idx]
|
||||
if (!stg.isEnabled) { continue }
|
||||
|
||||
const strategy = require(`../modules/authentication/${stg.key}`)
|
||||
|
||||
stg.config.callbackURL = `${WIKI.config.host}/login/${stg.key}/callback` // TODO: config.host
|
||||
strategy.init(passport, stg.config)
|
||||
|
||||
|
@@ -31,6 +31,9 @@ exports.up = knex => {
|
||||
table.boolean('isEnabled').notNullable().defaultTo(false)
|
||||
table.boolean('useForm').notNullable().defaultTo(false)
|
||||
table.jsonb('config').notNullable()
|
||||
table.boolean('selfRegistration').notNullable().defaultTo(false)
|
||||
table.jsonb('domainWhitelist').notNullable()
|
||||
table.jsonb('autoEnrollGroups').notNullable()
|
||||
})
|
||||
// COMMENTS ----------------------------
|
||||
.createTable('comments', table => {
|
||||
|
@@ -22,13 +22,21 @@ module.exports = class Authentication extends Model {
|
||||
title: {type: 'string'},
|
||||
isEnabled: {type: 'boolean'},
|
||||
useForm: {type: 'boolean'},
|
||||
config: {type: 'object'}
|
||||
config: {type: 'object'},
|
||||
selfRegistration: {type: 'boolean'},
|
||||
domainWhitelist: {type: 'object'},
|
||||
autoEnrollGroups: {type: 'object'}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static async getEnabledStrategies() {
|
||||
return WIKI.db.authentication.query().where({ isEnabled: true })
|
||||
static async getStrategies() {
|
||||
const strategies = await WIKI.db.authentication.query()
|
||||
return strategies.map(str => ({
|
||||
...str,
|
||||
domainWhitelist: _.get(str.domainWhitelist, 'v', []),
|
||||
autoEnrollGroups: _.get(str.autoEnrollGroups, 'v', [])
|
||||
}))
|
||||
}
|
||||
|
||||
static async refreshStrategiesFromDisk() {
|
||||
@@ -46,7 +54,10 @@ module.exports = class Authentication extends Model {
|
||||
config: _.reduce(strategy.props, (result, value, key) => {
|
||||
_.set(result, value, '')
|
||||
return result
|
||||
}, {})
|
||||
}, {}),
|
||||
selfRegistration: false,
|
||||
domainWhitelist: { v: [] },
|
||||
autoEnrollGroups: { v: [] }
|
||||
})
|
||||
}
|
||||
})
|
||||
|
@@ -16,7 +16,7 @@ module.exports = {
|
||||
},
|
||||
AuthenticationQuery: {
|
||||
async strategies(obj, args, context, info) {
|
||||
let strategies = await WIKI.db.authentication.getEnabledStrategies()
|
||||
let strategies = await WIKI.db.authentication.getStrategies()
|
||||
strategies = strategies.map(stg => ({
|
||||
...stg,
|
||||
config: _.transform(stg.config, (res, value, key) => {
|
||||
|
@@ -56,6 +56,9 @@ type AuthenticationStrategy {
|
||||
useForm: Boolean!
|
||||
icon: String
|
||||
config: [KeyValuePair]
|
||||
selfRegistration: Boolean!
|
||||
domainWhitelist: [String]!
|
||||
autoEnrollGroups: [String]!
|
||||
}
|
||||
|
||||
type AuthenticationLoginResponse {
|
||||
|
@@ -24,7 +24,7 @@ module.exports = {
|
||||
return arr.filter(prvFilter.test)
|
||||
},
|
||||
orderBy (arr, orderString) {
|
||||
let orderParams = _.zip(orderString.split(',').map(ord => _.trim(ord).split(' ').map(_.trim)))
|
||||
let orderParams = _.zip(...orderString.split(',').map(ord => _.trim(ord).split(' ').map(_.trim)))
|
||||
return _.orderBy(arr, orderParams[0], orderParams[1])
|
||||
}
|
||||
}
|
||||
|
@@ -8,7 +8,7 @@ const GoogleStrategy = require('passport-google-oauth20').Strategy
|
||||
|
||||
module.exports = {
|
||||
key: 'google',
|
||||
title: 'Google ID',
|
||||
title: 'Google',
|
||||
useForm: false,
|
||||
props: ['clientId', 'clientSecret'],
|
||||
init (passport, conf) {
|
||||
|
Reference in New Issue
Block a user