Skip to content

Commit

Permalink
Merge pull request #14 from RobDWaller/2.0.0
Browse files Browse the repository at this point in the history
2.0.0
  • Loading branch information
RobDWaller authored May 2, 2022
2 parents a1b4fcd + 3fc6099 commit 95d982f
Show file tree
Hide file tree
Showing 25 changed files with 159 additions and 135 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
php-versions: ['7.2', '7.3', '7.4']
php-versions: ['7.4', '8.0']
name: PHP ${{ matrix.php-versions }} Test
steps:
- name: Checkout
Expand Down
24 changes: 12 additions & 12 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,22 @@
}
],
"require": {
"php": ">=7.2.0",
"rbdwllr/reallysimplejwt": "^3.0",
"php": ">=7.4.0",
"rbdwllr/reallysimplejwt": "^4.0",
"psr/http-message": "^1.0",
"psr/http-server-middleware": "^1.0",
"nyholm/psr7": "^1.2"
"nyholm/psr7": "^1.5"
},
"require-dev": {
"phpunit/phpunit": "^8.0",
"phpstan/phpstan": "^0.11",
"phpstan/phpstan-mockery": "^0.11",
"phpmd/phpmd": "^2.7",
"squizlabs/php_codesniffer": "^3.0",
"mockery/mockery": "^1.3",
"infection/infection": "^0.14",
"phploc/phploc": "^5.0",
"sebastian/phpcpd": "^4.0"
"phpunit/phpunit": "^9.0",
"phpstan/phpstan": "^1.5",
"phpstan/phpstan-mockery": "^1.0",
"phpmd/phpmd": "^2.12",
"squizlabs/php_codesniffer": "^3.6",
"mockery/mockery": "^1.5",
"infection/infection": "^0.20",
"phploc/phploc": "^7.0",
"sebastian/phpcpd": "^6.0"
},
"autoload": {
"psr-4": {
Expand Down
4 changes: 2 additions & 2 deletions src/Auth/Authorise.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,9 @@ private function validate(string $token): Auth
{
$jwt = new Jwt();

$parse = $jwt->parser($token, $this->secret);
$validator = $jwt->validator($token, $this->secret);

$validate = new Validate($parse);
$validate = new Validate($validator);

$validationState = $validate->validate();

Expand Down
37 changes: 20 additions & 17 deletions src/Factory/Jwt.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,10 @@

namespace PsrJwt\Factory;

use ReallySimpleJWT\Tokens;
use ReallySimpleJWT\Build;
use ReallySimpleJWT\Validate;
use ReallySimpleJWT\Encode;
use ReallySimpleJWT\Parse;
use ReallySimpleJWT\Secret;
use ReallySimpleJWT\Jwt as RSJwt;
use ReallySimpleJWT\Validate;

/**
* PSR-JWT wraps around the ReallySimpleJWT library to provide token
Expand All @@ -26,27 +24,32 @@ class Jwt
*/
public function builder(): Build
{
return new Build(
'JWT',
new Validate(),
new Secret(),
new Encode()
);
$tokens = new Tokens();

return $tokens->builder();
}

/**
* Allow for the parsing and validation of JSON Web Tokens.
* Allow for the parsing of JSON Web Tokens.
*
* @return Parse
*/
public function parser(string $token, string $secret): Parse
{
$jwt = new RSJwt($token, $secret);
$tokens = new Tokens();

return $tokens->parser($token, $secret);
}

/**
* Allow for the validation JSON Web Tokens.
*
* @return Validate
*/
public function validator(string $token, string $secret): Validate
{
$tokens = new Tokens();

return new Parse(
$jwt,
new Validate(),
new Encode()
);
return $tokens->validator($token, $secret);
}
}
2 changes: 1 addition & 1 deletion src/Factory/JwtMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public static function html(string $secret, string $tokenKey = '', string $body
*
* @param string $tokenKey
* @param string $secret
* @param array $body
* @param mixed[] $body
* @return JwtAuthMiddleware
*/
public static function json(string $secret, string $tokenKey = '', array $body = []): JwtAuthMiddleware
Expand Down
4 changes: 2 additions & 2 deletions src/Handler/Json.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@
class Json extends Authorise implements RequestHandlerInterface
{
/**
* @var array The content to add to the response body.
* @var mixed[] The content to add to the response body.
*/
private $body;

/**
* @param string $secret
* @param string $tokenKey
* @param array $body
* @param mixed[] $body
*/
public function __construct(string $secret, string $tokenKey, array $body)
{
Expand Down
4 changes: 4 additions & 0 deletions src/Helper/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ public function getParsedToken(ServerRequestInterface $request, string $tokenKey

/**
* Retrieve the JWT header information from a request.
*
* @return mixed[]
*/
public function getTokenHeader(ServerRequestInterface $request, string $tokenKey): array
{
Expand All @@ -41,6 +43,8 @@ public function getTokenHeader(ServerRequestInterface $request, string $tokenKey

/**
* Retrieve the JWT payload information from a request.
*
* @return mixed[]
*/
public function getTokenPayload(ServerRequestInterface $request, string $tokenKey): array
{
Expand Down
2 changes: 1 addition & 1 deletion src/Parser/Parse.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
class Parse
{
/**
* @var array $parsers
* @var mixed[] $parsers
*/
private $parsers = [];

Expand Down
30 changes: 15 additions & 15 deletions src/Validation/Validate.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@

namespace PsrJwt\Validation;

use ReallySimpleJWT\Parse;
use ReallySimpleJWT\Validate as RSValidate;
use ReallySimpleJWT\Exception\ValidateException;
use ReallySimpleJWT\Exception\ParseException;

/**
* Validate the JSON Web Token will parse, has a valid signature, is ready to
Expand All @@ -14,29 +15,27 @@
class Validate
{
/**
* @param Parse $parse
* @param RSValidate $validate
*/
private $parse;
private RSValidate $validate;

/**
* @param Parse $parse
*/
public function __construct(Parse $parse)
public function __construct(RSValidate $validate)
{
$this->parse = $parse;
$this->validate = $validate;
}

/**
* The JSON Web Token must be valid and not have expired.
*
* @return array
* @return mixed[]
*/
public function validate(): array
{
try {
$this->parse->validate()
->validateExpiration();
} catch (ValidateException $e) {
$this->validate->structure()
->signature()
->expiration();
} catch (ValidateException | ParseException $e) {
if (in_array($e->getCode(), [1, 2, 3, 4], true)) {
return ['code' => $e->getCode(), 'message' => $e->getMessage()];
}
Expand All @@ -48,13 +47,14 @@ public function validate(): array
/**
* The token must be ready to use.
*
* @return array
* @param mixed[] $validationState
* @return mixed[]
*/
public function validateNotBefore(array $validationState): array
{
try {
$this->parse->validateNotBefore();
} catch (ValidateException $e) {
$this->validate->notBefore();
} catch (ValidateException | ParseException $e) {
if ($e->getCode() === 5) {
return ['code' => $e->getCode(), 'message' => $e->getMessage()];
}
Expand Down
6 changes: 3 additions & 3 deletions tests/Auth/AuthTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class AuthTest extends TestCase
/**
* @covers PsrJwt\Auth\Auth::__construct
*/
public function testAuth()
public function testAuth(): Auth
{
$auth = new Auth(200, 'Ok');
$this->assertInstanceOf(Auth::class, $auth);
Expand All @@ -21,7 +21,7 @@ public function testAuth()
* @depends testAuth
* @covers PsrJwt\Auth\Auth::getCode
*/
public function testGetCode($auth)
public function testGetCode(Auth $auth): void
{
$this->assertSame(200, $auth->getCode());
}
Expand All @@ -30,7 +30,7 @@ public function testGetCode($auth)
* @depends testAuth
* @covers PsrJwt\Auth\Auth::getMessage
*/
public function testGetMessage($auth)
public function testGetMessage(Auth $auth): void
{
$this->assertSame('Ok', $auth->getMessage());
}
Expand Down
Loading

0 comments on commit 95d982f

Please sign in to comment.