feat(xo-server-auth-oidc): support email for username field (#6722)

Fixes https://xcp-ng.org/forum/post/59587
This commit is contained in:
Julien Fontanet
2023-03-13 15:26:03 +01:00
committed by GitHub
parent 299803f03c
commit 5a2c315b20
2 changed files with 12 additions and 4 deletions

View File

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

View File

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