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>
This commit is contained in:
Ed Pelc 2023-09-13 09:34:54 -04:00 committed by GitHub
parent 1e76606719
commit c80de55abe
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 3 additions and 0 deletions

View File

@ -124,6 +124,9 @@ type MyCustomClaims struct {
jwt.RegisteredClaims
}
// Ensure we implement [jwt.ClaimsValidator] at compile time so we know our custom Validate method is used.
var _ jwt.ClaimsValidator = (*MyCustomClaims)(nil)
// Validate can be used to execute additional application-specific claims
// validation.
func (m MyCustomClaims) Validate() error {