| 1 |
<?php |
| 2 |
|
| 3 |
declare(strict_types=1); |
| 4 |
|
| 5 |
namespace Facile\OpenIDClient; |
| 6 |
|
| 7 |
use Facile\OpenIDClient\Client\ClientInterface as OpenIDClient; |
| 8 |
use Facile\OpenIDClient\Exception\RuntimeException; |
| 9 |
|
| 10 |
use function is_string; |
| 11 |
use function strpos; |
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
function get_endpoint_uri(OpenIDClient $client, string $endpointMetadata): string |
| 19 |
{ |
| 20 |
|
| 21 |
$authMethod = $client->getMetadata()->get($endpointMetadata . '_auth_method'); |
| 22 |
|
| 23 |
$endpoint = null; |
| 24 |
|
| 25 |
if (null !== $authMethod && false !== strpos($authMethod, 'tls_client_auth')) { |
| 26 |
$endpoint = $client->getIssuer() |
| 27 |
->getMetadata() |
| 28 |
->getMtlsEndpointAliases()['token_endpoint'] ?? null; |
| 29 |
} |
| 30 |
|
| 31 |
if ($endpoint === null) { |
| 32 |
|
| 33 |
$endpoint = $client->getIssuer()->getMetadata()->get($endpointMetadata); |
| 34 |
} |
| 35 |
|
| 36 |
if (! is_string($endpoint)) { |
| 37 |
throw new RuntimeException('Unable to retrieve the token endpoint'); |
| 38 |
} |
| 39 |
|
| 40 |
return $endpoint; |
| 41 |
} |