feat: new login experience (#2139)
* feat: multiple auth instances * fix: auth setup + strategy initialization * feat: admin auth - add strategy * feat: redirect on login - group setting * feat: oauth2 generic - props definitions * feat: new login UI (wip) * feat: new login UI (wip) * feat: admin security login settings * feat: tabset editor indicators + print view improvements * fix: code styling
This commit is contained in:
@@ -34,16 +34,28 @@ module.exports = {
|
||||
apiState () {
|
||||
return WIKI.config.api.isEnabled
|
||||
},
|
||||
async strategies () {
|
||||
return WIKI.data.authentication.map(stg => ({
|
||||
...stg,
|
||||
isAvailable: stg.isAvailable === true,
|
||||
props: _.sortBy(_.transform(stg.props, (res, value, key) => {
|
||||
res.push({
|
||||
key,
|
||||
value: JSON.stringify(value)
|
||||
})
|
||||
}, []), 'key')
|
||||
}))
|
||||
},
|
||||
/**
|
||||
* Fetch active authentication strategies
|
||||
*/
|
||||
async strategies (obj, args, context, info) {
|
||||
let strategies = await WIKI.models.authentication.getStrategies(args.isEnabled)
|
||||
async activeStrategies (obj, args, context, info) {
|
||||
let strategies = await WIKI.models.authentication.getStrategies()
|
||||
strategies = strategies.map(stg => {
|
||||
const strategyInfo = _.find(WIKI.data.authentication, ['key', stg.key]) || {}
|
||||
const strategyInfo = _.find(WIKI.data.authentication, ['key', stg.strategyKey]) || {}
|
||||
return {
|
||||
...strategyInfo,
|
||||
...stg,
|
||||
strategy: strategyInfo,
|
||||
config: _.sortBy(_.transform(stg.config, (res, value, key) => {
|
||||
const configData = _.get(strategyInfo.props, key, false)
|
||||
if (configData) {
|
||||
@@ -174,16 +186,18 @@ module.exports = {
|
||||
*/
|
||||
async updateStrategies (obj, args, context) {
|
||||
try {
|
||||
WIKI.config.auth = {
|
||||
audience: _.get(args, 'config.audience', WIKI.config.auth.audience),
|
||||
tokenExpiration: _.get(args, 'config.tokenExpiration', WIKI.config.auth.tokenExpiration),
|
||||
tokenRenewal: _.get(args, 'config.tokenRenewal', WIKI.config.auth.tokenRenewal)
|
||||
}
|
||||
await WIKI.configSvc.saveToDb(['auth'])
|
||||
// WIKI.config.auth = {
|
||||
// audience: _.get(args, 'config.audience', WIKI.config.auth.audience),
|
||||
// tokenExpiration: _.get(args, 'config.tokenExpiration', WIKI.config.auth.tokenExpiration),
|
||||
// tokenRenewal: _.get(args, 'config.tokenRenewal', WIKI.config.auth.tokenRenewal)
|
||||
// }
|
||||
// await WIKI.configSvc.saveToDb(['auth'])
|
||||
|
||||
for (let str of args.strategies) {
|
||||
await WIKI.models.authentication.query().patch({
|
||||
isEnabled: str.isEnabled,
|
||||
const previousStrategies = await WIKI.models.authentication.getStrategies()
|
||||
for (const str of args.strategies) {
|
||||
const newStr = {
|
||||
displayName: str.displayName,
|
||||
order: str.order,
|
||||
config: _.reduce(str.config, (result, value, key) => {
|
||||
_.set(result, `${value.key}`, _.get(JSON.parse(value.value), 'v', null))
|
||||
return result
|
||||
@@ -191,8 +205,32 @@ module.exports = {
|
||||
selfRegistration: str.selfRegistration,
|
||||
domainWhitelist: { v: str.domainWhitelist },
|
||||
autoEnrollGroups: { v: str.autoEnrollGroups }
|
||||
}).where('key', str.key)
|
||||
}
|
||||
|
||||
if (_.some(previousStrategies, ['key', str.key])) {
|
||||
await WIKI.models.authentication.query().patch({
|
||||
key: str.key,
|
||||
strategyKey: str.strategyKey,
|
||||
...newStr
|
||||
}).where('key', str.key)
|
||||
} else {
|
||||
await WIKI.models.authentication.query().insert({
|
||||
key: str.key,
|
||||
strategyKey: str.strategyKey,
|
||||
...newStr
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
for (const str of _.differenceBy(previousStrategies, args.strategies, 'key')) {
|
||||
const hasUsers = await WIKI.models.users.query().count('* as total').where({ providerKey: str.key }).first()
|
||||
if (_.toSafeInteger(hasUsers.total) > 0) {
|
||||
throw new Error(`Cannot delete ${str.displayName} as 1 or more users are still using it.`)
|
||||
} else {
|
||||
await WIKI.models.authentication.query().delete().where('key', str.key)
|
||||
}
|
||||
}
|
||||
|
||||
await WIKI.auth.activateStrategies()
|
||||
WIKI.events.outbound.emit('reloadAuthStrategies')
|
||||
return {
|
||||
|
Reference in New Issue
Block a user