fix: Store Username in auto-onboard flow

Signed-off-by: Joost Buskermolen <joost@buskervezel.nl>

fix: Remove conditional & elaborate comment on fix

Signed-off-by: Joost Buskermolen <joost@buskervezel.nl>

Add conditional to res.Username override

Signed-off-by: Joost Buskermolen <joost@buskervezel.nl>

test: Set Username based on configured UserClaim

Signed-off-by: Joost Buskermolen <joost@buskervezel.nl>

fix: Remove breaking conditional
Username may be set already if the token has a name claim.
Username is should always be set as the autoOnboard setting.

Signed-off-by: Joost Buskermolen <joost@buskervezel.nl>

Remove conditional altogether
autoOnboardUsername should always be the same as Username

Signed-off-by: Joost Buskermolen <joost@buskervezel.nl>
This commit is contained in:
Joost Buskermolen 2021-12-30 14:15:52 +01:00
parent 5cd5bcaee4
commit c103a6e9ef
No known key found for this signature in database
GPG Key ID: E325635BD6C50C2B
2 changed files with 5 additions and 2 deletions

View File

@ -355,7 +355,10 @@ func userInfoFromClaims(c claimsProvider, setting cfgModels.OIDCSetting) (*UserI
}
if username, ok := allClaims[setting.UserClaim].(string); ok {
res.autoOnboardUsername = username
// res.Username and autoOnboardUsername both need to be set to create a fallback when mergeUserInfo has not been successfully called.
// This can for example occur when remote fails and only a local token is available for onboarding.
// Otherwise the onboard flow only has a fallback when "name" is set in the token, which is not always the case as a custom Username Claim could be configured.
res.autoOnboardUsername, res.Username = username, username
} else {
log.Warningf("OIDC. Failed to recover Username from claim. Claim '%s' is invalid or not a string", setting.UserClaim)
}

View File

@ -284,7 +284,7 @@ func TestUserInfoFromClaims(t *testing.T) {
Issuer: "",
Subject: "",
autoOnboardUsername: "airadier@gmail.com",
Username: "Alvaro",
Username: "airadier@gmail.com", // Set Username based on configured UserClaim
Email: "airadier@gmail.com",
Groups: []string{},
hasGroupClaim: false,