Skip to content
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

jwt: use AnyAudience matching #81

Merged
merged 1 commit into from
Dec 12, 2023
Merged

jwt: use AnyAudience matching #81

merged 1 commit into from
Dec 12, 2023

Conversation

jsha
Copy link
Collaborator

@jsha jsha commented Dec 12, 2023

Previously, the Expected.Audience field meant "all of these audiences must be present in the token." But that doesn't really make sense with the spec:

https://datatracker.ietf.org/doc/html/rfc7519#section-4.1.3

Instead, rename the field to AnyAudience and changes its semantics to mean "there must be an intersection between this set and the set of audiences in the token."

Re-land of #10 on the main (v4) branch. Followup of #23 and #24. cc @shnmorimoto

Previously, the `Expected.Audience` field meant "all of these audiences
must be present in the token." But that doesn't really make sense with
the spec:

https://datatracker.ietf.org/doc/html/rfc7519#section-4.1.3

Instead, rename the field to `AnyAudience` and changes its semantics to
mean "there must be an intersection between this set and the set of
audiences in the token."
Comment on lines +92 to +103
if len(e.AnyAudience) != 0 {
var intersection bool
for _, v := range e.AnyAudience {
if c.Audience.Contains(v) {
intersection = true
break
}
}

if !intersection {
return ErrInvalidAudience
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we're on >= go1.21 we could also do:

if len(e.AnyAudience) != 0 && !slices.Contains(c.Audience, e.AnyAudience...) {
    return ErrInvalidAudience
}

@jsha jsha merged commit 7c8ceda into main Dec 12, 2023
3 checks passed
@jsha jsha deleted the multi-audience branch December 12, 2023 18:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants