Skip to content

Commit

Permalink
Add explicit ClaimsValidator implementation check for custom claims (#…
Browse files Browse the repository at this point in the history
…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>
  • Loading branch information
epelc and oxisto committed Sep 13, 2023
1 parent 1e76606 commit c80de55
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit c80de55

Please sign in to comment.