feat(xo-server-auth-oidc): support email for username field (#6722)
Fixes https://xcp-ng.org/forum/post/59587
This commit is contained in:
@@ -7,6 +7,8 @@
|
||||
|
||||
> Users must be able to say: “Nice enhancement, I'm eager to test it”
|
||||
|
||||
- [Plugin/auth-oidc] Support `email` for _username field_ setting [Forum#59587](https://xcp-ng.org/forum/post/59587)
|
||||
|
||||
### Bug fixes
|
||||
|
||||
> Users must be able to say: “I had this issue, happy to know it's fixed”
|
||||
@@ -33,7 +35,7 @@
|
||||
|
||||
- @xen-orchestra/backups minor
|
||||
- xo-server minor
|
||||
- xo-server-auth-oidc patch
|
||||
- xo-server-auth-oidc minor
|
||||
- xo-web patch
|
||||
|
||||
<!--packages-end-->
|
||||
|
||||
@@ -33,7 +33,7 @@ exports.configurationSchema = {
|
||||
userInfoURL: { title: 'User info URL', type: 'string' },
|
||||
usernameField: {
|
||||
default: 'username',
|
||||
description: 'Field to use as the XO username',
|
||||
description: 'Field to use as the XO username (e.g. `displayName`, `username` or `email`)',
|
||||
title: 'Username field',
|
||||
type: 'string',
|
||||
},
|
||||
@@ -82,8 +82,14 @@ class AuthOidc {
|
||||
this.#unregisterPassportStrategy = xo.registerPassportStrategy(
|
||||
new Strategy(conf, async (issuer, profile, done) => {
|
||||
try {
|
||||
const { id, [usernameField]: name } = profile
|
||||
done(null, await xo.registerUser2('oidc:' + issuer, { user: { id, name } }))
|
||||
// See https://github.com/jaredhanson/passport-openidconnect/blob/master/lib/profile.js
|
||||
const { id } = profile
|
||||
done(
|
||||
null,
|
||||
await xo.registerUser2('oidc:' + issuer, {
|
||||
user: { id, name: usernameField === 'email' ? profile.emails[0].value : profile[usernameField] },
|
||||
})
|
||||
)
|
||||
} catch (error) {
|
||||
done(error.message)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user