Skip to content

Commit 436e005

Browse files
committed
Merge pull request #59 from Dashron/master
Add firebase\jwt namespace
2 parents 21498f7 + 3a6b01a commit 436e005

10 files changed

+45
-27
lines changed

Diff for: Exceptions/BeforeValidException.php

-6
This file was deleted.

Diff for: Exceptions/ExpiredException.php

-6
This file was deleted.

Diff for: Exceptions/SignatureInvalidException.php

-6
This file was deleted.

Diff for: README.md

+1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ Example
2121
-------
2222
```php
2323
<?php
24+
use \Firebase\JWT\JWT;
2425

2526
$key = "example_key";
2627
$token = array(

Diff for: composer.json

+4-2
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,12 @@
1616
],
1717
"license": "BSD-3-Clause",
1818
"require": {
19-
"php": ">=5.2.0"
19+
"php": ">=5.3.0"
2020
},
2121
"autoload": {
22-
"classmap": ["Authentication/", "Exceptions/"]
22+
"psr-4": {
23+
"Firebase\\JWT\\": "src"
24+
}
2325
},
2426
"minimum-stability": "dev"
2527
}

Diff for: src/BeforeValidException.php

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?php
2+
namespace Firebase\JWT;
3+
4+
class BeforeValidException extends \UnexpectedValueException
5+
{
6+
7+
}

Diff for: src/ExpiredException.php

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?php
2+
namespace Firebase\JWT;
3+
4+
class ExpiredException extends \UnexpectedValueException
5+
{
6+
7+
}

Diff for: Authentication/JWT.php renamed to src/JWT.php

+5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
<?php
22

3+
namespace Firebase\JWT;
4+
use \DomainException;
5+
use \UnexpectedValueException;
6+
use \DateTime;
7+
38
/**
49
* JSON Web Token implementation, based on this spec:
510
* http://tools.ietf.org/html/draft-ietf-oauth-json-web-token-06

Diff for: src/SignatureInvalidException.php

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?php
2+
namespace Firebase\JWT;
3+
4+
class SignatureInvalidException extends \UnexpectedValueException
5+
{
6+
7+
}

Diff for: tests/JWTTest.php

+14-7
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
use \Firebase\JWT\JWT;
23

34
class JWTTest extends PHPUnit_Framework_TestCase
45
{
@@ -37,7 +38,7 @@ public function testMalformedJsonThrowsException()
3738

3839
public function testExpiredToken()
3940
{
40-
$this->setExpectedException('ExpiredException');
41+
$this->setExpectedException('Firebase\JWT\ExpiredException');
4142
$payload = array(
4243
"message" => "abc",
4344
"exp" => time() - 20); // time in the past
@@ -47,7 +48,7 @@ public function testExpiredToken()
4748

4849
public function testBeforeValidTokenWithNbf()
4950
{
50-
$this->setExpectedException('BeforeValidException');
51+
$this->setExpectedException('Firebase\JWT\BeforeValidException');
5152
$payload = array(
5253
"message" => "abc",
5354
"nbf" => time() + 20); // time in the future
@@ -57,7 +58,7 @@ public function testBeforeValidTokenWithNbf()
5758

5859
public function testBeforeValidTokenWithIat()
5960
{
60-
$this->setExpectedException('BeforeValidException');
61+
$this->setExpectedException('Firebase\JWT\BeforeValidException');
6162
$payload = array(
6263
"message" => "abc",
6364
"iat" => time() + 20); // time in the future
@@ -93,7 +94,7 @@ public function testExpiredTokenWithLeeway()
9394
$payload = array(
9495
"message" => "abc",
9596
"exp" => time() - 70); // time far in the past
96-
$this->setExpectedException('ExpiredException');
97+
$this->setExpectedException('Firebase\JWT\ExpiredException');
9798
$encoded = JWT::encode($payload, 'my_key');
9899
$decoded = JWT::decode($encoded, 'my_key', array('HS256'));
99100
$this->assertEquals($decoded->message, 'abc');
@@ -141,7 +142,7 @@ public function testInvalidTokenWithNbfLeeway()
141142
"message" => "abc",
142143
"nbf" => time() + 65); // not before too far in future
143144
$encoded = JWT::encode($payload, 'my_key');
144-
$this->setExpectedException('BeforeValidException');
145+
$this->setExpectedException('Firebase\JWT\BeforeValidException');
145146
$decoded = JWT::decode($encoded, 'my_key', array('HS256'));
146147
JWT::$leeway = 0;
147148
}
@@ -165,7 +166,7 @@ public function testInvalidTokenWithIatLeeway()
165166
"message" => "abc",
166167
"iat" => time() + 65); // issued too far in future
167168
$encoded = JWT::encode($payload, 'my_key');
168-
$this->setExpectedException('BeforeValidException');
169+
$this->setExpectedException('Firebase\JWT\BeforeValidException');
169170
$decoded = JWT::decode($encoded, 'my_key', array('HS256'));
170171
JWT::$leeway = 0;
171172
}
@@ -176,7 +177,7 @@ public function testInvalidToken()
176177
"message" => "abc",
177178
"exp" => time() + 20); // time in the future
178179
$encoded = JWT::encode($payload, 'my_key');
179-
$this->setExpectedException('SignatureInvalidException');
180+
$this->setExpectedException('Firebase\JWT\SignatureInvalidException');
180181
$decoded = JWT::decode($encoded, 'my_key2', array('HS256'));
181182
}
182183

@@ -234,4 +235,10 @@ public function testAdditionalHeaders()
234235
$msg = JWT::encode('abc', 'my_key', 'HS256', null, array('cty' => 'test-eit;v=1'));
235236
$this->assertEquals(JWT::decode($msg, 'my_key', array('HS256')), 'abc');
236237
}
238+
239+
public function testInvalidSegmentCount()
240+
{
241+
$this->setExpectedException('UnexpectedValueException');
242+
JWT::decode('brokenheader.brokenbody', 'my_key', array('HS256'));
243+
}
237244
}

0 commit comments

Comments
 (0)