@@ -47,7 +47,7 @@ func (a *Algorithm) Sign(unsignedToken string) (string, error) {
47
47
return "" , errors .Wrap (err , "Unable to write to HMAC-SHA256" )
48
48
}
49
49
50
- encodedToken := base64 .StdEncoding .EncodeToString (a .sum (nil ))
50
+ encodedToken := base64 .RawURLEncoding .EncodeToString (a .sum (nil ))
51
51
a .reset ()
52
52
53
53
return encodedToken , nil
@@ -62,22 +62,22 @@ func (a *Algorithm) Encode(payload *Claims) (string, error) {
62
62
return "" , errors .Wrap (err , "unable to marshal header" )
63
63
}
64
64
65
- b64TokenHeader := base64 .StdEncoding .EncodeToString (jsonTokenHeader )
65
+ b64TokenHeader := base64 .RawURLEncoding .EncodeToString (jsonTokenHeader )
66
66
67
67
jsonTokenPayload , err := json .Marshal (payload .claimsMap )
68
68
if err != nil {
69
69
return "" , errors .Wrap (err , "unable to marshal payload" )
70
70
}
71
71
72
- b64TokenPayload := base64 .StdEncoding .EncodeToString (jsonTokenPayload )
72
+ b64TokenPayload := base64 .RawURLEncoding .EncodeToString (jsonTokenPayload )
73
73
74
74
unsignedSignature := b64TokenHeader + "." + b64TokenPayload
75
75
76
76
signature , err := a .Sign (unsignedSignature )
77
77
if err != nil {
78
78
return "" , errors .Wrap (err , "unable to sign token" )
79
79
}
80
- b64Signature := base64 .StdEncoding .EncodeToString ([]byte (signature ))
80
+ b64Signature := base64 .RawURLEncoding .EncodeToString ([]byte (signature ))
81
81
82
82
token := b64TokenHeader + "." + b64TokenPayload + "." + b64Signature
83
83
@@ -91,7 +91,7 @@ func (a *Algorithm) Decode(encoded string) (*Claims, error) {
91
91
b64Payload := encryptedComponents [1 ]
92
92
93
93
var claims map [string ]interface {}
94
- payload , err := base64 .StdEncoding .DecodeString (b64Payload )
94
+ payload , err := base64 .RawURLEncoding .DecodeString (b64Payload )
95
95
if err != nil {
96
96
return nil , errors .Wrap (err , "unable to decode base64 payload" )
97
97
}
@@ -140,7 +140,7 @@ func (a *Algorithm) validateSignature(encoded string) error {
140
140
return errors .Wrap (err , "unable to sign token for validation" )
141
141
}
142
142
143
- b64SignedAttempt := base64 .StdEncoding .EncodeToString ([]byte (signedAttempt ))
143
+ b64SignedAttempt := base64 .RawURLEncoding .EncodeToString ([]byte (signedAttempt ))
144
144
145
145
if strings .Compare (b64Signature , b64SignedAttempt ) != 0 {
146
146
return errors .New ("invalid signature" )
0 commit comments