Skip to content

Commit b6d8cf4

Browse files
authored
Merge pull request #7 from facile-it/jwt-framework3
chore: allow jwt-framework v3
2 parents 39d9762 + eaa8c03 commit b6d8cf4

30 files changed

+602
-129
lines changed

.github/workflows/continuous-integration.yml

Lines changed: 44 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ jobs:
2424
- "7.3"
2525
- "7.4"
2626
- "8.0"
27+
- "8.1"
2728

2829
steps:
2930
- name: "Checkout"
@@ -47,14 +48,54 @@ jobs:
4748
run: "composer update --no-interaction --no-progress --no-suggest --prefer-dist"
4849

4950
- name: "Run psalm"
50-
run: "vendor/bin/psalm --long-progress --output-format=github --report=psalm.sarif"
51+
run: "vendor/bin/psalm --long-progress --output-format=github --report=psalm.sarif --php-version=${{ matrix.php-version }}"
5152

5253
- name: "Upload SARIF file"
5354
uses: github/codeql-action/upload-sarif@v1
5455
continue-on-error: true
5556
with:
5657
sarif_file: psalm.sarif
5758

59+
codestyle:
60+
name: "Code Style"
61+
runs-on: "ubuntu-20.04"
62+
63+
strategy:
64+
matrix:
65+
php-version:
66+
- "8.1"
67+
deps:
68+
- "latest"
69+
coverage:
70+
- "false"
71+
72+
steps:
73+
- name: "Checkout"
74+
uses: "actions/checkout@v2"
75+
with:
76+
fetch-depth: 2
77+
78+
- name: "Install PHP"
79+
uses: "shivammathur/setup-php@v2"
80+
with:
81+
php-version: "${{ matrix.php-version }}"
82+
coverage: "pcov"
83+
ini-values: "zend.assertions=1"
84+
extensions: "bcmath gmp"
85+
86+
- name: "Cache dependencies installed with composer"
87+
uses: "actions/cache@v2"
88+
with:
89+
path: "~/.composer/cache"
90+
key: "php-${{ matrix.php-version }}-composer-${{ hashFiles('composer.lock') }}"
91+
restore-keys: "php-${{ matrix.php-version }}-composer-"
92+
93+
- name: "Install dependencies with composer"
94+
run: "composer update --no-interaction --no-progress --no-suggest --prefer-dist"
95+
96+
- name: "Run PHPCS check"
97+
run: "composer cs-check"
98+
5899
phpunit:
59100
name: "PHPUnit"
60101
runs-on: "ubuntu-20.04"
@@ -66,13 +107,14 @@ jobs:
66107
- "7.3"
67108
- "7.4"
68109
- "8.0"
110+
- "8.1"
69111
deps:
70112
- "lowest"
71113
- "latest"
72114
coverage:
73115
- "false"
74116
include:
75-
- php-version: "7.4"
117+
- php-version: "8.1"
76118
deps: "latest"
77119
coverage: "true"
78120

@@ -109,10 +151,6 @@ jobs:
109151
run: "vendor/bin/phpunit -c phpunit.xml.dist"
110152
if: "${{ matrix.coverage != 'true' }}"
111153

112-
- name: "Run PHPCS check"
113-
run: "composer cs-check"
114-
if: "${{ matrix.coverage == 'true' }}"
115-
116154
- name: "Run PHPUnit with coverage"
117155
run: "vendor/bin/phpunit -c phpunit.xml.dist --coverage-clover=coverage-report.xml"
118156
if: "${{ matrix.coverage == 'true' }}"

composer.json

Lines changed: 24 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,14 @@
3636
"php-http/discovery": "^1.7",
3737
"psr/http-client": "^1.0",
3838
"psr/http-message": "^1.0",
39-
"psr/simple-cache": "^1.0",
39+
"psr/simple-cache": "^1.0 || ^2.0 || ^3.0",
4040
"spomky-labs/base64url": "^2.0.1",
4141
"symfony/polyfill-mbstring": "^1.15",
42-
"web-token/jwt-checker": "^2.2.0",
43-
"web-token/jwt-core": "^2.2.0",
44-
"web-token/jwt-easy": "^2.2.0",
45-
"web-token/jwt-key-mgmt": "^2.2.0",
46-
"web-token/jwt-signature": "^2.2.0",
47-
"web-token/jwt-signature-algorithm-rsa": "^2.2.0"
42+
"web-token/jwt-checker": "^2.2.0 || ^3.0",
43+
"web-token/jwt-core": "^2.2.0 || ^3.0",
44+
"web-token/jwt-key-mgmt": "^2.2.0 || ^3.0",
45+
"web-token/jwt-signature": "^2.2.0 || ^3.0",
46+
"web-token/jwt-signature-algorithm-rsa": "^2.2.0 || ^3.0"
4847
},
4948
"autoload": {
5049
"files": [
@@ -67,28 +66,28 @@
6766
"php-http/curl-client": "^2.1",
6867
"phpspec/prophecy-phpunit": "^1.1 || ^2.0",
6968
"phpunit/phpunit": "^8.5.14 || ^9.3",
70-
"vimeo/psalm": "^4.4.1",
71-
"web-token/jwt-encryption": "^2.2.0",
72-
"web-token/jwt-encryption-algorithm-aescbc": "^2.2.0",
73-
"web-token/jwt-encryption-algorithm-aesgcm": "^2.2.0",
74-
"web-token/jwt-encryption-algorithm-aesgcmkw": "^2.2.0",
75-
"web-token/jwt-encryption-algorithm-aeskw": "^2.2.0",
76-
"web-token/jwt-encryption-algorithm-dir": "^2.2.0",
77-
"web-token/jwt-encryption-algorithm-ecdh-es": "^2.2.0",
78-
"web-token/jwt-encryption-algorithm-experimental": "^2.2.0",
79-
"web-token/jwt-encryption-algorithm-pbes2": "^2.2.0",
80-
"web-token/jwt-encryption-algorithm-rsa": "^2.2.0",
81-
"web-token/jwt-nested-token": "^2.2.0",
82-
"web-token/jwt-signature-algorithm-ecdsa": "^2.2.0",
83-
"web-token/jwt-signature-algorithm-experimental": "^2.2.0",
84-
"web-token/jwt-signature-algorithm-hmac": "^2.2.0",
85-
"web-token/jwt-signature-algorithm-none": "^2.2.0",
86-
"web-token/jwt-util-ecc": "^2.2.0"
69+
"vimeo/psalm": "^4.23",
70+
"web-token/jwt-encryption": "^2.2.0 || ^3.0",
71+
"web-token/jwt-encryption-algorithm-aescbc": "^2.2.0 || ^3.0",
72+
"web-token/jwt-encryption-algorithm-aesgcm": "^2.2.0 || ^3.0",
73+
"web-token/jwt-encryption-algorithm-aesgcmkw": "^2.2.0 || ^3.0",
74+
"web-token/jwt-encryption-algorithm-aeskw": "^2.2.0 || ^3.0",
75+
"web-token/jwt-encryption-algorithm-dir": "^2.2.0 || ^3.0",
76+
"web-token/jwt-encryption-algorithm-ecdh-es": "^2.2.0 || ^3.0",
77+
"web-token/jwt-encryption-algorithm-experimental": "^2.2.0 || ^3.0",
78+
"web-token/jwt-encryption-algorithm-pbes2": "^2.2.0 || ^3.0",
79+
"web-token/jwt-encryption-algorithm-rsa": "^2.2.0 || ^3.0",
80+
"web-token/jwt-nested-token": "^2.2.0 || ^3.0",
81+
"web-token/jwt-signature-algorithm-ecdsa": "^2.2.0 || ^3.0",
82+
"web-token/jwt-signature-algorithm-experimental": "^2.2.0 || ^3.0",
83+
"web-token/jwt-signature-algorithm-hmac": "^2.2.0 || ^3.0",
84+
"web-token/jwt-signature-algorithm-none": "^2.2.0 || ^3.0",
85+
"web-token/jwt-util-ecc": "^2.2.0 || ^3.0"
8786
},
8887
"scripts": {
8988
"cs-check": "php-cs-fixer fix --dry-run --diff --allow-risky=yes",
9089
"cs-fix": "php-cs-fixer fix --diff --allow-risky=yes",
91-
"psalm": "psalm",
90+
"psalm": "psalm --php-version=8.1",
9291
"test": "phpunit",
9392
"test-coverage": "phpunit --coverage-text",
9493
"check": [

src/AbstractTokenVerifier.php

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44

55
namespace Facile\JoseVerifier;
66

7-
use Facile\JoseVerifier\ClaimChecker\AuthTimeChecker;
8-
use Facile\JoseVerifier\ClaimChecker\AzpChecker;
9-
use Facile\JoseVerifier\ClaimChecker\NonceChecker;
7+
use Facile\JoseVerifier\Checker\AuthTimeChecker;
8+
use Facile\JoseVerifier\Checker\AzpChecker;
9+
use Facile\JoseVerifier\Checker\NonceChecker;
1010
use Facile\JoseVerifier\Decrypter\TokenDecrypterInterface;
1111
use Facile\JoseVerifier\Exception\InvalidArgumentException;
1212
use Facile\JoseVerifier\Exception\InvalidTokenException;
@@ -15,6 +15,12 @@
1515
use Facile\JoseVerifier\JWK\MemoryJwksProvider;
1616
use Facile\JoseVerifier\Validate\Validate;
1717
use function is_array;
18+
use Jose\Component\Checker\AlgorithmChecker;
19+
use Jose\Component\Checker\AudienceChecker;
20+
use Jose\Component\Checker\ExpirationTimeChecker;
21+
use Jose\Component\Checker\IssuedAtChecker;
22+
use Jose\Component\Checker\IssuerChecker;
23+
use Jose\Component\Checker\NotBeforeChecker;
1824
use Jose\Component\Core\JWK;
1925
use Jose\Component\Core\JWKSet;
2026
use Jose\Component\Core\Util\JsonConverter;
@@ -189,38 +195,37 @@ protected function create(string $jwt): Validate
189195

190196
if ($this->aadIssValidation) {
191197
$payload = $this->getPayload($jwt);
192-
$expectedIssuer = str_replace('{tenantid}', $payload['tid'] ?? '', $expectedIssuer);
198+
$expectedIssuer = str_replace('{tenantid}', (string) ($payload['tid'] ?? ''), $expectedIssuer);
193199
}
194200

195201
$validator = Validate::token($jwt)
196202
->keyset($this->buildJwks($jwt))
197-
->iss($expectedIssuer)
198-
->iat($this->clockTolerance)
199-
->aud($this->clientId)
200-
->exp($this->clockTolerance)
201-
->nbf($this->clockTolerance);
203+
->claim(new IssuerChecker([$expectedIssuer], true))
204+
->claim(new IssuedAtChecker($this->clockTolerance, true))
205+
->claim(new AudienceChecker($this->clientId, true))
206+
->claim(new ExpirationTimeChecker($this->clockTolerance))
207+
->claim(new NotBeforeChecker($this->clockTolerance, true));
202208

203209
if (null !== $this->azp) {
204-
$validator = $validator->claim('azp', new AzpChecker($this->azp));
210+
$validator = $validator->claim(new AzpChecker($this->azp));
205211
}
206212

207213
if (null !== $this->expectedAlg) {
208-
$validator = $validator->alg($this->expectedAlg);
214+
$validator = $validator->header(new AlgorithmChecker([$this->expectedAlg], true));
209215
}
210216

211217
if (null !== $this->nonce) {
212-
$validator = $validator->claim('nonce', new NonceChecker($this->nonce));
218+
$validator = $validator->claim(new NonceChecker($this->nonce));
213219
}
214220

215221
if (null !== $this->maxAge) {
216-
$validator = $validator->claim('auth_time', new AuthTimeChecker($this->maxAge, $this->clockTolerance));
222+
$validator = $validator->claim(new AuthTimeChecker($this->maxAge, $this->clockTolerance));
217223
}
218224

219225
if ((int) $this->maxAge > 0 || null !== $this->maxAge) {
220226
$mandatoryClaims[] = 'auth_time';
221227
}
222228

223-
/** @var Validate $validator */
224229
$validator = $validator->mandatory($mandatoryClaims);
225230

226231
return $validator;

src/ClaimChecker/AbstractHashChecker.php renamed to src/Checker/AbstractHashChecker.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
declare(strict_types=1);
44

5-
namespace Facile\JoseVerifier\ClaimChecker;
5+
namespace Facile\JoseVerifier\Checker;
66

77
use Base64Url\Base64Url;
88
use function hash;
@@ -13,6 +13,9 @@
1313
use function strlen;
1414
use function substr;
1515

16+
/**
17+
* @internal
18+
*/
1619
abstract class AbstractHashChecker implements ClaimChecker
1720
{
1821
/** @var string */
@@ -45,7 +48,7 @@ private function getShaSize(string $alg): string
4548
}
4649

4750
/**
48-
* {@inheritdoc}
51+
* @param mixed $value
4952
*/
5053
public function checkClaim($value): void
5154
{

src/ClaimChecker/AtHashChecker.php renamed to src/Checker/AtHashChecker.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,11 @@
22

33
declare(strict_types=1);
44

5-
namespace Facile\JoseVerifier\ClaimChecker;
5+
namespace Facile\JoseVerifier\Checker;
66

7+
/**
8+
* @internal
9+
*/
710
final class AtHashChecker extends AbstractHashChecker
811
{
912
private const CLAIM_NAME = 'at_hash';

src/ClaimChecker/AuthTimeChecker.php renamed to src/Checker/AuthTimeChecker.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,16 @@
22

33
declare(strict_types=1);
44

5-
namespace Facile\JoseVerifier\ClaimChecker;
5+
namespace Facile\JoseVerifier\Checker;
66

77
use function is_int;
88
use Jose\Component\Checker\ClaimChecker;
99
use Jose\Component\Checker\InvalidClaimException;
1010
use function time;
1111

12+
/**
13+
* @internal
14+
*/
1215
final class AuthTimeChecker implements ClaimChecker
1316
{
1417
private const CLAIM_NAME = 'auth_time';
@@ -26,7 +29,7 @@ public function __construct(int $maxAge, int $allowedTimeDrift = 0)
2629
}
2730

2831
/**
29-
* {@inheritdoc}
32+
* @param mixed $value
3033
*/
3134
public function checkClaim($value): void
3235
{

src/ClaimChecker/AzpChecker.php renamed to src/Checker/AzpChecker.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,15 @@
22

33
declare(strict_types=1);
44

5-
namespace Facile\JoseVerifier\ClaimChecker;
5+
namespace Facile\JoseVerifier\Checker;
66

77
use Jose\Component\Checker\ClaimChecker;
88
use Jose\Component\Checker\InvalidClaimException;
99
use function sprintf;
1010

11+
/**
12+
* @internal
13+
*/
1114
final class AzpChecker implements ClaimChecker
1215
{
1316
private const CLAIM_NAME = 'azp';
@@ -21,7 +24,7 @@ public function __construct(string $azp)
2124
}
2225

2326
/**
24-
* {@inheritdoc}
27+
* @param mixed $value
2528
*/
2629
public function checkClaim($value): void
2730
{

src/ClaimChecker/CHashChecker.php renamed to src/Checker/CHashChecker.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,11 @@
22

33
declare(strict_types=1);
44

5-
namespace Facile\JoseVerifier\ClaimChecker;
5+
namespace Facile\JoseVerifier\Checker;
66

7+
/**
8+
* @internal
9+
*/
710
final class CHashChecker extends AbstractHashChecker
811
{
912
private const CLAIM_NAME = 'c_hash';

0 commit comments

Comments
 (0)