mirror of
https://github.com/goharbor/harbor.git
synced 2024-12-27 02:58:05 +01:00
Merge pull request #15291 from kschu91/bugfix/15290
if username is not available in remote, fall back to username from token
This commit is contained in:
commit
cdb13f5191
8
src/pkg/oidc/helper.go
Normal file → Executable file
8
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
|
||||
|
@ -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