Skip to content

Commit

Permalink
Deprecate jws.WithHeaders (#1163)
Browse files Browse the repository at this point in the history
The option never worked since v2, but it was kept around, and the
documentation sometimes refered to this option, which it shouldn't have.
  • Loading branch information
lestrrat authored Jul 27, 2024
1 parent 853dc9c commit ccef636
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
8 changes: 5 additions & 3 deletions cmd/jwx/jws.go
Original file line number Diff line number Diff line change
Expand Up @@ -258,16 +258,18 @@ func makeJwsSignCmd() *cli.Command {
return fmt.Errorf(`invalid alg %s`, givenalg)
}

var options []jws.SignOption
// headers must go to WithKeySuboptions
var suboptions []jws.WithKeySuboption
if hdrbuf := c.String("header"); hdrbuf != "" {
h := jws.NewHeaders()
if err := json.Unmarshal([]byte(hdrbuf), h); err != nil {
return fmt.Errorf(`failed to parse header: %w`, err)
}
options = append(options, jws.WithHeaders(h))
suboptions = append(suboptions, jws.WithProtectedHeaders(h))
}

options = append(options, jws.WithKey(alg, key))
var options []jws.SignOption
options = append(options, jws.WithKey(alg, key, suboptions...))
signed, err := jws.Sign(buf, options...)
if err != nil {
return fmt.Errorf(`failed to sign payload: %w`, err)
Expand Down
6 changes: 4 additions & 2 deletions jws/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@ import (
type identHeaders struct{}
type identInsecureNoSignature struct{}

// WithHeaders allows you to specify extra header values to include in the
// final JWS message
// WithHeaders is deprecated. See WithProtectedHeaders to specify
// headers to include in the jws signature.
//
// Using this option has NO EFFECT.
func WithHeaders(h Headers) SignOption {
return &signOption{option.New(identHeaders{}, h)}
}
Expand Down
2 changes: 1 addition & 1 deletion jwt/jwt.go
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,7 @@ OUTER:
//
// The protected header will also automatically have the `typ` field set
// to the literal value `JWT`, unless you provide a custom value for it
// by jwt.WithHeaders option.
// by jws.WithProtectedHeaders option, that can be passed to `jwt.WithKey“.
func Sign(t Token, options ...SignOption) ([]byte, error) {
var soptions []jws.SignOption
if l := len(options); l > 0 {
Expand Down

0 comments on commit ccef636

Please sign in to comment.