Skip to content

Commit 2b24dd3

Browse files
committed
Githug:17805 (Fix issue #17874)
#17874: [Bug]: header attribute are removed during the encoding
1 parent 1bbe8fc commit 2b24dd3

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

Project/Sources/Classes/JWT.4dm

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -51,17 +51,23 @@ Function generate($inParams : Object; $inPrivateKey : Text) : Text
5151
This._throwError(9; {which: "\"$inPrivateKey\""; function: "JWT.generate"})
5252

5353
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"
54+
var $alg : Text:=((Value type($inParams.header.alg)=Is text) && (Length($inParams.header.alg)>0)) ? $inParams.header.alg : "RS256"
55+
var $typ : Text:=((Value type($inParams.header.typ)=Is text) && (Length($inParams.header.typ)>0)) ? $inParams.header.typ : "JWT"
5656
var $x5t : Text:=(Value type($inParams.header.x5t)=Is text) ? $inParams.header.x5t : ""
5757

58-
This._header:={alg: $alg; typ: $typ}
59-
If (Length($x5t)>0)
58+
This._header:=((Value type($inParams.header)=Is object) && Not(OB Is empty($inParams.header))) ? $inParams.header : {}
59+
This._payload:=((Value type($inParams.payload)=Is object) && Not(OB Is empty($inParams.payload))) ? $inParams.payload : {}
60+
61+
If (Value type(This._header.alg)=Is undefined)
62+
This._header.alg:=$alg
63+
End if
64+
If (Value type(This._header.typ)=Is undefined)
65+
This._header.typ:=$typ
66+
End if
67+
If ((Value type(This._header.x5t)=Is undefined) && (Length($x5t)>0))
6068
This._header.x5t:=$x5t
6169
End if
6270

63-
This._payload:=(Value type($inParams.payload)=Is object) ? $inParams.payload : {}
64-
6571
var $header; $payload; $signature : Text
6672

6773
// Encode the Header and Payload
@@ -132,7 +138,7 @@ Function validate($inJWT : Text; $inKey : Text) : Boolean
132138
return Bool($result.success)
133139
End if
134140
End if
135-
141+
136142
End if
137143
End case
138144

0 commit comments

Comments
 (0)