From ac8ee77a8fcf76d4c80113ff8fce2cf3e1e08f94 Mon Sep 17 00:00:00 2001 From: Ed Pelc Date: Thu, 7 Sep 2023 16:59:55 -0400 Subject: [PATCH] Add explicit ClaimsValidator implementation check for custom claims Prevent user from misnaming or fat fingering the Validate() method implementation. --- example_test.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/example_test.go b/example_test.go index 0df31244..4923d513 100644 --- a/example_test.go +++ b/example_test.go @@ -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 {