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 15:16:31 -06:00
committed by GitHub
co-authored by Colin Adler
parent 8968a00035
commit de0601d611
11 changed files with 59 additions and 3 deletions
+3
View File
@@ -1975,6 +1975,9 @@ const docTemplate = `{
},
"scopes": {
"$ref": "#/definitions/codersdk.DeploymentConfigField-array_string"
},
"username_field": {
"$ref": "#/definitions/codersdk.DeploymentConfigField-string"
}
}
},
+3
View File
@@ -1795,6 +1795,9 @@
},
"scopes": {
"$ref": "#/definitions/codersdk.DeploymentConfigField-array_string"
},
"username_field": {
"$ref": "#/definitions/codersdk.DeploymentConfigField-string"
}
}
},
+1
View File
@@ -880,6 +880,7 @@ func (o *OIDCConfig) OIDCConfig() *coderd.OIDCConfig {
}, &oidc.Config{
SkipClientIDCheck: true,
}),
UsernameField: "preferred_username",
}
}
+4 -1
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)