forked from mirror/jwt
More documentation
This commit is contained in:
parent
91f51d0f6b
commit
06a12c108b
|
@ -7,9 +7,6 @@ import (
|
|||
"strings"
|
||||
)
|
||||
|
||||
// DefaultValidator is the default validator that is used, if no custom validator is supplied in a Parser.
|
||||
var DefaultValidator = NewValidator()
|
||||
|
||||
type Parser struct {
|
||||
// If populated, only these methods will be considered valid.
|
||||
//
|
||||
|
|
15
validator.go
15
validator.go
|
@ -6,7 +6,10 @@ import (
|
|||
"time"
|
||||
)
|
||||
|
||||
// Validator is the core of the new Validation API. It is
|
||||
// Validator is the core of the new Validation API. It can either be used to
|
||||
// modify the validation used during parsing with the [WithValidator] parser
|
||||
// option or used standalone to validate an already parsed [Claim]. It can be
|
||||
// further customized with a range of specified [ValidatorOption]s.
|
||||
type Validator struct {
|
||||
// leeway is an optional leeway that can be provided to account for clock skew.
|
||||
leeway time.Duration
|
||||
|
@ -28,6 +31,8 @@ type Validator struct {
|
|||
}
|
||||
|
||||
type customValidationType interface {
|
||||
// CustomValidation can be implemented by a user-specific claim to support
|
||||
// additional validation steps in addition to the regular validation.
|
||||
CustomValidation() error
|
||||
}
|
||||
|
||||
|
@ -177,8 +182,8 @@ func verifyIat(iat *time.Time, now time.Time, required bool, skew time.Duration)
|
|||
return !required
|
||||
}
|
||||
|
||||
t := (*iat).Add(-skew)
|
||||
return now.After(t) || now.Equal(t)
|
||||
t := iat.Add(-skew)
|
||||
return !now.Before(t)
|
||||
}
|
||||
|
||||
func verifyNbf(nbf *time.Time, now time.Time, required bool, skew time.Duration) bool {
|
||||
|
@ -186,8 +191,8 @@ func verifyNbf(nbf *time.Time, now time.Time, required bool, skew time.Duration)
|
|||
return !required
|
||||
}
|
||||
|
||||
t := (*nbf).Add(-skew)
|
||||
return now.After(t) || now.Equal(t)
|
||||
t := nbf.Add(-skew)
|
||||
return !now.Before(t)
|
||||
}
|
||||
|
||||
func verifyIss(iss string, cmp string, required bool) bool {
|
||||
|
|
Loading…
Reference in New Issue