From 620113e5ff939d60080d83fdbb423d64422e3675 Mon Sep 17 00:00:00 2001 From: ItalyPaleAle <43508+ItalyPaleAle@users.noreply.github.com> Date: Sun, 2 Jul 2023 16:51:35 -0700 Subject: [PATCH] Do not ignore custom encrypt and sign options in jwt package Fixes #951 --- jwt/options.go | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/jwt/options.go b/jwt/options.go index 19e30fc40..c75758822 100644 --- a/jwt/options.go +++ b/jwt/options.go @@ -18,7 +18,7 @@ type identTypedClaim struct{} type identVerifyAuto struct{} func toSignOptions(options ...Option) ([]jws.SignOption, error) { - var soptions []jws.SignOption + soptions := make([]jws.SignOption, 0, len(options)) for _, option := range options { //nolint:forcetypeassert switch option.Ident() { @@ -36,13 +36,16 @@ func toSignOptions(options ...Option) ([]jws.SignOption, error) { } soptions = append(soptions, jws.WithKey(wk.alg, wk.key, wksoptions...)) + case identSignOption{}: + sigOpt := option.Value().(jws.SignOption) // this always succeeds + soptions = append(soptions, sigOpt) } } return soptions, nil } func toEncryptOptions(options ...Option) ([]jwe.EncryptOption, error) { - var soptions []jwe.EncryptOption + soptions := make([]jwe.EncryptOption, 0, len(options)) for _, option := range options { //nolint:forcetypeassert switch option.Ident() { @@ -58,13 +61,16 @@ func toEncryptOptions(options ...Option) ([]jwe.EncryptOption, error) { } soptions = append(soptions, jwe.WithKey(wk.alg, wk.key, wksoptions...)) + case identEncryptOption{}: + encOpt := option.Value().(jwe.EncryptOption) // this always succeeds + soptions = append(soptions, encOpt) } } return soptions, nil } func toVerifyOptions(options ...Option) ([]jws.VerifyOption, error) { - var voptions []jws.VerifyOption + voptions := make([]jws.VerifyOption, 0, len(options)) for _, option := range options { //nolint:forcetypeassert switch option.Ident() {