mirror of
https://github.com/goharbor/harbor.git
synced 2024-11-15 23:05:57 +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
6
src/pkg/oidc/helper.go
Normal file → Executable file
6
src/pkg/oidc/helper.go
Normal file → Executable file
@ -289,9 +289,13 @@ func mergeUserInfo(remote, local *UserInfo) *UserInfo {
|
||||
Subject: local.Subject,
|
||||
Issuer: local.Issuer,
|
||||
// Used data from userinfo
|
||||
Username: remote.Username,
|
||||
Email: remote.Email,
|
||||
}
|
||||
if remote.Username != "" {
|
||||
res.Username = remote.Username
|
||||
} else {
|
||||
res.Username = local.Username
|
||||
}
|
||||
if remote.hasGroupClaim {
|
||||
res.Groups = remote.Groups
|
||||
res.AdminGroupMember = remote.AdminGroupMember
|
||||
|
@ -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