Skip to content

Commit

Permalink
Fall back to using OIDC Subject instead of Email
Browse files Browse the repository at this point in the history
Email is not mandatory field, Subject is mandatory and expected to be unique. Might want to take a look at UserInfo first, however.

Issue: #56
  • Loading branch information
aigarius committed Feb 13, 2019
1 parent ec4444f commit 9b841b6
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion providers/oidc.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ func (p *OIDCProvider) createSessionState(ctx context.Context, token *oauth2.Tok

// Extract custom claims.
var claims struct {
Subject string `json:"sub"`
Email string `json:"email"`
Verified *bool `json:"email_verified"`
}
Expand All @@ -114,7 +115,8 @@ func (p *OIDCProvider) createSessionState(ctx context.Context, token *oauth2.Tok
}

if claims.Email == "" {
return nil, fmt.Errorf("id_token did not contain an email")
// TODO: Try getting email from /userinfo before falling back to Subject
claims.Email = claims.Subject
}
if claims.Verified != nil && !*claims.Verified {
return nil, fmt.Errorf("email in id_token (%s) isn't verified", claims.Email)
Expand Down

0 comments on commit 9b841b6

Please sign in to comment.