Skip to content

ClientCredentialsClient

Outbound M2M: fetches an access token via the Client Credentials grant for the app to present to another service.

Unrelated to inbound request authentication — pair with BearerTokenAuthenticator (packages/auth-jwt) on the receiving end.

final class ClientCredentialsClient

Since1.0.0
SourceClientCredentialsClient.php

public function __construct(string $clientId, string $clientSecret, string $tokenEndpoint, array<int, string> $scopes = [], ?ClientInterface $httpClient = null): mixed

A Guzzle HTTP client override (e.g. for testing); defaults to a real Guzzle client.

ParameterTypeDescription
$clientIdstringThe OAuth client id.
$clientSecretstringThe OAuth client secret.
$tokenEndpointstringThe authorization server’s /token endpoint.
$scopesarray``<``int``, ``string``>The scopes to request.
$httpClient?``ClientInterfaceA Guzzle HTTP client override (e.g. for testing); defaults to a real Guzzle client.

Returns mixed

MethodDescription
fromDiscovery(OidcDiscoveryDocument $document, string $clientId, string $clientSecret, array<int, string> $scopes = [], ?ClientInterface $httpClient = null): selfBuilds a client from a provider’s discovery document (see OidcDiscoveryClient) instead of a hand-copied token-endpoint URL.
getAccessToken(): AccessTokenInterface

public static function fromDiscovery(OidcDiscoveryDocument $document, string $clientId, string $clientSecret, array<int, string> $scopes = [], ?ClientInterface $httpClient = null): self

Builds a client from a provider’s discovery document (see OidcDiscoveryClient) instead of a hand-copied token-endpoint URL.

A Guzzle HTTP client override (e.g. for testing); defaults to a real Guzzle client.

ParameterTypeDescription
$documentOidcDiscoveryDocumentThe provider’s metadata.
$clientIdstringThe OAuth client id.
$clientSecretstringThe OAuth client secret.
$scopesarray``<``int``, ``string``>The scopes to request.
$httpClient?``ClientInterfaceA Guzzle HTTP client override (e.g. for testing); defaults to a real Guzzle client.

Returns self — A client wired to the discovered token endpoint.

ThrowsWhen
AuthenticationExceptionIf the document does not advertise a token endpoint.

public function getAccessToken(): AccessTokenInterface

Returns AccessTokenInterface — The M2M access token, for the app to present to another service.