diff --git a/parser.go b/parser.go index ecf99af7..07235099 100644 --- a/parser.go +++ b/parser.go @@ -93,7 +93,7 @@ func (p *Parser) ParseWithClaims(tokenString string, claims Claims, keyFunc Keyf } switch have := got.(type) { - case VerificationKeySet: + case VerificationKeySet[VerificationKey]: if len(have.Keys) == 0 { return token, newError("keyfunc returned empty verification key set", ErrTokenUnverifiable) } diff --git a/parser_test.go b/parser_test.go index c0f81711..d3f6ddf0 100644 --- a/parser_test.go +++ b/parser_test.go @@ -30,22 +30,26 @@ var ( nilKeyFunc jwt.Keyfunc = nil multipleZeroKeyFunc jwt.Keyfunc = func(t *jwt.Token) (interface{}, error) { return []interface{}{}, nil } multipleEmptyKeyFunc jwt.Keyfunc = func(t *jwt.Token) (interface{}, error) { - return jwt.VerificationKeySet{Keys: []jwt.VerificationKey{nil, nil}}, nil + keys := []jwt.VerificationKey{nil, nil} + return jwt.VerificationKeySet[jwt.VerificationKey]{Keys: keys}, nil } multipleVerificationKeysFunc jwt.Keyfunc = func(t *jwt.Token) (interface{}, error) { return []jwt.VerificationKey{jwtTestDefaultKey, jwtTestEC256PublicKey}, nil } multipleLastKeyFunc jwt.Keyfunc = func(t *jwt.Token) (interface{}, error) { - return jwt.VerificationKeySet{Keys: []jwt.VerificationKey{jwtTestEC256PublicKey, jwtTestDefaultKey}}, nil + keys := []jwt.VerificationKey{jwtTestEC256PublicKey, jwtTestDefaultKey} + return jwt.VerificationKeySet[jwt.VerificationKey]{Keys: keys}, nil } multipleFirstKeyFunc jwt.Keyfunc = func(t *jwt.Token) (interface{}, error) { - return jwt.VerificationKeySet{Keys: []jwt.VerificationKey{jwtTestDefaultKey, jwtTestEC256PublicKey}}, nil + keys := []jwt.VerificationKey{jwtTestDefaultKey, jwtTestEC256PublicKey} + return jwt.VerificationKeySet[jwt.VerificationKey]{Keys: keys}, nil } multipleAltTypedKeyFunc jwt.Keyfunc = func(t *jwt.Token) (interface{}, error) { - return jwt.VerificationKeySet{Keys: []jwt.VerificationKey{jwtTestDefaultKey, jwtTestDefaultKey}}, nil + keys := []jwt.VerificationKey{jwtTestDefaultKey, jwtTestDefaultKey} + return jwt.VerificationKeySet[jwt.VerificationKey]{Keys: keys}, nil } emptyVerificationKeySetFunc jwt.Keyfunc = func(t *jwt.Token) (interface{}, error) { - return jwt.VerificationKeySet{}, nil + return jwt.VerificationKeySet[jwt.VerificationKey]{}, nil } ) diff --git a/token.go b/token.go index 352873a2..15cbce27 100644 --- a/token.go +++ b/token.go @@ -21,8 +21,8 @@ type VerificationKey interface { } // VerificationKeySet is a set of public or secret keys. It is used by the parser to verify a token. -type VerificationKeySet struct { - Keys []VerificationKey +type VerificationKeySet[T VerificationKey] struct { + Keys []T } // Token represents a JWT Token. Different fields will be used depending on