-
Notifications
You must be signed in to change notification settings - Fork 361
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
HdonCr/Allow multiple audiences #427
base: main
Are you sure you want to change the base?
Conversation
Hi! Looks like we have two PRs now for the same issue :) I will take some time after the holidays with @mfridman to see which direction we will follow. |
@@ -55,6 +55,13 @@ type Validator struct { | |||
// string will disable aud checking. | |||
expectedAud string | |||
|
|||
//expectedAuds contains the audiences this token expects. Supplying an empty | |||
// []string will disable auds checking. | |||
expectedAuds []string |
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 wonder whether we could merge this with the expectedAud
above
expectedAuds []string | ||
|
||
// expectedAudsMatchAll specifies whether all expected audiences must match all auds from claim | ||
expectedAudsMatchAll 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.
I would prefer a name like matchAllAud
@@ -126,6 +133,13 @@ func (v *Validator) Validate(claims Claims) error { | |||
} | |||
} | |||
|
|||
// If we have expected audiences, we also require the audiences claim | |||
if len(v.expectedAuds) != 0 { |
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.
should be > 0
just to be safe
// | ||
// Additionally, if any error occurs while retrieving the claim, e.g., when its | ||
// the wrong type, an ErrTokenUnverifiable error will be returned. | ||
func (v *Validator) verifyAudiences(claims Claims, cmps []string, required bool, matchAllAuds bool) error { |
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 function seems to be very complex, I wonder if we could streamline this implementation a little bit. Furthermore, it should be possible to include the previous implementation of verifyAudience
in this as well - or rather merge the two since one is just a special case of the other.
for _, a := range aud { | ||
|
||
// Perform constant time comparison | ||
result := subtle.ConstantTimeCompare([]byte(a), []byte(cmp)) != 0 |
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.
quite a large duplicate code fragment, this is essentially what the existing verifyAudience
does. why not use it?
for _, cmp := range cmps { | ||
|
||
// Perform constant time comparison | ||
result := subtle.ConstantTimeCompare([]byte(a), []byte(cmp)) != 0 |
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.
see above
Allow for multiple expected audiences as requested in issue 342.