Skip to content

Commit

Permalink
Merge pull request #10 from shnmorimoto/fix-allow-multiple-audiences
Browse files Browse the repository at this point in the history
Fix allow multiple audiences
  • Loading branch information
csstaub committed May 20, 2022
2 parents 6f2534b + 07268a3 commit 3258646
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
9 changes: 7 additions & 2 deletions jwt/validation.go
Expand Up @@ -89,11 +89,16 @@ func (c Claims) ValidateWithLeeway(e Expected, leeway time.Duration) error {
}

if len(e.Audience) != 0 {
flag := false
for _, v := range e.Audience {
if !c.Audience.Contains(v) {
return ErrInvalidAudience
if c.Audience.Contains(v) {
flag = true
break
}
}
if !flag {
return ErrInvalidAudience
}
}

// validate using the e.Time, or time.Now if not provided
Expand Down
11 changes: 11 additions & 0 deletions jwt/validation_test.go
Expand Up @@ -44,6 +44,17 @@ func TestFieldsMatch(t *testing.T) {
assert.NoError(t, c.Validate(v))
}

claimsWithSingleAudience := Claims{
Issuer: "issuer",
Subject: "subject",
Audience: []string{"a1"},
ID: "42",
}

for _, v := range valid {
assert.NoError(t, claimsWithSingleAudience.Validate(v))
}

invalid := []struct {
Expected Expected
Error error
Expand Down

0 comments on commit 3258646

Please sign in to comment.