> For the complete documentation index, see [llms.txt](https://docs.p0.dev/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.p0.dev/agentic-access/using-the-gateway/headless-oauth-credentials.md).

# OAuth servers from a headless agent

Register an OAuth credential for a federated client, so a headless agent can call an OAuth MCP server behind the P0 AI Gateway with no one signed in.

Some MCP servers behind the P0 AI Gateway (see [P0 Runtime Access for AI](https://docs.p0.dev/readme/agentic-control-plane.md)) use **OAuth** as their credential source, such as most [SaaS MCP servers](https://docs.p0.dev/agentic-access/agentic-gateway/mcp-server/saas.md). Normally a person signs in to the upstream service the first time they use the server. A headless agent, like a batch job or a service in your cluster, has no person and no browser to do that.

To enable headless agents to use OAuth credentials, you register an OAuth credential for the agent's client. The gateway stores the credential and uses it each time that client calls the server. Only that client can use it, and only while the person who registered it owns the client.

## Prerequisites

* A **federated client** for the agent. This is the client an agent gets when it signs in with a token from an [Identity provider](https://docs.p0.dev/agentic-access/identity-provider.md), for example a JWT-SVID (see [JWT-SVID](https://docs.p0.dev/agentic-access/using-the-gateway/spiffe-svid.md)). On the **Clients** tab of **Agentic Access**, its type shows as **Federated**. The client must be active.
* An MCP server with **Credential source** set to **OAuth**, installed on a gateway that has finished setup. See [MCP server](https://docs.p0.dev/agentic-access/agentic-gateway/mcp-server.md).
* An account at the upstream service that the agent should act as. The agent can do whatever this account can do, within your [Agentic access policies](https://docs.p0.dev/agentic-access/agentic-access-policies.md).

## Register an OAuth credential

Do these steps in a browser, as the client's owner. The gateway refuses anyone else. If the client has no owner, an admin who manages clients must set one first.

1. **Open the client.** Go to **Agentic Access** on [p0.app](https://p0.app), open the **Clients** tab, and select the agent's client.
2. **Start registration.** Under **OAuth credentials**, click **Register**.
3. **Choose the server.** In **MCP server**, select the server the agent needs. The list shows only servers that use OAuth.
4. **Go to the gateway.** Click **Continue to gateway**. The gateway opens in a new tab.
5. **Sign in to the gateway.** Use your normal sign-in for the gateway.
6. **Check the client and allow it.** The gateway shows the client's details and the server. Make sure this is the right agent, then click **Allow**.
7. **Sign in to the upstream service.** The upstream service asks you to sign in and approve access. Sign in with the account the agent should act as.

<figure><img src="https://3783273641-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FSQNwGQz62W737pY0FzVb%2Fuploads%2Fgit-blob-2f5ba099ed41d83bfbecf877d098a3630e471f34%2Fimage%20(3).png?alt=media" alt="" width="563"><figcaption></figcaption></figure>

<figure><img src="https://3783273641-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FSQNwGQz62W737pY0FzVb%2Fuploads%2Fgit-blob-e891e96b6ce2c24c758ead8d539ed12b55be47b3%2Fimage%20(4).png?alt=media" alt="" width="563"><figcaption></figcaption></figure>

When you see **Authorization complete**, close the tab. Back in P0, the server now appears under **OAuth credentials** for the client.

Repeat these steps for each server the agent uses. Each credential works for one client and one server.

## Use the credential

You don't need to change the agent. It signs in to the gateway the same way as before and calls the server. The gateway sends the stored credential to the upstream service for it.

The gateway also refreshes the credential for you. You need to register again if any of these happen:

* The upstream service stops accepting the credential, for example because the account's access was revoked there.
* The agent does not use the server for 30 days.
* You change the URL of the MCP server.
* Someone revokes the credential in P0.
* The client gets a new owner. The new owner registers the credential again. Changing the owner doesn't delete the old credential, so revoke it if you want it gone.
* You registered the credential on gateway 1.3.0-beta or earlier, and then upgraded the gateway to 1.4.0 or later.

## See and revoke credentials

Owners and Security Reviewers can see which servers a client has a credential for. Open the client on the **Clients** tab. The list is under **OAuth credentials**.

To revoke one, click **Revoke** next to the server, then confirm. The agent can't use that server again until someone registers a new credential.

{% hint style="info" %}
Disabling a client also stops it from using its credentials. You can't register a new credential for a disabled client. See [Agentic client registration API](https://docs.p0.dev/agentic-access/using-the-gateway/connect-an-mcp-client/client-registration-api.md#update-a-client).
{% endhint %}

## Related

* [JWT-SVID](https://docs.p0.dev/agentic-access/using-the-gateway/spiffe-svid.md): sign in a headless agent to the gateway.
* [Identity provider](https://docs.p0.dev/agentic-access/identity-provider.md): register federated agent identities.
* [Agentic access policies](https://docs.p0.dev/agentic-access/agentic-access-policies.md): control which tools the agent may call.
