esc
  • WorkflowsPages
  • Case studiesPages
  • Machine Learning FoundationsLearn
  • AI EngineeringLearn
  • AI Guardrails & Red TeamingLearn
  • UI/UXLearn
  • Design SystemsLearn
  • Production System DesignLearn
  • AI papersPages
  • Interview KitPages
  • Book a callContact
Let’s talk

I’ll build the agent for it.

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.

11 min readAdvancedOccasional · estimateFacts checked 27 November 2026

Say it out loud

Read it once, then say it without looking. Start with the short one; use the long one when they ask you to go deeper.

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.

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.

Key words

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. 1

    Agent asks for access

    It names the one tool server it wants, so the token is meant only for that server.

  2. 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. 3

    Authorisation server issues a token

    The token expires. An invalid or expired token gets an HTTP 401 error back.

  4. 4

    Agent sends the token

    It goes in the Authorization header of every request. The web address never carries it.

  5. 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.

How an agent gets and uses a token

Agent app

holds the token, never a password

Two stops

Auth server

checks the person, then issues a token

MCP tool server

checks the token is for it

Claims database

returns only what this person may see

  1. 1The agent asks for a token, and the person signs in and approves.
  2. 2The agent calls the tool and sends the token with the request.
  3. 3The tool calls the database with its own separate token, not the agent's.
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.

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

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."

    BetterKeys 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."

    BetterPasswords 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."

    BetterNo. 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?

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?

Can you answer these from memory?

Flash cards · tap a card to flip it

1 / 6

What will they ask next?

  1. Q186What is tool-result poisoning?13 min
  2. Q197Design a tool layer for native, OpenAPI and MCP tools.12 min
  3. Q202Direct vs indirect prompt injection?10 min
  4. Q238How do you keep API keys away from the model?12 min
  5. Q179Excessive agency and least privilege?11 min

Learn it in depth

Last updated on 27 November 2026

Giving an agent access to your own systems?

I design and build AI agents with proper sign-in, scoped tokens and checks on every tool call. Book a short call and tell me which systems yours needs to reach.