Skip to content
Workforce IdentityMarkdown

Give a client tokens for one API

Make each token name the one API it's for, so a token leaked from one API can't be used at another.

APIRFC 8707

A token names its API in aud, and an API that checks aud refuses tokens meant for any other. So if one API is compromised or logs tokens carelessly, the tokens taken there are useless against the rest. This guide is for any client that calls more than one of your APIs, and every API that checks tokens.

Before you start:

  • Who can do it: a realm administrator, in a group that holds RealmOwner (Delegated administration). RealmViewer can read the settings but not change them.
  • Where: today this is done through the API; Call the API shows how to get $CVYUH_SESSION.
  • First: have the client’s ID and the audience of each API it calls.
  1. List the APIs the client may call, and the one it gets when it names none:

    Terminal window
    curl -X PATCH 'https://foobar.cvyuh.com/api/v0/am/objects/v1/oauth2Client/<client-id>' \
    -H "Cookie: x-cvyuh-token=$CVYUH_SESSION" \
    -H "Content-Type: application/json" \
    -d '{ "allowedResources": ["https://billing.example.com/api",
    "https://reports.example.com/api"],
    "defaultAudience": "https://billing.example.com/api" }'

    The list you send replaces the client’s whole list, so name every API it may call. Each address is an absolute https URL with no fragment. defaultAudience must be one of allowedResources; without it, a request naming no API is refused.

  2. Optionally, require every token request in the realm to name its API:

    Terminal window
    curl -X PATCH https://foobar.cvyuh.com/api/v0/am/objects/v1/oauth2Settings/oauth2Settings \
    -H "Cookie: x-cvyuh-token=$CVYUH_SESSION" \
    -H "Content-Type: application/json" \
    -d '{ "requireResource": true }'
  3. Have the client name the API in each token request: resource=https://billing.example.com/api.

  4. Have each API check that aud holds its own address, or ask the realm, as in Check a token at your API.

  • A request naming an API not on the client’s list is refused invalid_target.
  • A request naming none gets a token for the default API.
  • On a refresh, the client may ask for fewer of its granted APIs, never more.
  • Each token’s TOKEN_ISSUED record shows the APIs asked for and the audience granted. Find it in Audit → Authentication in the dashboard.
SymptomCauseFix
invalid_targetThe API named isn’t on the client’s list, or none was named with requireResource on and no defaultAudienceAdd it to allowedResources, or set defaultAudience
Saving the client is refuseddefaultAudience isn’t one of allowedResources, or an address isn’t an absolute https URLFix the list
An API accepts tokens meant for anotherIt doesn’t check audHave it check aud, as in step 4

PATCH the client with the earlier allowedResources and defaultAudience, and the realm with { "requireResource": false }.