Token audience and the smallest scope

A token is a capability for a specific API, for a specific set of actions, for a limited time. Audience and scope are how you keep it from becoming a key to everything the identity provider knows.

Lesson 27 of 29 · 15 min read · practice only with authorization

Diagram

From a consent screen to a token an API will accept

Follow the path. One example at a time.

Step 1 of 4

Ask

The client requests a scope. The person or an admin sees that ask.

Illustration: the ask names a small scope
scope = "invoices.read"
# The application asks for the access the feature needs.
What changes the outcome
API

It checks the signature and nothing else.

Scope

The client asked for broad access.

Life

Refresh does not expire in practice.

The example on the open step is one illustration, or the fix you can paste into an application you own.

What this page is made of

4 pieces. Each one says what fails, who is affected, what you would notice, and what you change.

  1. Audience is which API

    What fails
    A signature proves the issuer made the token. It does not prove the token was made for this API. Without an audience check, a token for a different API is accepted here.
    Who is affected
    The owners of data this API will return under a confused token.
    What you would notice
    Validation that only calls a signature check.
    What you change
    Require the audience your API was given. Reject tokens minted for something else.
  2. Scope is the action

    What fails
    Broad scopes exist because they are easy to request. The consent screen then lies by being vague, and a stolen refresh token can do more than the feature.
    Who is affected
    The person who clicked consent, and the data that scope can reach.
    What you would notice
    A client registered for full mailbox or full admin because one read was needed.
    What you change
    Split the scope. Ask for the read or the send you actually perform. Drop the rest.
  3. Refresh and offline access

    What fails
    Offline access means the client acts when the person is gone. That is a standing key. It needs an owner, a review, and a revoke button.
    Who is affected
    The person, for as long as the refresh token lives.
    What you would notice
    No UI that lists grants. Refresh tokens that never expire.
    What you change
    Show the grant. Expire or rotate refresh. Revoke when the employee or the integration leaves.

A signature is not an audience

Identity providers sign tokens for many APIs. Each token should say which API it is for. If your API only checks the signature, a token stolen or issued for a quieter API becomes a token for the loud one. Validate the issuer, the audience, and the expiry. Reject tokens that have not been valid yet or that are older than you allow. Clock skew has a bound. “None” is not a bound.

Do the check in one library path every service uses. A hand-rolled decode that trusts the payload without a signature is a different and worse bug. A signature check that stops before the audience is the bug this page is about. Both belong in the same review.

Ask for the action, not the account

Scopes accumulate because each integration copies the broadest example. The consent screen becomes a shrug, and the refresh token is a key to mail, files, and directory. Name the action. Invoices.read is a scope. Mailbox full access is a different product and should feel like one when a human approves it.

Offline access and refresh tokens are standing access. They need an owner in your inventory, a lifetime, and a page where the person or the admin can remove them. When an employee leaves or an integration is retired, revocation is the off switch. A token you cannot list is a token you cannot turn off.

The screen has to match the grant

Admin consent that covers a whole tenant is sometimes necessary and often a shortcut. If users never see the client, your review of the scope is the only review. Write the human sentence next to the scope string in the registration. If you cannot write the sentence without wincing, the scope is too big.

You would notice a validation helper with no audience argument, a client requesting a scope named for an entire product, and no revoke UI. The people affected are whoever the grant can act for. The finding names the client, the scope, and the missing check. It does not include a token.

What you change

Add audience to the verifier. Split scopes and re-consent the broad clients. Ship the grant inventory. Expire refresh tokens and rotate them. Test that a token with the wrong audience is rejected even when the signature is valid. Build that token in the test with your own test key. Do not take one from production.

Read the redirect page with this one. Delivery and capability are the two halves of a grant. Exact redirect without a small scope still hands over too much. A small scope sent to the wrong redirect is someone else’s too much.

Check yourself

Recognition and the fix. Nothing here is a procedure.

1 / 3

An API accepts any token the identity provider signed, and it does not look at the audience. What failed?

Sibling techniques

Pages at the same depth, plus a lab and a glossary card for this one.

  1. MapOAuth 2.0 and delegated access: scopes, flows, and tokens explainedHow OAuth lets an app act for a user without the password: the authorization code flow with PKCE, what scopes and consent mean, access versus refresh tokens, and the review points that catch common mistakes.
  1. 01Exact redirect URI matchingThe redirect URI is where the authorization code goes.

Practice

  1. LabOAuth redirect URI matcherTest attacker-chosen redirect URIs against exact, prefix, host, and wildcard matching, and see which strategies leak an authorization code.

Glossary

  1. CardOAuth consent abuseA user approves an application that then reads mail or files under their identity.