diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index 28c7876..c709a01 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -14,6 +14,10 @@ jobs: include: - php: 8.0 coverage: "false" # PHPUnit 8.5.14 doesn't support code coverage under PHP 8 + - php: 8.1 + coverage: "false" # PHPUnit 8.5.14 doesn't support code coverage under PHP 8 + - php: 8.2 + coverage: "false" # PHPUnit 8.5.14 doesn't support code coverage under PHP 8 steps: - name: Checkout @@ -39,7 +43,7 @@ jobs: - name: Psalm run: | ./vendor/bin/psalm --shepherd - + - name: Coveralls if: ${{ matrix.coverage == 'true' }} env: diff --git a/CHANGELOG.md b/CHANGELOG.md index 53082e2..a570b1b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,11 @@ CHANGELOG ========= +6.8.0 +----- + +* Allowed setting custom JWT TTL + 6.7.2 ----- diff --git a/composer.json b/composer.json index 5e10a18..d6a1f71 100644 --- a/composer.json +++ b/composer.json @@ -5,14 +5,15 @@ "license": "GPL-2.0-only", "require": { "php": ">=7.2.0", - "ext-openssl": "*", "ext-json": "*", + "ext-openssl": "*", "codercat/jwk-to-pem": "^1.0", "guzzlehttp/guzzle": "^6.5 || ^7.0", "lcobucci/jwt": "^3.4 || ^4.1.5", "league/oauth2-server": "^8.2", "nesbot/carbon": "^2.43", "nyholm/psr7": "^1.3", + "php-http/message-factory": "^1.1", "phpseclib/phpseclib": "^2.0.31", "psr/cache": "^1.0 || ^2.0 || ^3.0", "psr/http-message": "^1.0", diff --git a/src/Security/Jwt/Builder/Builder.php b/src/Security/Jwt/Builder/Builder.php index 5c9b6b9..140bcb9 100644 --- a/src/Security/Jwt/Builder/Builder.php +++ b/src/Security/Jwt/Builder/Builder.php @@ -42,10 +42,17 @@ class Builder implements BuilderInterface /** @var IdGeneratorInterface */ private $generator; - public function __construct(?ConfigurationFactory $factory = null, ?IdGeneratorInterface $generator = null) - { + /** @var int */ + private $messageTtl; + + public function __construct( + ?ConfigurationFactory $factory = null, + ?IdGeneratorInterface $generator = null, + int $messageTtl = MessagePayloadInterface::TTL + ) { $this->factory = $factory ?? new ConfigurationFactory(); $this->generator = $generator ?? new IdGenerator(); + $this->messageTtl = $messageTtl; } /** @@ -68,7 +75,7 @@ public function build(array $headers, array $claims, KeyInterface $key): TokenIn MessagePayloadInterface::CLAIM_JTI => $this->generator->generate(), MessagePayloadInterface::CLAIM_IAT => $now->toDateTimeImmutable(), MessagePayloadInterface::CLAIM_NBF => $now->toDateTimeImmutable(), - MessagePayloadInterface::CLAIM_EXP => $now->addSeconds(MessagePayloadInterface::TTL)->toDateTimeImmutable(), + MessagePayloadInterface::CLAIM_EXP => $now->addSeconds($this->messageTtl)->toDateTimeImmutable(), ] );