File tree Expand file tree Collapse file tree 2 files changed +18
-2
lines changed Expand file tree Collapse file tree 2 files changed +18
-2
lines changed Original file line number Diff line number Diff line change @@ -21,6 +21,10 @@ type Validator struct {
21
21
// necessary. However, if wanted, it can be checked if the iat is
22
22
// unrealistic, i.e., in the future.
23
23
verifyIat bool
24
+
25
+ // expectedAud contains the audiences this token expects. Supplying an empty
26
+ // string will disable aud checking.
27
+ expectedAud string
24
28
}
25
29
26
30
type customValidationType interface {
@@ -67,6 +71,11 @@ func (v *Validator) Validate(claims Claims) error {
67
71
vErr .Errors |= ValidationErrorNotValidYet
68
72
}
69
73
74
+ if v .expectedAud != "" && ! v .VerifyAudience (claims , v .expectedAud , false ) {
75
+ vErr .Inner = ErrTokenNotValidYet
76
+ vErr .Errors |= ValidationErrorNotValidYet
77
+ }
78
+
70
79
// Finally, we want to give the claim itself some possibility to do some
71
80
// additional custom validation based on their custom claims
72
81
cvt , ok := claims .(customValidationType )
Original file line number Diff line number Diff line change @@ -25,10 +25,17 @@ func WithTimeFunc(f func() time.Time) ValidatorOption {
25
25
}
26
26
}
27
27
28
- // WithIssuedAtVerification returns the ValidatorOption to enable verification
28
+ // WithIssuedAt returns the ValidatorOption to enable verification
29
29
// of issued-at.
30
- func WithIssuedAtVerification () ValidatorOption {
30
+ func WithIssuedAt () ValidatorOption {
31
31
return func (v * Validator ) {
32
32
v .verifyIat = true
33
33
}
34
34
}
35
+
36
+ // WithAudience returns the ValidatorOption to set the expected audience.
37
+ func WithAudience (aud string ) ValidatorOption {
38
+ return func (v * Validator ) {
39
+ v .expectedAud = aud
40
+ }
41
+ }
You can’t perform that action at this time.
0 commit comments