Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions vicephp/Virtue-JWT/src/JWK/Store/OpenIdKeyStore.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,20 @@

namespace Virtue\JWK\Store;

use GuzzleHttp\Client;
use GuzzleHttp\ClientInterface;
use Virtue\JWK\KeySet;
use Virtue\JWK\KeyStore;
use Virtue\JWT\Token;
use Webmozart\Assert\Assert;

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;
}
Expand All @@ -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) {
Expand All @@ -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 = [];
Expand Down
42 changes: 21 additions & 21 deletions vicephp/Virtue-JWT/tests/JWK/Store/OpenIdKeyStoreTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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();

Expand All @@ -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);
Expand All @@ -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();

Expand All @@ -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();

Expand All @@ -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();

Expand All @@ -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();

Expand All @@ -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();

Expand All @@ -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();

Expand Down