Skip to content

Commit

Permalink
Remove setter and export variable directly
Browse files Browse the repository at this point in the history
  • Loading branch information
ajermaky committed Oct 31, 2021
1 parent 7cc0ea7 commit f7e4a4f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 8 deletions.
4 changes: 2 additions & 2 deletions parser_test.go
Expand Up @@ -488,7 +488,7 @@ func TestSetPadding(t *testing.T) {
t.Run(data.name, func(t *testing.T) {

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

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

})
jwt.SetDecodePadding(false)
jwt.DecodePaddingAllowed = false

}
}
Expand Down
10 changes: 4 additions & 6 deletions token.go
Expand Up @@ -7,15 +7,13 @@ import (
"time"
)

var decodePaddingAllowed bool

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

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

0 comments on commit f7e4a4f

Please sign in to comment.