From c80de55abe70cd72904468ed68e98dfd825fb0b1 Mon Sep 17 00:00:00 2001 From: Ed Pelc Date: Wed, 13 Sep 2023 09:34:54 -0400 Subject: [PATCH] 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 --- example_test.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/example_test.go b/example_test.go index 0df3124..932ee4c 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)(nil) + // Validate can be used to execute additional application-specific claims // validation. func (m MyCustomClaims) Validate() error {