Apply suggestions from code review

Co-authored-by: Micah Parks <66095735+MicahParks@users.noreply.github.com>
This commit is contained in:
Christian Banse 2022-10-15 22:21:15 +02:00 committed by GitHub
parent eedf3ebe01
commit 91f51d0f6b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 4 additions and 2 deletions

View File

@ -89,7 +89,7 @@ func (p *Parser) ParseWithClaims(tokenString string, claims Claims, keyFunc Keyf
if !p.SkipClaimsValidation {
// Make sure we have at least a default validator
if p.validator == nil {
p.validator = DefaultValidator
p.validator = NewValidator()
}
if err := p.validator.Validate(claims); err != nil {

View File

@ -28,6 +28,7 @@ func WithoutClaimsValidation() ParserOption {
}
}
// WithValidator is an option to include a claims validator.
func WithValidator(v *Validator) ParserOption {
return func(p *Parser) {
p.validator = v

View File

@ -42,6 +42,7 @@ func NewValidator(opts ...ValidatorOption) *Validator {
return v
}
// Validate validates the given claims. It will also perform any custom validation if claims implements the CustomValidator interface.
func (v *Validator) Validate(claims Claims) error {
var now time.Time
vErr := new(ValidationError)
@ -156,7 +157,7 @@ func verifyAud(aud []string, cmp string, required bool) bool {
}
// case where "" is sent in one or many aud claims
if len(stringClaims) == 0 {
if stringClaims == "" {
return !required
}