Skip to content
Prev Previous commit
Next Next commit
feat(coderd): add full name from claims
  • Loading branch information
johnstcn committed Jun 5, 2024
commit c32a71c2fd38ef299b296ddb486ac83a28f58425
15 changes: 14 additions & 1 deletion coderd/userauth.go
Original file line number Diff line number Diff line change
Expand Up @@ -955,13 +955,21 @@ func (api *API) userOIDC(rw http.ResponseWriter, r *http.Request) {
}
}

// The 'name' is an optional property in Coder. If not specified,
// it will be left blank.
var fullName string
fullNameRaw, ok := mergedClaims[api.OIDCConfig.NameField]
if ok {
fullName, _ = fullNameRaw.(string)
}

var picture string
pictureRaw, ok := mergedClaims["picture"]
if ok {
picture, _ = pictureRaw.(string)
}

ctx = slog.With(ctx, slog.F("email", email), slog.F("username", username))
ctx = slog.With(ctx, slog.F("email", email), slog.F("username", username), slog.F("name", fullName))
usingGroups, groups, groupErr := api.oidcGroups(ctx, mergedClaims)
if groupErr != nil {
groupErr.Write(rw, r)
Expand Down Expand Up @@ -999,6 +1007,7 @@ func (api *API) userOIDC(rw http.ResponseWriter, r *http.Request) {
AllowSignups: api.OIDCConfig.AllowSignups,
Email: email,
Username: username,
Name: fullName,
AvatarURL: picture,
UsingRoles: api.OIDCConfig.RoleSyncEnabled(),
Roles: roles,
Expand Down Expand Up @@ -1548,6 +1557,10 @@ func (api *API) oauthLogin(r *http.Request, params *oauthLoginParams) ([]*http.C
user.AvatarURL = params.AvatarURL
needsUpdate = true
}
if user.Name != params.Name {
user.Name = params.Name
needsUpdate = true
}

// If the upstream email or username has changed we should mirror
// that in Coder. Many enterprises use a user's email/username as
Expand Down