Skip to content

Commit c80de55

Browse files
epelcoxisto
andauthored
Add explicit ClaimsValidator implementation check for custom claims (#343)
* Add explicit ClaimsValidator implementation check for custom claims Prevent user from misnaming or fat fingering the Validate() method implementation. * Update example_test.go --------- Co-authored-by: Christian Banse <oxisto@aybaze.com>
1 parent 1e76606 commit c80de55

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

example_test.go

+3
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,9 @@ type MyCustomClaims struct {
124124
jwt.RegisteredClaims
125125
}
126126

127+
// Ensure we implement [jwt.ClaimsValidator] at compile time so we know our custom Validate method is used.
128+
var_ jwt.ClaimsValidator= (*MyCustomClaims)(nil)
129+
127130
// Validate can be used to execute additional application-specific claims
128131
// validation.
129132
func (mMyCustomClaims) Validate() error {

0 commit comments

Comments
 (0)
close