| 1 |
<?php |
| 2 |
|
| 3 |
declare(strict_types=1); |
| 4 |
|
| 5 |
namespace Facile\OpenIDClient\AuthMethod; |
| 6 |
|
| 7 |
use Facile\OpenIDClient\Client\ClientInterface as OpenIDClient; |
| 8 |
use Psr\Http\Message\RequestInterface; |
| 9 |
use Override; |
| 10 |
|
| 11 |
use function array_merge; |
| 12 |
use function http_build_query; |
| 13 |
|
| 14 |
abstract class AbstractJwtAuth implements AuthMethodInterface |
| 15 |
{ |
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
abstract protected function createAuthJwt(OpenIDClient $client, array $claims = []): string; |
| 20 |
|
| 21 |
#[Override] |
| 22 |
public function createRequest( |
| 23 |
RequestInterface $request, |
| 24 |
OpenIDClient $client, |
| 25 |
array $claims |
| 26 |
): RequestInterface { |
| 27 |
$clientId = $client->getMetadata()->getClientId(); |
| 28 |
|
| 29 |
$claims = array_merge([ |
| 30 |
'client_id' => $clientId, |
| 31 |
'client_assertion_type' => 'urn:ietf:params:oauth:client-assertion-type:jwt-bearer', |
| 32 |
'client_assertion' => $this->createAuthJwt($client, $claims), |
| 33 |
], $claims); |
| 34 |
|
| 35 |
$request->getBody()->write(http_build_query($claims)); |
| 36 |
|
| 37 |
return $request; |
| 38 |
} |
| 39 |
} |