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).RealmViewercan 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.
Set it up
Section titled “Set it up”-
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
httpsURL with no fragment.defaultAudiencemust be one ofallowedResources; without it, a request naming no API is refused. -
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 }' -
Have the client name the API in each token request:
resource=https://billing.example.com/api. -
Have each API check that
audholds its own address, or ask the realm, as in Check a token at your API.
Check it worked
Section titled “Check it worked”- 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_ISSUEDrecord shows the APIs asked for and the audience granted. Find it in Audit → Authentication in the dashboard.
Troubleshooting
Section titled “Troubleshooting”| Symptom | Cause | Fix |
|---|---|---|
invalid_target | The API named isn’t on the client’s list, or none was named with requireResource on and no defaultAudience | Add it to allowedResources, or set defaultAudience |
| Saving the client is refused | defaultAudience isn’t one of allowedResources, or an address isn’t an absolute https URL | Fix the list |
| An API accepts tokens meant for another | It doesn’t check aud | Have it check aud, as in step 4 |
Undo it
Section titled “Undo it”PATCH the client with the earlier allowedResources and defaultAudience, and the realm with
{ "requireResource": false }.
Related
Section titled “Related”- Resource indicators: the standard in full.
- Refresh tokens: what a refresh may ask for.
- Token swap: a gateway that swaps a token for each API behind it.