feat: oauth2 add groups mapping (#6053)
Co-authored-by: Nicolas Giard <github@ngpixel.com>
This commit is contained in:
@@ -31,6 +31,19 @@ module.exports = {
|
||||
email: _.get(profile, conf.emailClaim)
|
||||
}
|
||||
})
|
||||
if (conf.mapGroups) {
|
||||
const groups = _.get(profile, conf.groupsClaim)
|
||||
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)
|
||||
|
||||
Reference in New Issue
Block a user