Something went wrong. Try again.
mirror of github.com/PrefectHQ/fastmcp
Something went wrong. Try again.
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667---title: client_credentialssidebarTitle: client_credentials---
# `fastmcp.client.auth.client_credentials`
Machine-to-machine (M2M) OAuth client authentication for FastMCP.
These providers authenticate a FastMCP client to a protected MCP server withouta browser, using the OAuth 2.0 ``client_credentials`` grant:
- `ClientCredentialsOAuthProvider` authenticates with a ``client_id`` and ``client_secret`` (the common M2M case).- `PrivateKeyJWTOAuthProvider` authenticates with an RFC 7523 ``private_key_jwt`` client assertion (workload identity federation, or a locally signed JWT).
Both are thin wrappers over the MCP SDK's client-credentials providers. Like theinteractive `OAuth` provider, they can be constructed without an ``mcp_url`` andbound to the server URL automatically when passed to `Client(auth=...)`.
## Classes
### `ClientCredentialsOAuthProvider` <sup><a href="https://github.com/PrefectHQ/fastmcp/blob/main/fastmcp_slim/fastmcp/client/auth/client_credentials.py#L164" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
OAuth ``client_credentials`` provider using a client ID and secret.
This is the standard machine-to-machine flow: the client exchanges its``client_id`` and ``client_secret`` at the authorization server's tokenendpoint for an access token, which is then attached to every request. Thetoken endpoint is discovered from the MCP server's OAuth metadata, so callersprovide the MCP server URL rather than a raw token endpoint.
**Methods:**
#### `async_auth_flow` <sup><a href="https://github.com/PrefectHQ/fastmcp/blob/main/fastmcp_slim/fastmcp/client/auth/client_credentials.py#L258" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
```pythonasync_auth_flow(self, request: httpx2.Request) -> AsyncGenerator[httpx2.Request, httpx2.Response]```
### `PrivateKeyJWTOAuthProvider` <sup><a href="https://github.com/PrefectHQ/fastmcp/blob/main/fastmcp_slim/fastmcp/client/auth/client_credentials.py#L281" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
OAuth ``client_credentials`` provider using ``private_key_jwt`` (RFC 7523).
Instead of a shared client secret, the client authenticates to the tokenendpoint with a signed JWT assertion. The ``assertion_provider`` callbackreceives the authorization server's issuer identifier (the required JWTaudience) and returns the assertion. Use`SignedJWTParameters.create_assertion_provider()` to sign locally with aprivate key, `static_assertion_provider()` for a pre-built JWT, or supply yourown callback for workload identity federation.
**Methods:**
#### `async_auth_flow` <sup><a href="https://github.com/PrefectHQ/fastmcp/blob/main/fastmcp_slim/fastmcp/client/auth/client_credentials.py#L384" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
```pythonasync_auth_flow(self, request: httpx2.Request) -> AsyncGenerator[httpx2.Request, httpx2.Response]```