@@ -143,14 +143,14 @@ function jwt_decode($jwt, $secretKey=null, $currentTime=null, $algorithms=null){
143
143
$ algorithms = !empty ($ algorithms ) ? (is_array ($ algorithms ) ? $ algorithms : array ($ algorithms )) : JWT_SUPPORTED_ALGORITHMS ;
144
144
145
145
$ parts = explode (". " , $ jwt );
146
- if (count ($ parts ) != 3 ) return array ();
146
+ if (count ($ parts ) != 3 ) return new stdClass ();
147
147
148
148
list ($ head64 , $ payload64 , $ sig64 ) = $ parts ;
149
149
if (!($ header = _jwt_decode ($ head64 )) || !($ payload = _jwt_decode ($ payload64 )) || !($ sig = _jwt_decode ($ sig64 , false )))
150
- return array ();
150
+ return new stdClass ();
151
151
152
152
if (empty ($ header ->alg ) || !isset ($ algorithms [$ header ->alg ]))
153
- return array ();
153
+ return new stdClass ();
154
154
155
155
if ($ header ->alg === 'ES256 ' || $ header ->alg === 'ES384 ' ) {
156
156
// OpenSSL expects an ASN.1 DER sequence for ES256/ES384 signatures
@@ -163,7 +163,7 @@ function jwt_decode($jwt, $secretKey=null, $currentTime=null, $algorithms=null){
163
163
}
164
164
165
165
// Check the signature
166
- if (!jwt_verify ($ head64 .". " .$ payload64 , $ sig , $ secretKey , $ header ->alg )) return array ();
166
+ if (!jwt_verify ($ head64 .". " .$ payload64 , $ sig , $ secretKey , $ header ->alg )) return new stdClass ();
167
167
168
168
// Check if token can already be used (if set)
169
169
$ leeway = isset ($ _ENV ['JWT_LEEWAY_SEC ' ]) ? intval ($ _ENV ['JWT_LEEWAY_SEC ' ]) : 0 ;
@@ -250,10 +250,10 @@ function jwt_encode($payload, $secretKey=null, $alg='HS256', $keyId=null, $head=
250
250
* @param String $secretKey Private key to verify integrity of session data (if null then $_ENV['JWT_SECRET_KEY'])
251
251
* @param Int $currentTime Current UTC time seconds (optional, can be used for unit tests)
252
252
* @param Array $algorithms Map of allowed algorithms (optional, if null or empty then JWT_SUPPORTED_ALGORITHMS will be used)
253
- * @return Array containing loaded session values or empty array if no valid session
253
+ * @return Object JSON object containing loaded session values or empty object if no valid session
254
254
*/
255
255
function jwt_session_load ($ cookieName ="jwt " , $ secretKey =null , $ currentTime =null , $ algorithms =array ()){
256
- if (!isset ($ _COOKIE [$ cookieName ])) return array ();
256
+ if (!isset ($ _COOKIE [$ cookieName ])) return new stdClass ();
257
257
return jwt_decode ($ _COOKIE [$ cookieName ], $ secretKey , $ currentTime , $ algorithms );
258
258
}
259
259
0 commit comments