Skip to content

Commit

Permalink
Add explicit ClaimsValidator implementation check for custom claims
Browse files Browse the repository at this point in the history
Prevent user from misnaming or fat fingering the Validate() method implementation.
  • Loading branch information
epelc authored Sep 7, 2023
1 parent 6879d2c commit ac8ee77
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{}

// Validate can be used to execute additional application-specific claims
// validation.
func (m MyCustomClaims) Validate() error {
Expand Down

0 comments on commit ac8ee77

Please sign in to comment.