diff --git a/vicephp/Virtue-JWT/src/JWK/Store/OpenIdKeyStore.php b/vicephp/Virtue-JWT/src/JWK/Store/OpenIdKeyStore.php index 7172618..a6facc8 100644 --- a/vicephp/Virtue-JWT/src/JWK/Store/OpenIdKeyStore.php +++ b/vicephp/Virtue-JWT/src/JWK/Store/OpenIdKeyStore.php @@ -2,7 +2,7 @@ namespace Virtue\JWK\Store; -use GuzzleHttp\Client; +use GuzzleHttp\ClientInterface; use Virtue\JWK\KeySet; use Virtue\JWK\KeyStore; use Virtue\JWT\Token; @@ -10,12 +10,12 @@ class OpenIdKeyStore implements KeyStore { - /** @var Client */ + /** @var ClientInterface */ private $client; /** @var bool */ private $strict = false; - public function __construct(Client $client) + public function __construct(ClientInterface $client) { $this->client = $client; } @@ -24,7 +24,7 @@ public function getFor(Token $token): KeySet { $issuer = $token->payload('iss'); Assert::string($issuer, 'Issuer must be a string'); - $response = $this->client->get(rtrim($issuer, '/') . '/.well-known/openid-configuration'); + $response = $this->client->request('GET', rtrim($issuer, '/') . '/.well-known/openid-configuration'); $config = json_decode((string) $response->getBody(), true, 512, JSON_THROW_ON_ERROR); Assert::isArray($config, 'Invalid OpenID configuration'); if ($this->strict) { @@ -37,7 +37,7 @@ public function getFor(Token $token): KeySet } Assert::string($config['jwks_uri']); - $response = $this->client->get($config['jwks_uri']); + $response = $this->client->request('GET', $config['jwks_uri']); $keySet = json_decode((string) $response->getBody(), true, 512, JSON_THROW_ON_ERROR); if (!is_array($keySet)) { $keySet = []; diff --git a/vicephp/Virtue-JWT/tests/JWK/Store/OpenIdKeyStoreTest.php b/vicephp/Virtue-JWT/tests/JWK/Store/OpenIdKeyStoreTest.php index 7ba29dd..5aa0e25 100644 --- a/vicephp/Virtue-JWT/tests/JWK/Store/OpenIdKeyStoreTest.php +++ b/vicephp/Virtue-JWT/tests/JWK/Store/OpenIdKeyStoreTest.php @@ -2,7 +2,7 @@ namespace Virtue\JWK\Store; -use GuzzleHttp\Client; +use GuzzleHttp\ClientInterface; use GuzzleHttp\Psr7\Response; use Mockery as M; use Virtue\Api\TestCase; @@ -22,9 +22,9 @@ public function testRemoveTrailingSlashFromIssuer(): void [], Psr7\Utils::streamFor(json_encode(['jwks_uri' => 'https://issuer.ggs-ps.com/keys'])) ); - $client = M::mock(Client::class); - $client->shouldReceive('get') - ->with('https://issuer.ggs-ps.com/.well-known/openid-configuration') + $client = M::mock(ClientInterface::class); + $client->shouldReceive('request') + ->with('GET', 'https://issuer.ggs-ps.com/.well-known/openid-configuration') ->andReturn($response) ->once(); @@ -33,7 +33,7 @@ public function testRemoveTrailingSlashFromIssuer(): void [], Psr7\Utils::streamFor(json_encode(['keys' => [[]]])) ); - $client->shouldReceive('get')->andReturn($response)->once(); + $client->shouldReceive('request')->andReturn($response)->once(); $store = new OpenIdKeyStore($client); $store->getFor($token); @@ -48,9 +48,9 @@ public function testGetKeySet(): void [], Psr7\Utils::streamFor(json_encode(['jwks_uri' => 'https://issuer.ggs-ps.com/keys'])) ); - $client = M::mock(Client::class); - $client->shouldReceive('get') - ->with('https://issuer.ggs-ps.com/.well-known/openid-configuration') + $client = M::mock(ClientInterface::class); + $client->shouldReceive('request') + ->with('GET', 'https://issuer.ggs-ps.com/.well-known/openid-configuration') ->andReturn($response) ->once(); @@ -60,8 +60,8 @@ public function testGetKeySet(): void [], Psr7\Utils::streamFor(json_encode(['keys' => [$key]])) ); - $client->shouldReceive('get') - ->with('https://issuer.ggs-ps.com/keys') + $client->shouldReceive('request') + ->with('GET', 'https://issuer.ggs-ps.com/keys') ->andReturn($response) ->once(); @@ -82,9 +82,9 @@ public function testInvalidJwksUri(): void [], Psr7\Utils::streamFor(json_encode(['jwks_uri' => 'not a URI'])) ); - $client = M::mock(Client::class); - $client->shouldReceive('get') - ->with('https://issuer.ggs-ps.com/.well-known/openid-configuration') + $client = M::mock(ClientInterface::class); + $client->shouldReceive('request') + ->with('GET', 'https://issuer.ggs-ps.com/.well-known/openid-configuration') ->andReturn($response) ->once(); @@ -107,9 +107,9 @@ public function testIssuerMismatch(): void 'jwks_uri' => 'http://localhost', ])) ); - $client = M::mock(Client::class); - $client->shouldReceive('get') - ->with('https://issuer.ggs-ps.com/.well-known/openid-configuration') + $client = M::mock(ClientInterface::class); + $client->shouldReceive('request') + ->with('GET', 'https://issuer.ggs-ps.com/.well-known/openid-configuration') ->andReturn($response) ->once(); @@ -129,9 +129,9 @@ public function testEmptyKeys(): void [], Psr7\Utils::streamFor(json_encode(['jwks_uri' => 'https://issuer.ggs-ps.com/keys'])) ); - $client = M::mock(Client::class); - $client->shouldReceive('get') - ->with('https://issuer.ggs-ps.com/.well-known/openid-configuration') + $client = M::mock(ClientInterface::class); + $client->shouldReceive('request') + ->with('GET', 'https://issuer.ggs-ps.com/.well-known/openid-configuration') ->andReturn($response) ->once(); @@ -140,8 +140,8 @@ public function testEmptyKeys(): void [], Psr7\Utils::streamFor(json_encode('')) ); - $client->shouldReceive('get') - ->with('https://issuer.ggs-ps.com/keys') + $client->shouldReceive('request') + ->with('GET', 'https://issuer.ggs-ps.com/keys') ->andReturn($response) ->once();