Skip to content

Commit dd7ba46

Browse files
committed
Change TokenGenerator::generateIdToken(), adding a parameter to set token time.
1 parent 43cc138 commit dd7ba46

2 files changed

Lines changed: 5 additions & 5 deletions

File tree

src/TokenGenerator.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,15 +48,15 @@ public function generateRegistrationAccessToken($clientId, $privateKey) {
4848
return $token->toString();
4949
}
5050

51-
public function generateIdToken($accessToken, $clientId, $subject, $nonce, $privateKey, $dpopKey) {
51+
public function generateIdToken($accessToken, $clientId, $subject, $nonce, $privateKey, $dpopKey, $now=null) {
5252
$issuer = $this->config->getServer()->get(OidcMeta::ISSUER);
5353

5454
$jwks = $this->getJwks();
5555
$tokenHash = $this->generateTokenHash($accessToken);
5656

5757
// Create JWT
5858
$jwtConfig = Configuration::forSymmetricSigner(new Sha256(), InMemory::plainText($privateKey));
59-
$now = new DateTimeImmutable();
59+
$now = $now ?? new DateTimeImmutable();
6060
$useAfter = $now->sub(new \DateInterval('PT1S'));
6161

6262
$expire = $now->add($this->validFor);

tests/unit/TokenGeneratorTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -347,17 +347,17 @@ final public function testIdTokenGeneration(): void
347347

348348
$this->assertEquals('{"typ":"JWT","alg":"RS256","kid":"0c3932ca20f3a00ad2eb72035f6cc9cb"}', $header);
349349

350-
// @FIXME: Time-related values are unset, these do need to be tested.
351-
unset($body['exp'], $body['iat'], $body['nbf']);
352-
353350
$this->assertEquals([
354351
'aud' => 'mock clientId',
355352
'azp' => 'mock clientId',
356353
'c_hash' => '1EZBnvsFWlK8ESkgHQsrIQ',
357354
'at_hash' => '1EZBnvsFWlK8ESkgHQsrIQ',
358355
'cnf' => ["jkt" => "mock dpop"],
356+
'exp' => -23225829903.789,
357+
'iat' => -23225829904.789,
359358
'iss' => 'mock issuer',
360359
'jti' => '4dc20036dbd8313ed055',
360+
'nbf' => -23225829905.789,
361361
'nonce' => 'mock nonce',
362362
'sub' => 'mock subject',
363363
], $body);

0 commit comments

Comments
 (0)