liveBook · Manning

Audience parameter

As explained in Secure APIs

An audience parameter identifies the protected API or resource server for which an authorization request or token is intended.

An audience parameter identifies the API or resource server that an authorization request and resulting access token are intended to serve. When an identity provider exposes multiple APIs, the client includes the target API as the audience, preventing the login flow from leaving the destination ambiguous. section 8.4.1

For an admin workflow, request the admin API by setting the audience in the login redirect, then validate that same expected audience when accepting the bearer token. Audience validation works with permission checks: the admin endpoint requires both the correct audience and an admin permission. section 8.6

Requesting an admin API token

A login route redirects to the authorization endpoint with parameters such as response_type=code, client_id, redirect_uri, and audience=<audience>. After authentication, the returned authorization code is exchanged for an access token. The /admin/hello endpoint calls validate_token with the expected audience before checking whether the token permissions include admin.

How Secure APIs covers it

How deep it goes
Defines the parameter and demonstrates setting and validating it, but does not elaborate its provider-level internals.
Examples
Uses Auth0 authorization URLs, admin login routes, authorization-code exchanges, and an admin endpoint requiring audience and permission checks.
What it assumes
Assumes basic client authentication and authorization-flow concepts while showing the authorization-code exchange and bearer-token validation.
What you can do after
Apply it via Auth0 and FastAPI by requesting an API audience and validating it before serving protected endpoints.
How it connects
Connects authorization requests, access tokens, OAuth, OpenID Connect, client IDs, redirect URIs, and role-based access control.

This explainer was generated by Manning's knowledge graph from the text of Secure APIs. The section links point to the parts of the book it draws on.