Skip to content

Commit c4e2a22

Browse files
committed
move times to own variables, fix jti
1 parent 7664e6a commit c4e2a22

1 file changed

Lines changed: 8 additions & 4 deletions

File tree

src/TokenGenerator.php

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,15 +51,19 @@ public function generateIdToken($accessToken, $clientId, $subject, $nonce, $priv
5151

5252
// Create JWT
5353
$jwtConfig = Configuration::forSymmetricSigner(new Sha256(), InMemory::plainText($privateKey));
54+
$now = new DateTimeImmutable();
55+
$useAfter = $now->sub(new \DateInterval('PT1S'));
56+
$expire = $now->add(new \DateInterval('PT' . 14*24*60*60 . 'S'));
57+
5458
$token = $jwtConfig->builder()
5559
->issuedBy($issuer)
5660
->permittedFor($clientId)
57-
->issuedAt(new DateTimeImmutable(time()))
58-
->canOnlyBeUsedAfter(new DateTimeImmutable(time() - 1))
59-
->expiresAt(new DateTimeImmutable(time() + 14*24*60*60))
61+
->issuedAt($now)
62+
->canOnlyBeUsedAfter($useAfter)
63+
->expiresAt($expire)
6064
->withClaim("azp", $clientId)
6165
->relatedTo($subject)
62-
->withClaim("jti", $this->generateJti())
66+
->identifiedBy($this->generateJti())
6367
->withClaim("nonce", $nonce)
6468
->withClaim("at_hash", $tokenHash) //FIXME: at_hash should only be added if the response_type is a token
6569
->withClaim("c_hash", $tokenHash) // FIXME: c_hash should only be added if the response_type is a code

0 commit comments

Comments
 (0)