-
Notifications
You must be signed in to change notification settings - Fork 1.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adding oidc email scope check #1610
Conversation
32038d8
to
45bc3be
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, only a few suggestions
connector/oidc/oidc.go
Outdated
EmailVerified: emailVerified, | ||
ConnectorData: connData, | ||
} | ||
if email != "" { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This check is not necessary because of default values.
connector/oidc/oidc.go
Outdated
@@ -302,10 +315,12 @@ func (c *oidcConnector) createIdentity(ctx context.Context, identity connector.I | |||
identity = connector.Identity{ | |||
UserID: idToken.Subject, | |||
Username: name, | |||
Email: email, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would revert this, because it doesn't change behavior at all.
Further thinking about this: |
7f049f0
to
cbed29a
Compare
Yep, it has sense. I will change the behavior according to your thoughts. |
b03ed83
to
c4ebee2
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A few more nits
connector/oidc/oidc.go
Outdated
@@ -262,15 +262,28 @@ func (c *oidcConnector) createIdentity(ctx context.Context, identity connector.I | |||
if !found { | |||
return identity, fmt.Errorf("missing \"%s\" claim", userNameKey) | |||
} | |||
|
|||
emailInScopes := func() bool { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about:
hasEmailScope := false
for _, s := range c.oauth2Config.Scopes {
if s == "email" {
hasEmailScope = true
break
}
}
Feels a bit cleaner and more readable
connector/oidc/oidc.go
Outdated
email, found := claims["email"].(string) | ||
if !found { | ||
return identity, errors.New("missing \"email\" claim") | ||
if emailInScopes { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You could merge these two if
s. The default value of email is an empty string because of the type.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, you are right. Fixed.
This helps to avoid "no email claim" error if email scope was not specified. Signed-off-by: m.nabokikh <maksim.nabokikh@flant.com>
c4ebee2
to
383c2fe
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @nabokihms
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
This helps to avoid "no email claim" error if the email scope was not specified.
Signed-off-by: m.nabokikh maksim.nabokikh@flant.com
Closes #1598