Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not ignore custom encrypt and sign options in jwt package #952

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions jwt/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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() {
Expand All @@ -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() {
Expand Down