Debian Codegraph @

lib/3rdParty/composer/facile-it/php-openid-client/src/functions/get_endpoint_uri.php

raw symbols SCIP
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 * Handle endpoint URI based on auth method.
15 *
16 * @internal
17 */
18 function get_endpoint_uri(OpenIDClient $client, string $endpointMetadata): string
19 {
20 /** @var string|null $authMethod */
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 /** @var null|string $endpoint */
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 }