mirror of
https://github.com/coder/coder.git
synced 2025-07-08 11:39:50 +00:00
feat: allow configurable username claim field in OIDC (#5507)
Co-authored-by: Colin Adler <colin1adler@gmail.com>
This commit is contained in:
@ -1975,6 +1975,9 @@ const docTemplate = `{
|
||||
},
|
||||
"scopes": {
|
||||
"$ref": "#/definitions/codersdk.DeploymentConfigField-array_string"
|
||||
},
|
||||
"username_field": {
|
||||
"$ref": "#/definitions/codersdk.DeploymentConfigField-string"
|
||||
}
|
||||
}
|
||||
},
|
||||
|
@ -1795,6 +1795,9 @@
|
||||
},
|
||||
"scopes": {
|
||||
"$ref": "#/definitions/codersdk.DeploymentConfigField-array_string"
|
||||
},
|
||||
"username_field": {
|
||||
"$ref": "#/definitions/codersdk.DeploymentConfigField-string"
|
||||
}
|
||||
}
|
||||
},
|
||||
|
@ -880,6 +880,7 @@ func (o *OIDCConfig) OIDCConfig() *coderd.OIDCConfig {
|
||||
}, &oidc.Config{
|
||||
SkipClientIDCheck: true,
|
||||
}),
|
||||
UsernameField: "preferred_username",
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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)
|
||||
|
Reference in New Issue
Block a user