File tree Expand file tree Collapse file tree 2 files changed +8
-12
lines changed Expand file tree Collapse file tree 2 files changed +8
-12
lines changed Original file line number Diff line number Diff line change @@ -121,7 +121,9 @@ type MyCustomClaims struct {
121
121
jwt.RegisteredClaims
122
122
}
123
123
124
- func (m MyCustomClaims ) CustomValidation () error {
124
+ // Validate can be used to execute additional application-specific claims
125
+ // validation.
126
+ func (m MyCustomClaims ) Validate () error {
125
127
if m .Foo != "bar" {
126
128
return errors .New ("must be foobar" )
127
129
}
Original file line number Diff line number Diff line change @@ -39,14 +39,6 @@ type validator struct {
39
39
expectedSub string
40
40
}
41
41
42
- // customClaims represents a custom claims interface, which can be built upon the integrated
43
- // claim types, such as map claims or registered claims.
44
- type customClaims interface {
45
- // CustomValidation can be implemented by a user-specific claim to support
46
- // additional validation steps in addition to the regular validation.
47
- CustomValidation () error
48
- }
49
-
50
42
// newValidator can be used to create a stand-alone validator with the supplied
51
43
// options. This validator can then be used to validate already parsed claims.
52
44
func newValidator (opts ... ParserOption ) * validator {
@@ -102,10 +94,12 @@ func (v *validator) Validate(claims Claims) error {
102
94
}
103
95
104
96
// Finally, we want to give the claim itself some possibility to do some
105
- // additional custom validation based on a custom function
106
- cvt , ok := claims .(customClaims )
97
+ // additional custom validation based on a custom Validate function.
98
+ cvt , ok := claims .(interface {
99
+ Validate () error
100
+ })
107
101
if ok {
108
- if err := cvt .CustomValidation (); err != nil {
102
+ if err := cvt .Validate (); err != nil {
109
103
errs = append (errs , err )
110
104
}
111
105
}
You can’t perform that action at this time.
0 commit comments