Skip to content

Commit

Permalink
Revert Encoding/Decoding changes for better compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
ajermaky committed Oct 29, 2021
1 parent a2aa655 commit 08b2b96
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions token.go
Expand Up @@ -104,13 +104,17 @@ func ParseWithClaims(tokenString string, claims Claims, keyFunc Keyfunc, options
// Deprecated: In a future release, we will demote this function to a non-exported function, since it
// should only be used internally
func EncodeSegment(seg []byte) string {
return base64.RawURLEncoding.EncodeToString(seg)
return strings.TrimRight(base64.URLEncoding.EncodeToString(seg), "=")
}

// DecodeSegment decodes a JWT specific base64url encoding with padding stripped
//
// 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) {
return base64.RawURLEncoding.DecodeString(seg)
if l := len(seg) % 4; l > 0 {
seg += strings.Repeat("=", 4-l)
}

return base64.URLEncoding.DecodeString(seg)
}

0 comments on commit 08b2b96

Please sign in to comment.