diff --git a/README.md b/README.md index 632c401..ae0363e 100644 --- a/README.md +++ b/README.md @@ -48,6 +48,7 @@ Symmetric: Asymmetric: - RSA (RS256, RS384, RS512) - ECDSA (ES256, ES384, ES512) +- EdDSA (since 3.1.0) Signer IDs are available as constants (like Jwt::HS256). diff --git a/composer.json b/composer.json index 744a329..f3eb226 100644 --- a/composer.json +++ b/composer.json @@ -19,7 +19,7 @@ }, "require": { "php": ">=7.4", - "lcobucci/jwt": "^4.0", + "lcobucci/jwt": "^4.1", "yiisoft/yii2": ">=2.0.14 <2.1" }, "require-dev": { diff --git a/infection.json.dist b/infection.json.dist index 0bcf1b3..58830a5 100644 --- a/infection.json.dist +++ b/infection.json.dist @@ -14,7 +14,7 @@ "@default": true, "MethodCallRemoval": { "ignore": [ - "bizley\\jwt\\Jwt::init::187", + "bizley\\jwt\\Jwt::init::190", "bizley\\jwt\\JwtHttpBearerAuth::init::68" ] } diff --git a/src/Jwt.php b/src/Jwt.php index a12c482..6c61b65 100644 --- a/src/Jwt.php +++ b/src/Jwt.php @@ -46,6 +46,7 @@ class Jwt extends Component public const ES256 = 'ES256'; public const ES384 = 'ES384'; public const ES512 = 'ES512'; + public const EDDSA = 'EdDSA'; public const STORE_IN_MEMORY = 'in_memory'; public const STORE_LOCAL_FILE_REFERENCE = 'local_file_reference'; @@ -129,6 +130,7 @@ class Jwt extends Component self::ES256 => [Signer\Ecdsa\Sha256::class], self::ES384 => [Signer\Ecdsa\Sha384::class], self::ES512 => [Signer\Ecdsa\Sha512::class], + self::EDDSA => [Signer\Eddsa::class], ]; /** @@ -148,6 +150,7 @@ class Jwt extends Component self::ES256, self::ES384, self::ES512, + self::EDDSA, ], ]; diff --git a/tests/BearerTest.php b/tests/BearerTest.php index d58e024..794beab 100644 --- a/tests/BearerTest.php +++ b/tests/BearerTest.php @@ -15,7 +15,7 @@ use Lcobucci\Clock\SystemClock; use Lcobucci\JWT\Token; use Lcobucci\JWT\Validation\Constraint\IssuedBy; -use Lcobucci\JWT\Validation\Constraint\ValidAt; +use Lcobucci\JWT\Validation\Constraint\LooseValidAt; use PHPUnit\Framework\TestCase; use Yii; use yii\base\InvalidConfigException; @@ -122,7 +122,7 @@ public function testHttpBearerAuthExpiredToken(): void { $now = new DateTimeImmutable(); - $this->getJwt()->getConfiguration()->setValidationConstraints(new ValidAt(SystemClock::fromSystemTimezone())); + $this->getJwt()->getConfiguration()->setValidationConstraints(new LooseValidAt(SystemClock::fromSystemTimezone())); $token = $this->getJwt()->getBuilder() ->issuedAt($now->modify('-10 minutes')) @@ -151,7 +151,7 @@ public function testHttpBearerAuth(): void $now = new DateTimeImmutable(); $this->getJwt()->getConfiguration()->setValidationConstraints( - new ValidAt(SystemClock::fromSystemTimezone()), + new LooseValidAt(SystemClock::fromSystemTimezone()), new IssuedBy('test') ); @@ -179,7 +179,7 @@ public function testHttpBearerAuthCustom(): void { $now = new DateTimeImmutable(); - $this->getJwt()->getConfiguration()->setValidationConstraints(new ValidAt(SystemClock::fromSystemTimezone())); + $this->getJwt()->getConfiguration()->setValidationConstraints(new LooseValidAt(SystemClock::fromSystemTimezone())); $token = $this->getJwt()->getBuilder() ->relatedTo('test') diff --git a/tests/JwtTest.php b/tests/JwtTest.php index 9667479..cbf803d 100644 --- a/tests/JwtTest.php +++ b/tests/JwtTest.php @@ -8,6 +8,7 @@ use bizley\tests\stubs\JwtStub; use Lcobucci\JWT\Decoder; use Lcobucci\JWT\Encoder; +use Lcobucci\JWT\Signer; use Lcobucci\JWT\Validation\Constraint\IdentifiedBy; use Lcobucci\JWT\Validation\RequiredConstraintsViolated; use PHPUnit\Framework\TestCase; @@ -16,6 +17,48 @@ class JwtTest extends TestCase { + public function testAvailableSigners(): void + { + self::assertSame( + [ + Jwt::HS256 => [Signer\Hmac\Sha256::class], + Jwt::HS384 => [Signer\Hmac\Sha384::class], + Jwt::HS512 => [Signer\Hmac\Sha512::class], + Jwt::RS256 => [Signer\Rsa\Sha256::class], + Jwt::RS384 => [Signer\Rsa\Sha384::class], + Jwt::RS512 => [Signer\Rsa\Sha512::class], + Jwt::ES256 => [Signer\Ecdsa\Sha256::class], + Jwt::ES384 => [Signer\Ecdsa\Sha384::class], + Jwt::ES512 => [Signer\Ecdsa\Sha512::class], + Jwt::EDDSA => [Signer\Eddsa::class], + ], + (new Jwt())->signers, + ); + } + + public function testAvailableAlgorithmTypes(): void + { + self::assertSame( + [ + Jwt::SYMMETRIC => [ + Jwt::HS256, + Jwt::HS384, + Jwt::HS512, + ], + Jwt::ASYMMETRIC => [ + Jwt::RS256, + Jwt::RS384, + Jwt::RS512, + Jwt::ES256, + Jwt::ES384, + Jwt::ES512, + Jwt::EDDSA, + ], + ], + (new Jwt())->algorithmTypes, + ); + } + public function testNoInit(): void { $this->expectException(InvalidConfigException::class);