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

Adjust behaviour of WithIssuedAt ParserOption (#411) #412

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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