Skip to content

Commit

Permalink
Adjust behaviour of WithIssuedAt ParserOption (#411)
Browse files Browse the repository at this point in the history
  • Loading branch information
sknr committed Oct 17, 2024
1 parent 5ec246c commit 72c8910
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
9 changes: 4 additions & 5 deletions validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,11 +112,10 @@ func (v *Validator) Validate(claims Claims) error {
errs = append(errs, err)
}

// Check issued-at if the option is enabled
if v.verifyIat {
if err = v.verifyIssuedAt(claims, now, false); err != nil {
errs = append(errs, err)
}
// Check issued-at if the option is enabled, but usage of the claim
// itself is OPTIONAL.
if err = v.verifyIssuedAt(claims, now, v.verifyIat); err != nil {
errs = append(errs, err)
}

// If we have an expected audience, we also require the audience claim
Expand Down
10 changes: 8 additions & 2 deletions validator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -231,17 +231,23 @@ func Test_Validator_verifyIssuedAt(t *testing.T) {
}{
{
name: "good claim without iat",
fields: fields{verifyIat: true},
fields: fields{verifyIat: false},
args: args{claims: MapClaims{}, required: false},
wantErr: nil,
},
{
name: "bad claim without iat",
fields: fields{verifyIat: true},
args: args{claims: MapClaims{}, required: true},
wantErr: ErrTokenRequiredClaimMissing,
},
{
name: "good claim with iat",
fields: fields{verifyIat: true},
args: args{
claims: RegisteredClaims{IssuedAt: NewNumericDate(time.Now())},
cmp: time.Now().Add(10 * time.Minute),
required: false,
required: true,
},
wantErr: nil,
},
Expand Down

0 comments on commit 72c8910

Please sign in to comment.