1313 * @license http://opensource.org/licenses/BSD-3-Clause 3-clause BSD
1414 * @link https://github.com/firebase/php-jwt
1515 */
16- /**
17- * JSON Web Token implementation, based on this spec:
18- * http://tools.ietf.org/html/draft-ietf-oauth-json-web-token-06
19- *
20- * @category Authentication
21- * @package Authentication_JWT
22- * @author Neuman Vong <[email protected] > 23- * @author Anant Narayanan <[email protected] > 24- * @license http://opensource.org/licenses/BSD-3-Clause 3-clause BSD
25- * @link https://github.com/firebase/php-jwt
26- */
2716class JWT
2817{
2918 static $ methods = array (
@@ -32,13 +21,13 @@ class JWT
3221 'HS384 ' => array ('hash_hmac ' , 'SHA384 ' ),
3322 'RS256 ' => array ('openssl ' , 'SHA256 ' ),
3423 );
35-
24+
3625 /**
3726 * Decodes a JWT string into a PHP object.
3827 *
39- * @param string $jwt The JWT
40- * @param string|Array|null $key The secret key, or map of keys
41- * @param bool $verify Don't skip verification process
28+ * @param string $jwt The JWT
29+ * @param string|Array|null $key The secret key, or map of keys
30+ * @param bool $verify Don't skip verification process
4231 *
4332 * @return object The JWT's payload as a PHP object
4433 * @throws UnexpectedValueException Provided JWT was invalid
@@ -71,7 +60,7 @@ public static function decode($jwt, $key = null, $verify = true)
7160 } else {
7261 throw new DomainException ('"kid" empty, unable to lookup correct key ' );
7362 }
74- }
63+ }
7564 if (!JWT ::verify ("$ headb64. $ bodyb64 " , $ sig , $ key , $ header ->alg )) {
7665 throw new UnexpectedValueException ('Signature verification failed ' );
7766 }
@@ -98,9 +87,9 @@ public static function decode($jwt, $key = null, $verify = true)
9887 public static function encode ($ payload , $ key , $ algo = 'HS256 ' , $ keyId = null )
9988 {
10089 $ header = array ('typ ' => 'JWT ' , 'alg ' => $ algo );
101- if ($ keyId !== null ) {
102- $ header ['kid ' ] = $ keyId ;
103- }
90+ if ($ keyId !== null ) {
91+ $ header ['kid ' ] = $ keyId ;
92+ }
10493 $ segments = array ();
10594 $ segments [] = JWT ::urlsafeB64Encode (JWT ::jsonEncode ($ header ));
10695 $ segments [] = JWT ::urlsafeB64Encode (JWT ::jsonEncode ($ payload ));
@@ -115,10 +104,10 @@ public static function encode($payload, $key, $algo = 'HS256', $keyId = null)
115104 /**
116105 * Sign a string with a given key and algorithm.
117106 *
118- * @param string $msg The message to sign
119- * @param string|resource $key The secret key
120- * @param string $method The signing algorithm. Supported
121- * algorithms are 'HS256', 'HS384', 'HS512' and 'RS256'
107+ * @param string $msg The message to sign
108+ * @param string|resource $key The secret key
109+ * @param string $method The signing algorithm. Supported algorithms
110+ * are 'HS256', 'HS384', 'HS512' and 'RS256'
122111 *
123112 * @return string An encrypted message
124113 * @throws DomainException Unsupported algorithm was specified
@@ -142,7 +131,7 @@ public static function sign($msg, $key, $method = 'HS256')
142131 }
143132 }
144133 }
145-
134+
146135 /**
147136 * Verify a signature with the mesage, key and method. Not all methods
148137 * are symmetric, so we must have a separate verify and sign method.
0 commit comments