Skip to content
This repository was archived by the owner on Apr 22, 2024. It is now read-only.

Commit 2eb16e9

Browse files
authored
Merge pull request #11 from tartale/issue-10-encoding
Changed encoding/decoding to RawURL
2 parents 5481a4c + 4ae9a6d commit 2eb16e9

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

algorithms.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ func (a *Algorithm) Sign(unsignedToken string) (string, error) {
4747
return "", errors.Wrap(err, "Unable to write to HMAC-SHA256")
4848
}
4949

50-
encodedToken := base64.StdEncoding.EncodeToString(a.sum(nil))
50+
encodedToken := base64.RawURLEncoding.EncodeToString(a.sum(nil))
5151
a.reset()
5252

5353
return encodedToken, nil
@@ -62,22 +62,22 @@ func (a *Algorithm) Encode(payload *Claims) (string, error) {
6262
return "", errors.Wrap(err, "unable to marshal header")
6363
}
6464

65-
b64TokenHeader := base64.StdEncoding.EncodeToString(jsonTokenHeader)
65+
b64TokenHeader := base64.RawURLEncoding.EncodeToString(jsonTokenHeader)
6666

6767
jsonTokenPayload, err := json.Marshal(payload.claimsMap)
6868
if err != nil {
6969
return "", errors.Wrap(err, "unable to marshal payload")
7070
}
7171

72-
b64TokenPayload := base64.StdEncoding.EncodeToString(jsonTokenPayload)
72+
b64TokenPayload := base64.RawURLEncoding.EncodeToString(jsonTokenPayload)
7373

7474
unsignedSignature := b64TokenHeader + "." + b64TokenPayload
7575

7676
signature, err := a.Sign(unsignedSignature)
7777
if err != nil {
7878
return "", errors.Wrap(err, "unable to sign token")
7979
}
80-
b64Signature := base64.StdEncoding.EncodeToString([]byte(signature))
80+
b64Signature := base64.RawURLEncoding.EncodeToString([]byte(signature))
8181

8282
token := b64TokenHeader + "." + b64TokenPayload + "." + b64Signature
8383

@@ -91,7 +91,7 @@ func (a *Algorithm) Decode(encoded string) (*Claims, error) {
9191
b64Payload := encryptedComponents[1]
9292

9393
var claims map[string]interface{}
94-
payload, err := base64.StdEncoding.DecodeString(b64Payload)
94+
payload, err := base64.RawURLEncoding.DecodeString(b64Payload)
9595
if err != nil {
9696
return nil, errors.Wrap(err, "unable to decode base64 payload")
9797
}
@@ -140,7 +140,7 @@ func (a *Algorithm) validateSignature(encoded string) error {
140140
return errors.Wrap(err, "unable to sign token for validation")
141141
}
142142

143-
b64SignedAttempt := base64.StdEncoding.EncodeToString([]byte(signedAttempt))
143+
b64SignedAttempt := base64.RawURLEncoding.EncodeToString([]byte(signedAttempt))
144144

145145
if strings.Compare(b64Signature, b64SignedAttempt) != 0 {
146146
return errors.New("invalid signature")

0 commit comments

Comments
 (0)