Debian Codegraph @

lib/3rdParty/composer/facile-it/php-openid-client/src/Service/RevocationService.php

raw symbols SCIP
1 <?php
2
3 declare(strict_types=1);
4
5 namespace Facile\OpenIDClient\Service;
6
7 use Facile\OpenIDClient\Client\ClientInterface as OpenIDClient;
8 use Facile\OpenIDClient\Exception\RuntimeException;
9 use Psr\Http\Client\ClientExceptionInterface;
10 use Psr\Http\Client\ClientInterface;
11 use Psr\Http\Message\RequestFactoryInterface;
12
13 use function Facile\OpenIDClient\check_server_response;
14 use function Facile\OpenIDClient\get_endpoint_uri;
15
16 /**
17 * RFC 7009 Token Revocation.
18 *
19 * @see https://tools.ietf.org/html/rfc7009 RFC 7009
20 *
21 * @psalm-api
22 */
23 final class RevocationService
24 {
25 private ClientInterface $client;
26
27 private RequestFactoryInterface $requestFactory;
28
29 public function __construct(
30 ClientInterface $client,
31 RequestFactoryInterface $requestFactory
32 ) {
33 $this->client = $client;
34 $this->requestFactory = $requestFactory;
35 }
36
37 /**
38 * @param array<string, mixed> $params
39 */
40 public function revoke(OpenIDClient $client, string $token, array $params = []): void
41 {
42 $endpointUri = get_endpoint_uri($client, 'revocation_endpoint');
43
44 $authMethod = $client->getAuthMethodFactory()
45 ->create($client->getMetadata()->getRevocationEndpointAuthMethod());
46
47 $tokenRequest = $this->requestFactory->createRequest('POST', $endpointUri)
48 ->withHeader('content-type', 'application/x-www-form-urlencoded');
49
50 $params['token'] = $token;
51 $tokenRequest = $authMethod->createRequest($tokenRequest, $client, $params);
52
53 $httpClient = $client->getHttpClient() ?? $this->client;
54
55 try {
56 $response = $httpClient->sendRequest($tokenRequest);
57 check_server_response($response, 200);
58 } catch (ClientExceptionInterface $e) {
59 throw new RuntimeException('Unable to get revocation response', 0, $e);
60 }
61 }
62 }