feat: allow configurable username claim field in OIDC (#5507)

Co-authored-by: Colin Adler <colin1adler@gmail.com>
This commit is contained in:
Jan Losinski
2023-01-04 22:16:31 +01:00
committed by GitHub
parent 8968a00035
commit de0601d611
11 changed files with 59 additions and 3 deletions

View File

@ -198,6 +198,9 @@ type OIDCConfig struct {
// IgnoreEmailVerified allows ignoring the email_verified claim
// from an upstream OIDC provider. See #5065 for context.
IgnoreEmailVerified bool
// UsernameField selects the claim field to be used as the created user's
// username.
UsernameField string
}
func (api *API) userOIDC(rw http.ResponseWriter, r *http.Request) {
@ -236,7 +239,7 @@ func (api *API) userOIDC(rw http.ResponseWriter, r *http.Request) {
})
return
}
usernameRaw, ok := claims["preferred_username"]
usernameRaw, ok := claims[api.OIDCConfig.UsernameField]
var username string
if ok {
username, _ = usernameRaw.(string)