Merge pull request #16181 from JoooostB/16180-oidc-auto-onboard

Store Username in auto-onboard flow (resolves #16180)
This commit is contained in:
Daniel Jiang 2022-01-25 11:00:38 +08:00 committed by GitHub
commit 60189f2cef
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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,