@@ -22,7 +22,7 @@ script "jwtHelper"
22
22
# @package revIgniter
23
23
# @subpackage Helpers
24
24
# @category Helpers
25
- # @requires com.livecode.library.json
25
+ # @requires com.livecode.library.json (not required if the engine is LC Create)
26
26
# @author rabit@revigniter.com
27
27
# @link https://revigniter.com/userGuide/helpers/jwtHelper.html
28
28
# #
@@ -34,7 +34,7 @@ script "jwtHelper"
34
34
global gRigA
35
35
36
36
local sH0 , sH1 , sH2 , sH3 , sH4 , sH5 , sH6 , sH7 , sK
37
- local sSource , sIsFile , sBytesDone , sDataSize , sTail , sStackInUse
37
+ local sSource , sIsFile , sBytesDone , sDataSize , sTail , sStackInUse , sBetterJSONIncluded
38
38
39
39
constant kRSAkeyLength = 4096
40
40
@@ -46,34 +46,40 @@ constant kRSAkeyLength = 4096
46
46
--| COMMAND libraryStack
47
47
--|
48
48
--| Author: rabit
49
- --| Version: 1.0
49
+ --| Version: 1.1
50
50
--| Created: 2018-12-28
51
- --| Last Mod: --
52
- --| Requires: _rigJWTinitHelper
51
+ --| Last Mod: 2024-09-07
52
+ --| Requires: _checkBetterJSON, _rigJWTinitHelper
53
53
--|
54
- --| Summary: Run security check and run initial handler .
54
+ --| Summary: Run security check and run initial handlers .
55
55
--|
56
56
--| Parameters: --
57
57
--|
58
58
--| Return: empty
59
59
----------------------------------------------------------------------*/
60
60
61
61
on libraryStack
62
- if (gRigA is not an array) and (the environment is "server" ) then
63
- put "No direct script access allowed."
64
- exit to top
65
- end if
66
-
67
- if the short name of the target = the short name of me then
68
- if sStackInUse <> TRUE then
69
- put TRUE into sStackInUse
70
-
71
- _rigJWTinitHelper
72
- end if -- if sStackInUse <> TRUE
73
-
74
- else
75
- pass libraryStack
76
- end if -- if the short name of the target = the short name of me
62
+ if (gRigA is not an array) and (the environment is "server" ) then
63
+ put "No direct script access allowed."
64
+ exit to top
65
+ end if
66
+
67
+ if the short name of the target = the short name of me then
68
+ if sStackInUse <> TRUE then
69
+ put TRUE into sStackInUse
70
+
71
+ # CHECK IF THE ENGINE IS LC CREATE AND
72
+ # IF THE LC CREATE VERSION > 1.0.0-DP-1
73
+ _checkBetterJSON
74
+
75
+ if not sBetterJSONIncluded then
76
+ _rigJWTinitHelper
77
+ end if
78
+ end if -- if sStackInUse <> TRUE
79
+
80
+ else
81
+ pass libraryStack
82
+ end if -- if the short name of the target = the short name of me
77
83
end libraryStack
78
84
79
85
@@ -109,9 +115,9 @@ end _rigJWTinitHelper
109
115
--| FUNCTION rigJWTencode
110
116
--|
111
117
--| Author: rabit
112
- --| Version: 1.3
118
+ --| Version: 1.4
113
119
--| Created: 2016-07-08
114
- --| Last Mod: 2021-12-16
120
+ --| Last Mod: 2024-09-07
115
121
--| Requires: _rigStrToArray(), _rigJWTgenerateSecret(), _rigHmacSha2b64(), _rigJWTpurge
116
122
--| _rigJWTrsaKeys(), rigLogMessage
117
123
--|
@@ -151,14 +157,24 @@ function rigJWTencode pHeader pPayload pNumBits pAlg
151
157
put _rigStrToArray(pHeader , , TRUE , TRUE ) into tJWTheaderDataA
152
158
end if
153
159
end if
154
- put base64Encode (JsonExport(tJWTheaderDataA )) into tJWTheader
160
+
161
+ if sBetterJSONIncluded then
162
+ put base64Encode (jsonEncode(tJWTheaderDataA )) into tJWTheader
163
+ else
164
+ put base64Encode (JsonExport(tJWTheaderDataA )) into tJWTheader
165
+ end if
155
166
#
156
167
157
168
# PAYLOAD
158
169
if pPayload is not an array then
159
170
put _rigStrToArray(pPayload , , TRUE , TRUE ) into pPayload
160
171
end if
161
- put base64Encode (JsonExport(pPayload )) into tJWTpayload
172
+
173
+ if sBetterJSONIncluded then
174
+ put base64Encode (jsonEncode(pPayload )) into tJWTpayload
175
+ else
176
+ put base64Encode (JsonExport(pPayload )) into tJWTpayload
177
+ end if
162
178
#
163
179
164
180
# SECRET
@@ -211,9 +227,9 @@ end rigJWTencode
211
227
--| FUNCTION rigJWTdecode
212
228
--|
213
229
--| Author: rabit
214
- --| Version: 1.2
230
+ --| Version: 1.3
215
231
--| Created: 2016-07-09
216
- --| Last Mod: 2021-12-16
232
+ --| Last Mod: 2024-09-07
217
233
--| Requires: rigGetHTTPheader(), _rigJWTVerifySig(), rigLogMessage
218
234
--|
219
235
--| Summary: Decode and validate a JSON Web Token.
@@ -248,12 +264,17 @@ function rigJWTdecode pToken
248
264
put item 3 of pToken into tJWThmac
249
265
250
266
if (pToken <> empty ) and (the number of items of pToken is 3 ) then
251
- # GET HASH SIZE AND ALGORITHM FROM HEADER
252
- put JsonImport(base64Decode (tJWTheader )) into tJWTDecodedA ["header" ]
253
- put JsonImport(base64Decode (tJWTpayload )) into tJWTDecodedA ["payload" ]
267
+ # GET HASH SIZE AND ALGORITHM FROM HEADER
268
+ if sBetterJSONIncluded then
269
+ put jsonDecode(base64Decode (tJWTheader )) into tJWTDecodedA ["header" ]
270
+ put jsonDecode(base64Decode (tJWTpayload )) into tJWTDecodedA ["payload" ]
271
+ else
272
+ put JsonImport(base64Decode (tJWTheader )) into tJWTDecodedA ["header" ]
273
+ put JsonImport(base64Decode (tJWTpayload )) into tJWTDecodedA ["payload" ]
274
+ end if
254
275
255
- put char 1 to 2 of tJWTDecodedA ["header" ]["alg" ] into tAlg
256
- put char 3 to 5 of tJWTDecodedA ["header" ]["alg" ] into tNumBits
276
+ put char 1 to 2 of tJWTDecodedA ["header" ]["alg" ] into tAlg
277
+ put char 3 to 5 of tJWTDecodedA ["header" ]["alg" ] into tNumBits
257
278
258
279
# CHECK INTEGRITY OF TOKEN
259
280
put _rigJWTVerifySig(tJWTheader , tJWTpayload , tJWThmac , tNumBits , tAlg ) into tJWTDecodedA ["valid" ]
@@ -1135,6 +1156,38 @@ end _rigJWTTypeNum
1135
1156
1136
1157
1137
1158
1159
+ /* ----------------------------------------------------------------------
1160
+ --| COMMAND _checkBetterJSON
1161
+ --|
1162
+ --| Author: rabit
1163
+ --| Version: 1.0
1164
+ --| Created: 2024-09-07
1165
+ --| Last Mod: --
1166
+ --| Requires: --
1167
+ --|
1168
+ --| Summary: Check if the engine is lc create
1169
+ --| and if the LC Create version > 1.0.0-DP-1
1170
+ --|
1171
+ --| Format: _checkBetterJSON
1172
+ --|
1173
+ --| Parameters: --
1174
+ --|
1175
+ --| Return: boolean
1176
+ ----------------------------------------------------------------------*/
1177
+
1178
+ private command _checkBetterJSON
1179
+ put FALSE into sBetterJSONIncluded
1180
+ if gRigA ["IsCreate" ] then
1181
+ if productVersion() is not "1.0.0-dp-1" then
1182
+ put TRUE into sBetterJSONIncluded
1183
+ end if
1184
+ end if
1185
+ end _checkBetterJSON
1186
+
1187
+
1188
+
1189
+
1190
+
1138
1191
1139
1192
1140
1193
0 commit comments