feat: auth self-registration config + gql grouping

This commit is contained in:
NGPixel
2018-06-25 02:44:40 -04:00
parent 49834461a6
commit 0afa65fa58
39 changed files with 104 additions and 50 deletions

View File

@@ -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)

View File

@@ -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 => {

View File

@@ -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: [] }
})
}
})

View File

@@ -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) => {

View File

@@ -56,6 +56,9 @@ type AuthenticationStrategy {
useForm: Boolean!
icon: String
config: [KeyValuePair]
selfRegistration: Boolean!
domainWhitelist: [String]!
autoEnrollGroups: [String]!
}
type AuthenticationLoginResponse {

View File

@@ -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])
}
}

View File

@@ -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) {