Skip to content

Commit f7e4a4f

Browse files
committed
Remove setter and export variable directly
1 parent 7cc0ea7 commit f7e4a4f

File tree

2 files changed

+6
-8
lines changed

2 files changed

+6
-8
lines changed

parser_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -488,7 +488,7 @@ func TestSetPadding(t *testing.T) {
488488
t.Run(data.name, func(t *testing.T) {
489489

490490
// If the token string is blank, use helper function to generate string
491-
jwt.SetDecodePadding(data.paddedDecode)
491+
jwt.DecodePaddingAllowed = data.paddedDecode
492492

493493
if data.tokenString == "" {
494494
data.tokenString = signToken(data.claims, data.signingMethod)
@@ -512,7 +512,7 @@ func TestSetPadding(t *testing.T) {
512512
}
513513

514514
})
515-
jwt.SetDecodePadding(false)
515+
jwt.DecodePaddingAllowed = false
516516

517517
}
518518
}

token.go

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,13 @@ import (
77
"time"
88
)
99

10-
var decodePaddingAllowed bool
1110

12-
// SetDecodePadding will switch the codec used for encoding/decoding JWTs respectively. Note that the JWS RFC7515
11+
// DecodePaddingAllowed will switch the codec used for encoding/decoding JWTs respectively. Note that the JWS RFC7515
1312
// states that the tokens will utilize a Base64url encoding with no padding. Unfortunately, some implementations
1413
// of JWT are producing non-standard tokens, and thus require support for decoding. Note that this is a global
1514
// variable, and updating it will change the behavior on a package level, and is also NOT go-routine safe.
16-
func SetDecodePadding(setPadding bool) {
17-
decodePaddingAllowed = setPadding
18-
}
15+
// To use the non-recommended decoding, set this boolean to `true` prior to using this package.
16+
var DecodePaddingAllowed bool
1917

2018
// TimeFunc provides the current time when parsing token to validate "exp" claim (expiration time).
2119
// You can override it to use another time value. This is useful for testing or if your
@@ -122,7 +120,7 @@ func EncodeSegment(seg []byte) string {
122120
// Deprecated: In a future release, we will demote this function to a non-exported function, since it
123121
// should only be used internally
124122
func DecodeSegment(seg string) ([]byte, error) {
125-
if decodePaddingAllowed {
123+
if DecodePaddingAllowed {
126124
if l := len(seg) % 4; l > 0 {
127125
seg += strings.Repeat("=", 4-l)
128126
}

0 commit comments

Comments
 (0)