# How Do Agents Authenticate to Tools (OAuth)?

> How an agent gets a token to use tools for a person, what the tool server must check, and when an app uses its own credentials, explained for your AI interview.

**In short:** An agent proves it may use a tool with OAuth. The person signs in and approves the access on the provider's page. The agent then gets a token that expires, and the tool server checks it before acting.

AI and LLM interview question Q185, Agents and tool use. Advanced, occasional (our estimate). From Venkat R. Murty's free Interview Kit: https://designervenkat.online/interview/ai/how-do-agents-authenticate-to-tools-oauth

## Say it in 30 seconds

An agent uses OAuth to prove it may use a tool, so the agent does not need the person's password. The person signs in on the provider's own page and approves the access. The agent gets a token that expires, sends it with each call, and the tool server checks that the token was issued for it. The tool server never passes that token on to another service. For a nightly job with no person, the app uses its own credentials, kept narrow.

## Say it in 2 minutes

An agent is an AI app that calls tools, such as a mail system, a CRM or a claims database. Each tool needs proof that the agent may use it. Sharing a password would be the wrong way, so we use OAuth, the standard for this. It lets an app act with a token that the service issues instead of the user's password.

The flow works like this. The agent sends the person to the provider's sign-in page. The person approves the access they want to give, and the authorisation server, the part that issues tokens, hands the agent a token that expires. The agent sends that token in the Authorization header of each request, never in the web address.

The tool server does the last check. It confirms the token was issued for that server, that it has not expired, and that its scope covers the action. Then it runs the tool. It must never pass the agent's token on to another service. That is token passthrough: accepting a token without checking it and passing it on. The MCP security guide calls this an anti-pattern. The tool calls the other service with its own separate token instead.

When no person is involved, such as a nightly sync, the app signs in with its own credentials. That is a different trade-off. A person's token limits the agent to what that person can see. An app's token needs narrow permissions set by an admin. Either way, give the least access the task needs.

## What is OAuth for an agent, in plain words?

An AI agent often needs to use other services: read a mailbox, look up a customer, open a claim. Each service has to know who is asking and what that caller may do. OAuth is the standard way to handle this. It lets an app get a token from the service, so the app does not need the person's password.

Think of a bank teller's badge. It opens the screens and tills that teller may use, and it stops working when the shift ends. A token works the same way: it is for one service, it covers only certain actions, and it expires. An agent reading claim files for an adjuster needs the same kind of badge, and it should work only inside that adjuster's claims.

The 2026 Model Context Protocol (MCP) specification, the standard for connecting agents to tools, makes OAuth optional. Local tools that use the STDIO transport take their credentials from the environment instead.

- **Token:** The pass a service issues. The agent shows it with each request.
- **Scope:** A named permission on a token, such as claims:read.
- **Consent:** The person's yes to the access, given on the provider's own sign-in page.
- **Audience:** The one service a token was issued for. Other services must refuse it.
- **Authorisation server:** The service that signs the person in and issues the tokens.

## How does an agent get a token?

Five steps, and each stop has one job. The person and the authorisation server handle sign-in. The agent holds the token. The tool server checks it.

1. **Agent asks for access:** It names the one tool server it wants, so the token is meant only for that server.
2. **Person signs in and approves:** The sign-in happens on the provider's page, through the authorisation server. The app also uses PKCE, a secret check that helps prevent someone who intercepts the sign-in code from using it.
3. **Authorisation server issues a token:** The token expires. An invalid or expired token gets an HTTP 401 error back.
4. **Agent sends the token:** It goes in the Authorization header of every request. The web address never carries it.
5. **Tool server checks, then acts:** It checks the audience and the scope, then runs the action. Any call onward uses its own separate token.

*Diagram, How an agent gets and uses a token: The person signs in at the authorisation server, not inside the agent. The agent keeps only the token and sends it to the tool server. The tool server checks the token, then calls the database with its own token.*
1. The agent asks for a token, and the person signs in and approves.
2. The agent calls the tool and sends the token with the request.
3. The tool calls the database with its own separate token, not the agent's.

Claude's MCP connector, still in beta, accepts OAuth Bearer tokens for authenticated servers, so the same token idea works in the API. The app that makes the API call runs the OAuth flow and passes the token in.

## Does the agent act as the person or as itself?

The answer depends on the task, and interviewers often ask which one you would pick.

- **On behalf of a person: The agent sees what they see.** The person signs in and approves the access. Use it for mail, files and CRM data, so the tool applies that person's own permissions.
- **As the app itself: No person in the loop.** For nightly syncs and back-office jobs, the app uses its own credentials. An admin must grant those permissions, so keep them narrow.
- **The mistake: One broad token for all.** Reusing one wide token for every user and every tool lets one bad call reach everything.

> "The OAuth 2.0 client credentials grant flow permits a web service (confidential client) to use its own credentials, instead of impersonating a user, to authenticate when calling another web service." (Microsoft identity platform)
>
> "An MCP client acts as an OAuth 2.1 client, making protected resource requests on behalf of a resource owner." (MCP specification)

The Microsoft quote describes the app-only case. The MCP quote describes the person-first case, where the agent acts for a resource owner.

## What must the tool server check?

The tool server is the last gate, so it checks before it acts. It must refuse a token issued for someone else, even a valid one, and it must never pass the token on.

> "MCP servers MUST NOT accept any tokens that were not explicitly issued for the MCP server." (MCP security best practices)
>
> "Token passthrough is explicitly forbidden in the authorization specification as it introduces a number of security risks" (MCP security best practices)

Here is a small version of the check, with made-up names. It leaves out the signature and issuer checks a real server also makes, so these three tests are only part of the job.

```python
# A simplified check a tool server runs on every call (made-up claims system).
CLAIMS_SERVER = "https://claims-tools.example.com/mcp"
NOW = 1800000000  # a fixed clock, so the result never changes

def check_token(token):
    # The token must be for this server, not another service.
    if token["aud"] != CLAIMS_SERVER:
        return "REJECTED: issued for " + token["aud"]
    if NOW >= token["exp"]:
        return "REJECTED: expired, the client must get a new token"
    if "claims:read" not in token["scope"]:
        return "REJECTED: missing claims:read"
    # Only now does the tool run. It never forwards the token on.
    return "OK: " + token["sub"] + " may read claims"

tokens = [
    {"aud": "https://crm.example.com", "sub": "priya", "scope": ["claims:read"], "exp": NOW + 600},
    {"aud": CLAIMS_SERVER, "sub": "priya", "scope": ["claims:read"], "exp": NOW + 600},
    {"aud": CLAIMS_SERVER, "sub": "priya", "scope": ["claims:read"], "exp": NOW - 1},
    {"aud": CLAIMS_SERVER, "sub": "sam", "scope": ["claims:write"], "exp": NOW + 600},
]
for token in tokens:
    print(check_token(token))
```

Output:

```text
REJECTED: issued for https://crm.example.com
OK: priya may read claims
REJECTED: expired, the client must get a new token
REJECTED: missing claims:read
```

> **Tip:** Asked how you would stop a stolen token? Say it expires, check the audience on every call, never pass it on, and keep it out of web addresses. Don't promise leaks can't happen.

### How would you connect an agent to a claims system?

Picture a mid-size insurer's claims assistant. It drafts replies for claims adjusters, reads claim files and can email policyholders. Here is how I would set its access up.

- **Sign in as the adjuster:** The agent then sees only that adjuster's assigned claims.
- **Refuse the wrong token:** The claims server refuses any token that was not issued for it.
- **Separate scopes for each action:** Reading claims needs claims:read. Sending mail needs its own scope and a person's click.
- **Log the caller, not the token:** Logs record who called and which scope was used, never the token itself.

An adjuster types: "Summarise the open claims on this policy, and flag any over 30 days." That is read-only, so it runs with claims:read and nothing more.

## What does the interviewer want to hear?

**A strong answer covers**

- [ ] A plain answer: the agent gets a token after the person signs in, through OAuth.
- [ ] Whose access: the person's token, or the app's own, and why.
- [ ] The tool server checks the audience and the scope on every call.
- [ ] No token passthrough, and no tokens in web addresses.
- [ ] Least privilege: request only the scopes each task needs.
- [ ] An honest limit: a stolen token keeps working until it expires.

**Common traps**

- Trap: "Just give the agent the API key." Better: Keys in a prompt can be copied. Keep secrets in the server or connector, and give the agent a token that expires.
- Trap: "The agent logs in with my password." Better: Passwords belong to the person at the provider's sign-in page. The agent holds a token, never the password.
- Trap: "Any valid token works on any tool." Better: No. A token must be issued for that one tool server, or the server refuses it.

## Can you spot the flaw?

**Spot the flaw:** A tool server gets a valid token from an agent, and it needs data from the claims database. Which step is the flaw?

A. Check the token's audience is this tool server.
B. Check the token has not expired and its scope covers the action.
C. Forward the agent's token to the claims database so it can check the user too.
D. Return an error if the token is missing or invalid.

**Answer:** C. Forwarding the token is token passthrough, which the spec forbids. The database may trust a token this server never checked. The fix is a separate token for the database, issued by the database's own authorisation server.

**Quick check:** An agent holds a valid token issued for the mail server, and it sends that token to the claims tool. What should the claims tool do?

A. Run the call, since the token's signature is valid
B. Refuse it, because the token was not issued for this server
C. Pass the token on to the mail server so it can check
D. Ask the model to pick a different token

**Answer:** B. A valid signature is not enough. The token must be issued for this server, or it is refused. Passing it on is the passthrough mistake, and asking the model to choose a token is no fix at all.

## Can you answer these from memory?

**Flash cards**

- **What does OAuth give an agent?** A token that proves access, so the agent does not need the user's password.
- **Who signs the person in?** The authorisation server, on the provider's own page, not the agent.
- **What is the audience?** The one service a token was issued for. Other services must refuse it.
- **Where does the token go?** In the Authorization header of each request, never in the web address.
- **On behalf of a person, or as the app?** A person's token when the agent should see only what they see; app credentials for jobs.
- **What is token passthrough?** A tool forwarding the agent's token to another service. The MCP spec forbids it.

## Likely follow-up questions

- Q186 What is tool-result poisoning? https://designervenkat.online/interview/ai/what-is-tool-result-poisoning
- Q197 Design a tool layer for native, OpenAPI and MCP tools. https://designervenkat.online/interview/ai/design-a-tool-layer-for-native-openapi-and-mcp-tools
- Q202 Direct vs indirect prompt injection? https://designervenkat.online/interview/ai/direct-vs-indirect-prompt-injection
- Q238 How do you keep API keys away from the model? https://designervenkat.online/interview/ai/how-do-you-keep-api-keys-away-from-the-model
- Q179 Excessive agency and least privilege? https://designervenkat.online/interview/ai/excessive-agency-and-least-privilege

## Learn it in depth

- [Connecting to MCP servers](https://designervenkat.online/learn/ai-engineering/connecting-to-mcp-servers)
