feat: Set groups based on Azure groups

pull/7736/head
Ole Christian Tvedt 4 months ago
parent 07855ab329
commit 94ee71ffe9

@ -48,6 +48,19 @@ module.exports = {
picture: ''
}
})
if (conf.mapGroups) {
const groups = _.get(profile, '_json.groups')
if (groups && _.isArray(groups)) {
const currentGroups = (await user.$relatedQuery('groups').select('groups.id')).map(g => g.id)
const expectedGroups = Object.values(WIKI.auth.groups).filter(g => groups.includes(g.name)).map(g => g.id)
for (const groupId of _.difference(expectedGroups, currentGroups)) {
await user.$relatedQuery('groups').relate(groupId)
}
for (const groupId of _.difference(currentGroups, expectedGroups)) {
await user.$relatedQuery('groups').unrelate().where('groupId', groupId)
}
}
}
cb(null, user)
} catch (err) {
cb(err, null)

@ -27,3 +27,9 @@ props:
title: Cookie Encryption Key String
hint: Random string with 44-character length. Setting this enables workaround for Chrome's SameSite cookies.
order: 3
mapGroups:
type: Boolean
title: Map Groups
hint: Map groups matching names from the groups claim value
default: false
order: 4

Loading…
Cancel
Save