|
1 | 1 | /* |
2 | | -Largely inspired by Tech Note: "JSON Web Tokens in 4D" from Thomas Maul |
| 2 | +Largely inspired by Tech Note: "JSON Web Tokens in 4D" |
3 | 3 | See: https://kb.4d.com/assetid=79100 |
4 | 4 | */ |
5 | 5 |
|
@@ -70,14 +70,9 @@ Function generate($inParams : Object; $inPrivateKey : Text) : Text |
70 | 70 |
|
71 | 71 | // Parse Header for Algorithm Family |
72 | 72 | var $algorithm : Text:=This._header.alg |
73 | | - If (($algorithm="HS256") || ($algorithm="HS512")) |
74 | | - $algorithm:="HS" |
75 | | - Else |
76 | | - $algorithm:="RS" |
77 | | - End if |
78 | 73 |
|
79 | 74 | // Generate Verify Signature Hash based on Algorithm |
80 | | - If ($algorithm="HS") |
| 75 | + If ($algorithm="HS@") |
81 | 76 | $signature:=This._hashHS(This; $inPrivateKey) // HMAC Hash |
82 | 77 | Else |
83 | 78 | $signature:=This._hashSign(This; $inPrivateKey) // All other Hashes |
@@ -124,14 +119,20 @@ Function validate($inJWT : Text; $inKey : Text) : Boolean |
124 | 119 | This._payload:=$jwt._payload |
125 | 120 | End if |
126 | 121 |
|
127 | | - // Prepare CryptoKey settings |
128 | | - var $settings : Object:={type: "PEM"; pem: $key} // Use specified PEM format Key |
129 | | - var $cryptoKey : 4D.CryptoKey:=4D.CryptoKey.new($settings) |
130 | | - If ($cryptoKey#Null) |
131 | | - var $result : Object:=$cryptoKey.verify(String($parts[0]+"."+$parts[1]); $parts[2]; {hash: (Substring($jwt._header.alg; 3)="256") ? SHA256 digest : SHA512 digest; pss: Bool($jwt._header.alg="PS@"); encoding: "Base64URL"}) |
132 | | - return Bool($result.success) |
| 122 | + var $algorithm : Text:=This._header.alg |
| 123 | + If ($algorithm="HS@") |
| 124 | + $signature:=This._hashHS($jwt; $key) // HMAC Hash |
| 125 | + return ($signature=$parts[2]) |
| 126 | + Else |
| 127 | + // Prepare CryptoKey settings |
| 128 | + var $settings : Object:={type: "PEM"; pem: $key} // Use specified PEM format Key |
| 129 | + var $cryptoKey : 4D.CryptoKey:=4D.CryptoKey.new($settings) |
| 130 | + If ($cryptoKey#Null) |
| 131 | + var $result : Object:=$cryptoKey.verify(String($parts[0]+"."+$parts[1]); $parts[2]; {hash: (Substring($jwt._header.alg; 3)="256") ? SHA256 digest : SHA512 digest; pss: Bool($jwt._header.alg="PS@"); encoding: "Base64URL"}) |
| 132 | + return Bool($result.success) |
| 133 | + End if |
133 | 134 | End if |
134 | | - |
| 135 | + |
135 | 136 | End if |
136 | 137 | End case |
137 | 138 |
|
|
0 commit comments