mirror of
https://github.com/goharbor/harbor.git
synced 2024-11-07 02:59:50 +01:00
if username is not available in remote, fall back to username from token
Signed-off-by: Kevin Schu <kevin.schu@aoe.com>
This commit is contained in:
parent
29ccdff766
commit
0679f4701e
9
src/pkg/oidc/helper.go
Normal file → Executable file
9
src/pkg/oidc/helper.go
Normal file → Executable file
@ -289,8 +289,12 @@ func mergeUserInfo(remote, local *UserInfo) *UserInfo {
|
||||
Subject: local.Subject,
|
||||
Issuer: local.Issuer,
|
||||
// Used data from userinfo
|
||||
Username: remote.Username,
|
||||
Email: remote.Email,
|
||||
Email: remote.Email,
|
||||
}
|
||||
if remote.Username != "" {
|
||||
res.Username = remote.Username
|
||||
} else {
|
||||
res.Username = local.Username
|
||||
}
|
||||
if remote.hasGroupClaim {
|
||||
res.Groups = remote.Groups
|
||||
@ -346,6 +350,7 @@ func userInfoFromClaims(c claimsProvider, setting cfgModels.OIDCSetting) (*UserI
|
||||
if username, ok := allClaims[setting.UserClaim].(string); ok {
|
||||
res.Username = username
|
||||
} else {
|
||||
log.Debugf("OIDC. Failed to recover Username from claims: %+v", allClaims)
|
||||
log.Warningf("OIDC. Failed to recover Username from claim. Claim '%s' is invalid or not a string", setting.UserClaim)
|
||||
}
|
||||
}
|
||||
|
@ -379,6 +379,32 @@ func TestMergeUserInfo(t *testing.T) {
|
||||
hasGroupClaim: true,
|
||||
},
|
||||
},
|
||||
{
|
||||
fromInfo: &UserInfo{
|
||||
Issuer: "",
|
||||
Subject: "",
|
||||
Username: "",
|
||||
Email: "kevin@whatever.com",
|
||||
Groups: []string{},
|
||||
hasGroupClaim: false,
|
||||
},
|
||||
fromIDToken: &UserInfo{
|
||||
Issuer: "issuer-whatever",
|
||||
Subject: "subject-kevin",
|
||||
Username: "kevin",
|
||||
Email: "kevin@whatever.com",
|
||||
Groups: []string{"g1", "g2"},
|
||||
hasGroupClaim: true,
|
||||
},
|
||||
expected: &UserInfo{
|
||||
Issuer: "issuer-whatever",
|
||||
Subject: "subject-kevin",
|
||||
Username: "kevin",
|
||||
Email: "kevin@whatever.com",
|
||||
Groups: []string{"g1", "g2"},
|
||||
hasGroupClaim: true,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
for _, tc := range s {
|
||||
|
Loading…
Reference in New Issue
Block a user