Skip to content

Navigation Menu

Sign in
Appearance settings
Sign up
Appearance settings
Open
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
[AccessToken] hardened ClientCredentialsProvider::fetchToken()
  • Loading branch information
pounard committed Sep 30, 2024
commit 4eea5a93a0c7f261402b1ce96f2a37da9eada177
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,9 @@ public function supports(CredentialsInterface $credentials): bool

protected function fetchToken(CredentialsInterface $credentials): AccessTokenInterface
{
\assert($credentials instanceof ClientCredentials);
if (!$credentials instanceof ClientCredentials) {
throw new ProviderFetchException(sprintf('"%s" provider expects "%s" credentials instances.', self::class, ClientCredentials::class));
}

if (!$endpointUrl = ($credentials->getEndpoint() ?? $this->getDefaultEndpointUrl($credentials))) {
throw new ProviderFetchException('OAuth2 credentials are missing the endpoint URL.');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,4 +91,14 @@ public function testRaiseErrorWhenNoToken(): void
self::expectExceptionMessageMatches('/OAuth2 token is missing from response/');
$instance->getAccessToken((new OAuthFactory())->createCredentials(Dsn::fromString($dsn)));
}

public function testRaiseErrorWhenNotClientCredentials(): void
{
$httpClient = new MockHttpClient();
$instance = new ClientCredentialsProvider($httpClient);

self::expectException(ProviderFetchException::class);
self::expectExceptionMessageMatches('/provider expects .* credentials instances/');
$instance->getAccessToken(new BasicAuthCredentials($username));
}
}
Morty Proxy This is a proxified and sanitized view of the page, visit original site.