Can this use a keyset?

This commit is contained in:
Annika Merris 2024-02-09 16:25:21 -05:00
parent a77c65043f
commit 7e7e71ba74

View file

@ -8,6 +8,7 @@ import (
"time"
"github.com/lestrrat-go/jwx/v2/jwa"
"github.com/lestrrat-go/jwx/v2/jwk"
"github.com/lestrrat-go/jwx/v2/jwt"
)
@ -33,7 +34,7 @@ var (
ErrAlgoInvalid = errors.New("algorithm mismatch")
)
func New(alg string, signKey interface{}, verifyKey interface{}, validateOptions ...jwt.ValidateOption) *JWTAuth {
func New(alg string, signKey interface{}, verifyKey interface{}, jwkSet jwk.Set, validateOptions ...jwt.ValidateOption) *JWTAuth {
ja := &JWTAuth{
alg: jwa.SignatureAlgorithm(alg),
signKey: signKey,
@ -41,7 +42,9 @@ func New(alg string, signKey interface{}, verifyKey interface{}, validateOptions
validateOptions: validateOptions,
}
if ja.verifyKey != nil {
if jwkSet != nil {
ja.verifier = jwt.WithKeySet(jwkSet)
} else if ja.verifyKey != nil {
ja.verifier = jwt.WithKey(ja.alg, ja.verifyKey)
} else {
ja.verifier = jwt.WithKey(ja.alg, ja.signKey)