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:
Daniel Jiang 2021-08-17 16:58:46 +08:00 committed by GitHub
commit cdb13f5191
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 32 additions and 2 deletions

8
src/pkg/oidc/helper.go Normal file → Executable file
View 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

View File

@ -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 {