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 {
121121 jwt.RegisteredClaims
122122}
123123
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 {
125127 if m .Foo != "bar" {
126128 return errors .New ("must be foobar" )
127129 }
Original file line number Diff line number Diff line change @@ -39,14 +39,6 @@ type validator struct {
3939 expectedSub string
4040}
4141
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-
5042// newValidator can be used to create a stand-alone validator with the supplied
5143// options. This validator can then be used to validate already parsed claims.
5244func newValidator (opts ... ParserOption ) * validator {
@@ -102,10 +94,12 @@ func (v *validator) Validate(claims Claims) error {
10294 }
10395
10496 // 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+ })
107101 if ok {
108- if err := cvt .CustomValidation (); err != nil {
102+ if err := cvt .Validate (); err != nil {
109103 errs = append (errs , err )
110104 }
111105 }
You can’t perform that action at this time.
0 commit comments