Skip to content

Commit

Permalink
Fix creating tokens when iat is already set in the payload
Browse files Browse the repository at this point in the history
  • Loading branch information
chalasr committed Jan 20, 2021
1 parent f6c0d9a commit dee98cd
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 dee98cd

Please sign in to comment.