Skip to content

Commit

Permalink
bug #826 Fix creating tokens when iat is already set in the payload (…
Browse files Browse the repository at this point in the history
…chalasr)

This PR was merged into the 2.x-dev branch.

Discussion
----------

Fix creating tokens when iat is already set in the payload

Fixes #824

Commits
-------

dee98cd Fix creating tokens when iat is already set in the payload
  • Loading branch information
chalasr committed Jan 20, 2021
2 parents f6c0d9a + dee98cd commit c765af7
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
7 changes: 5 additions & 2 deletions Services/JWSProvider/LcobucciJWSProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,13 @@ public function create(array $payload, array $header = [])

$now = time();

$issuedAt = isset($payload['iat']) ? $payload['iat'] : $now;
unset($payload['iat']);

if ($this->legacyJWTApi) {
$jws->setIssuedAt($now);
$jws->setIssuedAt($issuedAt);
} else {
$jws->issuedAt($this->useDateObjects ? new \DateTimeImmutable("@{$now}") : $now);
$jws->issuedAt($this->useDateObjects && !$issuedAt instanceof \DateTimeImmutable ? new \DateTimeImmutable("@{$issuedAt}") : $issuedAt);
}

if (null !== $this->ttl || isset($payload['exp'])) {
Expand Down
2 changes: 1 addition & 1 deletion Tests/Services/JWSProvider/AbstractJWSProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public function testCreate()
->method('getPassphrase')
->willReturn('foobar');

$payload = ['username' => 'chalasr'];
$payload = ['username' => 'chalasr', 'iat' => time()];
$jwsProvider = new static::$providerClass($keyLoaderMock, 'openssl', 'RS384', 3600, 0);

$this->assertInstanceOf(CreatedJWS::class, $created = $jwsProvider->create($payload));
Expand Down

0 comments on commit c765af7

Please sign in to comment.