Skip to content

Add firebase\jwt namespace #59

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jul 9, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 0 additions & 6 deletions Exceptions/BeforeValidException.php

This file was deleted.

6 changes: 0 additions & 6 deletions Exceptions/ExpiredException.php

This file was deleted.

6 changes: 0 additions & 6 deletions Exceptions/SignatureInvalidException.php

This file was deleted.

1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ Example
-------
```php
<?php
use \Firebase\JWT\JWT;

$key = "example_key";
$token = array(
Expand Down
6 changes: 4 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,12 @@
],
"license": "BSD-3-Clause",
"require": {
"php": ">=5.2.0"
"php": ">=5.3.0"
},
"autoload": {
"classmap": ["Authentication/", "Exceptions/"]
"psr-4": {
"Firebase\\JWT\\": "src"
}
},
"minimum-stability": "dev"
}
7 changes: 7 additions & 0 deletions src/BeforeValidException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php
namespace Firebase\JWT;

class BeforeValidException extends \UnexpectedValueException
{

}
7 changes: 7 additions & 0 deletions src/ExpiredException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php
namespace Firebase\JWT;

class ExpiredException extends \UnexpectedValueException
{

}
5 changes: 5 additions & 0 deletions Authentication/JWT.php → src/JWT.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
<?php

namespace Firebase\JWT;
use \DomainException;
use \UnexpectedValueException;
use \DateTime;

/**
* JSON Web Token implementation, based on this spec:
* http://tools.ietf.org/html/draft-ietf-oauth-json-web-token-06
Expand Down
7 changes: 7 additions & 0 deletions src/SignatureInvalidException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php
namespace Firebase\JWT;

class SignatureInvalidException extends \UnexpectedValueException
{

}
21 changes: 14 additions & 7 deletions tests/JWTTest.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php
use \Firebase\JWT\JWT;

class JWTTest extends PHPUnit_Framework_TestCase
{
Expand Down Expand Up @@ -37,7 +38,7 @@ public function testMalformedJsonThrowsException()

public function testExpiredToken()
{
$this->setExpectedException('ExpiredException');
$this->setExpectedException('Firebase\JWT\ExpiredException');
$payload = array(
"message" => "abc",
"exp" => time() - 20); // time in the past
Expand All @@ -47,7 +48,7 @@ public function testExpiredToken()

public function testBeforeValidTokenWithNbf()
{
$this->setExpectedException('BeforeValidException');
$this->setExpectedException('Firebase\JWT\BeforeValidException');
$payload = array(
"message" => "abc",
"nbf" => time() + 20); // time in the future
Expand All @@ -57,7 +58,7 @@ public function testBeforeValidTokenWithNbf()

public function testBeforeValidTokenWithIat()
{
$this->setExpectedException('BeforeValidException');
$this->setExpectedException('Firebase\JWT\BeforeValidException');
$payload = array(
"message" => "abc",
"iat" => time() + 20); // time in the future
Expand Down Expand Up @@ -93,7 +94,7 @@ public function testExpiredTokenWithLeeway()
$payload = array(
"message" => "abc",
"exp" => time() - 70); // time far in the past
$this->setExpectedException('ExpiredException');
$this->setExpectedException('Firebase\JWT\ExpiredException');
$encoded = JWT::encode($payload, 'my_key');
$decoded = JWT::decode($encoded, 'my_key', array('HS256'));
$this->assertEquals($decoded->message, 'abc');
Expand Down Expand Up @@ -141,7 +142,7 @@ public function testInvalidTokenWithNbfLeeway()
"message" => "abc",
"nbf" => time() + 65); // not before too far in future
$encoded = JWT::encode($payload, 'my_key');
$this->setExpectedException('BeforeValidException');
$this->setExpectedException('Firebase\JWT\BeforeValidException');
$decoded = JWT::decode($encoded, 'my_key', array('HS256'));
JWT::$leeway = 0;
}
Expand All @@ -165,7 +166,7 @@ public function testInvalidTokenWithIatLeeway()
"message" => "abc",
"iat" => time() + 65); // issued too far in future
$encoded = JWT::encode($payload, 'my_key');
$this->setExpectedException('BeforeValidException');
$this->setExpectedException('Firebase\JWT\BeforeValidException');
$decoded = JWT::decode($encoded, 'my_key', array('HS256'));
JWT::$leeway = 0;
}
Expand All @@ -176,7 +177,7 @@ public function testInvalidToken()
"message" => "abc",
"exp" => time() + 20); // time in the future
$encoded = JWT::encode($payload, 'my_key');
$this->setExpectedException('SignatureInvalidException');
$this->setExpectedException('Firebase\JWT\SignatureInvalidException');
$decoded = JWT::decode($encoded, 'my_key2', array('HS256'));
}

Expand Down Expand Up @@ -234,4 +235,10 @@ public function testAdditionalHeaders()
$msg = JWT::encode('abc', 'my_key', 'HS256', null, array('cty' => 'test-eit;v=1'));
$this->assertEquals(JWT::decode($msg, 'my_key', array('HS256')), 'abc');
}

public function testInvalidSegmentCount()
{
$this->setExpectedException('UnexpectedValueException');
JWT::decode('brokenheader.brokenbody', 'my_key', array('HS256'));
}
}