diff --git a/plugins/oidc/server/auth/oidc.ts b/plugins/oidc/server/auth/oidc.ts index 9a6de60d4..55c8234ed 100644 --- a/plugins/oidc/server/auth/oidc.ts +++ b/plugins/oidc/server/auth/oidc.ts @@ -94,11 +94,6 @@ if ( `An email field was not returned in the profile parameter, but is required.` ); } - if (!profile.name) { - throw AuthenticationError( - `A name field was not returned in the profile parameter, but is required.` - ); - } const team = await getTeamFromContext(ctx); const client = getClientFromContext(ctx); @@ -115,6 +110,13 @@ if ( // Claim name can be overriden using an env variable. // Default is 'preferred_username' as per OIDC spec. const username = get(profile, env.OIDC_USERNAME_CLAIM); + const name = profile.name || username || profile.username; + + if (!name) { + throw AuthenticationError( + `Neither a name or username was returned in the profile parameter, but at least one is required.` + ); + } const result = await accountProvisioner({ ip: ctx.ip, @@ -126,7 +128,7 @@ if ( subdomain, }, user: { - name: profile.name || username || profile.username, + name, email: profile.email, avatarUrl: profile.picture, },