Fix a potential nil pointer issue

Signed-off-by: Daniel Jiang <jiangd@vmware.com>
This commit is contained in:
Daniel Jiang 2021-01-22 19:02:45 +08:00
parent 8e7a18dc80
commit 5ea43abc67
2 changed files with 5 additions and 4 deletions

View File

@ -264,10 +264,6 @@ func UserInfoFromToken(ctx context.Context, token *Token) (*UserInfo, error) {
if err != nil {
log.Warningf("Failed to get userInfo by calling remote userinfo endpoint, error: %v ", err)
}
if setting.UserClaim != "" && local.Username == "" && remote.Username == "" {
return nil, fmt.Errorf("OIDC. Failed to recover Username from claim. Claim '%s' is invalid or not a string", setting.UserClaim)
}
if remote != nil && local != nil {
if remote.Subject != local.Subject {
return nil, fmt.Errorf("the subject from userinfo: %s does not match the subject from ID token: %s, probably a security attack happened", remote.Subject, local.Subject)

View File

@ -137,6 +137,11 @@ func (oc *OIDCController) Callback() {
// If automatic onboard is enabled, skip the onboard page
if oidcSettings.AutoOnboard {
log.Debug("Doing automatic onboarding\n")
if username == "" {
oc.SendInternalServerError(fmt.Errorf("unable to recover username for auto onboard, username claim: %s",
oidcSettings.UserClaim))
return
}
user, onboarded := userOnboard(oc, info, username, tokenBytes)
if onboarded == false {
log.Error("User not onboarded\n")