Skip to content

Commit a0a95e1

Browse files
committed
Put base64 url en-/decoding more central and use this method everywhere. Enable checkSignature: also to handle complete token or splitted
1 parent 02dfe21 commit a0a95e1

13 files changed

Lines changed: 25 additions & 15 deletions

File tree

source/JSONWebToken-Core.package/JWAHMACSHA256.class/class/checkSignature.withKey..st renamed to source/JSONWebToken-Core.package/JWAHMACSHA256.class/class/checkSignatureOfParts.withKey..st

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
sign
2-
checkSignature: parts withKey: key
2+
checkSignatureOfParts: parts withKey: key
33
(self
44
signMessage:
55
($.

source/JSONWebToken-Core.package/JWANone.class/class/checkSignature.withKey..st

Lines changed: 0 additions & 3 deletions
This file was deleted.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
sign
2+
checkSignatureOfParts: parts withKey: key
3+

source/JSONWebToken-Core.package/JWSCompactSerializer.class/instance/materialize.key.checkSignature..st

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ materialize: aString key: aKeyString checkSignature: checkSignature
55

66
parts := $. split: aString.
77
(parts size = 3) ifFalse: [ JWSInvalidTokenFormat signal: 'the format of the token is invalid' ].
8-
header := JWSHeader fromJson: ( self base64Decoded: parts first ) utf8Decoded.
8+
header := JWSHeader fromJson: ( self class base64UrlDecoded: parts first ) utf8Decoded.
99
jws := JsonWebSignature new
1010
key: aKeyString;
1111
setProtectedHeader: header.
1212
checkSignature
1313
ifTrue: [ jws checkSignature: parts ].
14-
^ jws payload: ( JWTClaimsSet fromJson: ( self base64Decoded: parts second ) utf8Decoded )
14+
^ jws payload: ( JWTClaimsSet fromJson: ( self class base64UrlDecoded: parts second ) utf8Decoded )

source/JSONWebToken-Core.package/JWSCompactSerializer.class/instance/serialize..st

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,5 @@ serialize: aWebSignature
88
signature := aWebSignature signatureFor: stream contents.
99
stream
1010
nextPut: $.;
11-
nextPutAll: (self base64Encoded: signature).
11+
nextPutAll: (self class base64UrlEncoded: signature).
1212
^ stream contents
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
writing
22
writeHeader: aHeader
3-
stream nextPutAll: (self base64Encoded: aHeader asJson asByteArray)
3+
stream nextPutAll: (self class base64UrlEncoded: aHeader asJson asByteArray)
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
writing
22
writePayload: anObject
3-
stream nextPutAll: (self base64Encoded: anObject asJson asByteArray)
3+
stream nextPutAll: (self class base64UrlEncoded: anObject asJson asByteArray)

source/JSONWebToken-Core.package/JWSSerializer.class/instance/base64Decoded..st renamed to source/JSONWebToken-Core.package/JWSSerializer.class/class/base64UrlDecoded..st

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
conversion
2-
base64Decoded: aBase64String
2+
base64UrlDecoded: aBase64String
33

44
"According to https://tools.ietf.org/html/rfc7519#page-4 the encoding needs to be base64Url.
55
The padding can be stripped as it is not used for transport in JWT, so we need to pad it just in case"

source/JSONWebToken-Core.package/JWSSerializer.class/instance/base64Encoded..st renamed to source/JSONWebToken-Core.package/JWSSerializer.class/class/base64UrlEncoded..st

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
conversion
2-
base64Encoded: aByteArray
2+
base64UrlEncoded: aByteArray
33

44
"According to https://tools.ietf.org/html/rfc7519#page-4 the encoding needs to be base64Url.
55
The padding is stripped as it is not used for transport in JWT"
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
sign
2+
checkSignature: token withKey: key
3+
"keep this method backward compatible also accepting already splitted parts"
4+
self
5+
checkSignatureOfParts: (token isString
6+
ifTrue: [ $. split: token ]
7+
ifFalse: [ token ])
8+
withKey: key

0 commit comments

Comments
 (0)