Skip to content

Commit 75264d2

Browse files
committed
Github:17805 (fix: update generate function to accept private key as parameter for improved clarity and consistency)
1 parent 3799fc0 commit 75264d2

File tree

1 file changed

+13
-13
lines changed

1 file changed

+13
-13
lines changed

Project/Sources/Classes/JWT.4dm

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -39,22 +39,22 @@ Function decode($inToken : Text) : Object
3939
// ----------------------------------------------------
4040

4141

42-
Function generate($inParams : Object) : Text
43-
44-
var result : Text:=""
45-
var $alg : Text:=(Value type($inParams.header.alg)=Is text) ? $inParams.header.alg : "RS256"
46-
var $typ : Text:=(Value type($inParams.header.typ)=Is text) ? $inParams.header.typ : "JWT"
47-
var $x5t : Text:=(Value type($inParams.header.x5t)=Is text) ? $inParams.header.x5t : ""
48-
var $privateKey : Text:=((Value type($inParams.privateKey)=Is text) && (Length($inParams.privateKey)>0)) ? $inParams.privateKey : ""
42+
Function generate($inParams : Object; $inPrivateKey : Text) : Text
4943

44+
var $result : Text:=""
45+
5046
Case of
5147
: ((Value type($inParams.payload)#Is object) || (OB Is empty($inParams.payload)))
5248
This._throwError(9; {which: "\"$inParams.payload\""; function: "JWT.generate"})
5349

54-
: ((Value type($privateKey)#Is text) || (Length(String($privateKey))=0))
55-
This._throwError(9; {which: "\"$inParams.privateKey\""; function: "JWT.generate"})
50+
: ((Value type($inPrivateKey)#Is text) || (Length(String($inPrivateKey))=0))
51+
This._throwError(9; {which: "\"$inPrivateKey\""; function: "JWT.generate"})
5652

5753
Else
54+
var $alg : Text:=(Value type($inParams.header.alg)=Is text) ? $inParams.header.alg : "RS256"
55+
var $typ : Text:=(Value type($inParams.header.typ)=Is text) ? $inParams.header.typ : "JWT"
56+
var $x5t : Text:=(Value type($inParams.header.x5t)=Is text) ? $inParams.header.x5t : ""
57+
5858
This._header:={alg: $alg; typ: $typ}
5959
If (Length($x5t)>0)
6060
This._header.x5t:=$x5t
@@ -78,17 +78,17 @@ Function generate($inParams : Object) : Text
7878

7979
// Generate Verify Signature Hash based on Algorithm
8080
If ($algorithm="HS")
81-
$signature:=This._hashHS(This; $privateKey) // HMAC Hash
81+
$signature:=This._hashHS(This; $inPrivateKey) // HMAC Hash
8282
Else
83-
$signature:=This._hashSign(This; $privateKey) // All other Hashes
83+
$signature:=This._hashSign(This; $inPrivateKey) // All other Hashes
8484
End if
8585

8686
// Combine Encoded Header and Payload with Hashed Signature for the Token
87-
result:=$header+"."+$payload+"."+$signature
87+
$result:=$header+"."+$payload+"."+$signature
8888

8989
End case
9090

91-
return result
91+
return $result
9292

9393

9494
// ----------------------------------------------------

0 commit comments

Comments
 (0)