|
7 | 7 | use Laminas\Diactoros\Response\JsonResponse as JsonResponse; |
8 | 8 | use League\OAuth2\Server\CryptTrait; |
9 | 9 |
|
| 10 | +use DateTimeImmutable; |
10 | 11 | use Lcobucci\JWT\Configuration; |
11 | 12 | use Lcobucci\JWT\Signer\Key\InMemory; |
12 | 13 | use Lcobucci\JWT\Signer\Rsa\Sha256; |
@@ -45,33 +46,30 @@ public function generateRegistrationAccessToken($clientId, $privateKey) { |
45 | 46 | public function generateIdToken($accessToken, $clientId, $subject, $nonce, $privateKey, $dpopKey=null) { |
46 | 47 | $issuer = $this->config->getServer()->get(OidcMeta::ISSUER); |
47 | 48 |
|
48 | | - $jwks = $this->getJwks(); |
| 49 | + $jwks = $this->getJwks(); |
49 | 50 | $tokenHash = $this->generateTokenHash($accessToken); |
50 | 51 |
|
51 | | - // Create JWT |
52 | | - $signer = new \Lcobucci\JWT\Signer\Rsa\Sha256(); |
53 | | - $keychain = new \Lcobucci\JWT\Signer\Keychain(); |
54 | | - $builder = new \Lcobucci\JWT\Builder(); |
55 | | - $token = $builder |
56 | | - ->setIssuer($issuer) |
57 | | - ->permittedFor($clientId) |
58 | | - ->setIssuedAt(time()) |
59 | | - ->setNotBefore(time() - 1) |
60 | | - ->setExpiration(time() + 14*24*60*60) |
61 | | - ->set("azp", $clientId) |
62 | | - ->set("sub", $subject) |
63 | | - ->set("jti", $this->generateJti()) |
64 | | - ->set("nonce", $nonce) |
65 | | - ->set("at_hash", $tokenHash) //FIXME: at_hash should only be added if the response_type is a token |
66 | | - ->set("c_hash", $tokenHash) // FIXME: c_hash should only be added if the response_type is a code |
67 | | - ->set("cnf", array( |
68 | | - "jkt" => $dpopKey, |
69 | | - // "jwk" => $jwks['keys'][0] |
70 | | - )) |
71 | | - ->withHeader('kid', $jwks['keys'][0]['kid']) |
72 | | - ->sign($signer, $keychain->getPrivateKey($privateKey)) |
73 | | - ->getToken(); |
74 | | - return $token->__toString(); |
| 52 | + // Create JWT |
| 53 | + $jwtConfig = Configuration::forSymmetricSigner(new Sha256(), InMemory::plainText($privateKey)); |
| 54 | + $token = $jwtConfig->builder() |
| 55 | + ->issuedBy($issuer) |
| 56 | + ->permittedFor($clientId) |
| 57 | + ->issuedAt(new DateTimeImmutable(time())) |
| 58 | + ->canOnlyBeUsedAfter(new DateTimeImmutable(time() - 1)) |
| 59 | + ->expiresAt(new DateTimeImmutable(time() + 14*24*60*60)) |
| 60 | + ->withClaim("azp", $clientId) |
| 61 | + ->relatedTo($subject) |
| 62 | + ->withClaim("jti", $this->generateJti()) |
| 63 | + ->withClaim("nonce", $nonce) |
| 64 | + ->withClaim("at_hash", $tokenHash) //FIXME: at_hash should only be added if the response_type is a token |
| 65 | + ->withClaim("c_hash", $tokenHash) // FIXME: c_hash should only be added if the response_type is a code |
| 66 | + ->withClaim("cnf", array( |
| 67 | + "jkt" => $dpopKey, |
| 68 | + // "jwk" => $jwks['keys'][0] |
| 69 | + )) |
| 70 | + ->withHeader('kid', $jwks['keys'][0]['kid']) |
| 71 | + ->getToken($jwtConfig->signer(), $jwtConfig->signingKey()); |
| 72 | + return $token->toString(); |
75 | 73 | } |
76 | 74 |
|
77 | 75 | public function respondToRegistration($registration, $privateKey) { |
|
0 commit comments