diff options
author | Chris Raynor <chris@firebase.com> | 2014-06-25 12:30:42 -0700 |
---|---|---|
committer | Chris Raynor <chris@firebase.com> | 2014-06-25 13:31:45 -0700 |
commit | c59b68dc87bf52d2d351368988492bd4c900cc3a (patch) | |
tree | 554ccbb7974d7ed5a73099dac277464217784eea | |
parent | 3bb58d76599934be52450646cd4fe3ce5619997c (diff) | |
download | php-jwt-c59b68dc87bf52d2d351368988492bd4c900cc3a.zip php-jwt-c59b68dc87bf52d2d351368988492bd4c900cc3a.tar.gz php-jwt-c59b68dc87bf52d2d351368988492bd4c900cc3a.tar.bz2 |
whitespace cleanup
-rw-r--r-- | Authentication/JWT.php | 37 | ||||
-rw-r--r-- | tests/JWTTest.php | 19 |
2 files changed, 22 insertions, 34 deletions
diff --git a/Authentication/JWT.php b/Authentication/JWT.php index 11b1bde..4145869 100644 --- a/Authentication/JWT.php +++ b/Authentication/JWT.php @@ -13,17 +13,6 @@ * @license http://opensource.org/licenses/BSD-3-Clause 3-clause BSD * @link https://github.com/firebase/php-jwt */ -/** - * JSON Web Token implementation, based on this spec: - * http://tools.ietf.org/html/draft-ietf-oauth-json-web-token-06 - * - * @category Authentication - * @package Authentication_JWT - * @author Neuman Vong <neuman@twilio.com> - * @author Anant Narayanan <anant@php.net> - * @license http://opensource.org/licenses/BSD-3-Clause 3-clause BSD - * @link https://github.com/firebase/php-jwt - */ class JWT { static $methods = array( @@ -32,13 +21,13 @@ class JWT 'HS384' => array('hash_hmac', 'SHA384'), 'RS256' => array('openssl', 'SHA256'), ); - + /** * Decodes a JWT string into a PHP object. * - * @param string $jwt The JWT - * @param string|Array|null $key The secret key, or map of keys - * @param bool $verify Don't skip verification process + * @param string $jwt The JWT + * @param string|Array|null $key The secret key, or map of keys + * @param bool $verify Don't skip verification process * * @return object The JWT's payload as a PHP object * @throws UnexpectedValueException Provided JWT was invalid @@ -71,7 +60,7 @@ class JWT } else { throw new DomainException('"kid" empty, unable to lookup correct key'); } - } + } if (!JWT::verify("$headb64.$bodyb64", $sig, $key, $header->alg)) { throw new UnexpectedValueException('Signature verification failed'); } @@ -98,9 +87,9 @@ class JWT public static function encode($payload, $key, $algo = 'HS256', $keyId = null) { $header = array('typ' => 'JWT', 'alg' => $algo); - if($keyId !== null) { - $header['kid'] = $keyId; - } + if($keyId !== null) { + $header['kid'] = $keyId; + } $segments = array(); $segments[] = JWT::urlsafeB64Encode(JWT::jsonEncode($header)); $segments[] = JWT::urlsafeB64Encode(JWT::jsonEncode($payload)); @@ -115,10 +104,10 @@ class JWT /** * Sign a string with a given key and algorithm. * - * @param string $msg The message to sign - * @param string|resource $key The secret key - * @param string $method The signing algorithm. Supported - * algorithms are 'HS256', 'HS384', 'HS512' and 'RS256' + * @param string $msg The message to sign + * @param string|resource $key The secret key + * @param string $method The signing algorithm. Supported algorithms + * are 'HS256', 'HS384', 'HS512' and 'RS256' * * @return string An encrypted message * @throws DomainException Unsupported algorithm was specified @@ -142,7 +131,7 @@ class JWT } } } - + /** * Verify a signature with the mesage, key and method. Not all methods * are symmetric, so we must have a separate verify and sign method. diff --git a/tests/JWTTest.php b/tests/JWTTest.php index bdd8514..ee131d4 100644 --- a/tests/JWTTest.php +++ b/tests/JWTTest.php @@ -29,43 +29,42 @@ class JWTTest extends PHPUnit_Framework_TestCase { JWT::jsonDecode('this is not valid JSON string'); } - function testExpiredToken(){ + function testExpiredToken() { $this->setExpectedException('UnexpectedValueException'); $payload = array( - "message"=> "abc", - "exp"=> time()-20); // time in the past + "message" => "abc", + "exp" => time() - 20); // time in the past $encoded = JWT::encode($payload, 'my_key'); JWT::decode($encoded); } - function testValidToken(){ + function testValidToken() { $payload = array( - "message"=> "abc", - "exp"=> time()+20); // time in the future + "message" => "abc", + "exp" => time() + 20); // time in the future $encoded = JWT::encode($payload, 'my_key'); $decoded = JWT::decode($encoded, 'my_key'); $this->assertEquals($decoded->message, 'abc'); } - function testRSEncodeDecode(){ + function testRSEncodeDecode() { $privKey = openssl_pkey_new(array('digest_alg' => 'sha256', 'private_key_bits' => 1024, 'private_key_type' => OPENSSL_KEYTYPE_RSA)); - $msg = JWT::encode('abc',$privKey, 'RS256'); + $msg = JWT::encode('abc', $privKey, 'RS256'); $pubKey = openssl_pkey_get_details($privKey); $pubKey = $pubKey['key']; $decoded = JWT::decode($msg, $pubKey, true); $this->assertEquals($decoded, 'abc'); } - function testKIDChooser(){ + function testKIDChooser() { $keys = array('1' => 'my_key', '2' => 'my_key2'); $msg = JWT::encode('abc', $keys['1'], 'HS256', '1'); $decoded = JWT::decode($msg, $keys, true); $this->assertEquals($decoded, 'abc'); } - } ?> |