Native Android PKCE returns wrong access-token audience despite explicit audience and active user-delegated grant

Hello Auth0 Community,

I’m investigating unexpected access token audience behavior in a native Android application using Auth0 Authorization Code Flow with PKCE (S256).

The application needs separate access tokens for two custom APIs.

For illustration, their identifiers are:

  • API A: https://api.example.com

  • API B: https://consumer-api.example.com

All identifiers above are placeholders.

Configuration

  • Application type: Native, first-party

  • Both APIs are registered as Resource Servers

  • Signing algorithm: RS256

  • API Access Policy: Per-app authorization

  • The Native application has an active user-delegated access entry for API B

  • API B defines no custom permissions; the dashboard displays 0/0 permissions granted

  • No custom Post Login Actions or claim mappings

  • Tenant Default Audience is empty

  • Callback URLs and identity-provider connections are configured

Observed behavior

The application explicitly requests API B using the audience parameter in /authorize, together with the correct client ID, redirect URI, scopes, state, nonce, and PKCE challenge.

The authorization completes successfully and the code is exchanged at /oauth/token.

However, the returned access token does not contain API B’s audience.

The JWT signature, issuer, subject, and expiration were successfully checked. The application rejects the token because the audience does not match the requested API.

The same behavior was reproduced after rebuilding the application and repeating the authorization.

Questions

  1. Under Per-app authorization, is an active user-delegated client grant with zero custom API permissions sufficient to obtain an access token for that API?

  2. Is there an additional API Access Policy or Native application setting required for Auth0 to honor the requested audience?

  3. If Authorization Code + PKCE completes successfully but the access token has a different audience, what is the recommended way to diagnose whether the result is caused by the grant policy, an OAuth request parameter, or token issuance behavior?

  4. Should the audience be specified only in /authorize, or can including it again in /oauth/token affect the resulting access token?

We want to preserve least-privilege access and avoid adding unnecessary scopes, enabling unrestricted access, or changing the tenant-wide Default Audience.

Any guidance on the relevant configuration or a reliable diagnostic procedure would be appreciated.

Thank you!

Hi @cattleweight-auth

Welcome to the Auth0 Community!

You are asking why an Authorization Code Flow with PKCE request from a native Android application returns an access token whose audience does not match API B, even though the audience parameter is sent to /authorize, and whether the Per-app authorization grant, an API Access Policy setting, or the /oauth/token request is responsible.

1. Under Per-app authorization, is an active user-delegated client grant with zero custom API permissions sufficient to obtain an access token for that API?

No. Under Auth0’s Per-app authorization policy, an active client grant with zero permissions (scope: []) and allow_all_scopes: false (the default dashboard behavior when 0 permissions are selected) is treated by the token issuance engine as having no authorized access to that Resource Server.

  • When an application requests an audience for which it has no authorized scopes under Per-app authorization, Auth0 drops or ignores the requested audience rather than failing the authentication request.

  • It falls back to issuing a baseline access token for the /userinfo endpoint (typically an opaque token, or a JWT with aud: "https://<your-tenant>.auth0.com/userinfo").

  • Least-Privilege Fix: You do not have to switch to unrestricted access or change the tenant default audience. You have two supported options:

    1. Enable allow_all_scopes on the Client Grant: Via the Management API, update the client grant linking the Native App to API B:
     PATCH /api/v2/client-grants/{client_grant_id}
     Content-Type: application/json

     {
       "allow_all_scopes": true
     }

This authorizes the app to receive access tokens for that audience even if the API defines no custom permissions.

  1. Define a baseline/default scope: Add at least one permission on API B (e.g., read:profile or a base API access scope) and grant that permission to the Native Application in the dashboard.

2. Is there an additional API Access Policy or Native application setting required for Auth0 to honor the requested audience?

No additional global or Native application settings are required.

Auth0 will honor the requested audience in Authorization Code + PKCE provided that:

  1. The Client Grant exists and permits access: It links client_id (Native app) and audience (API B) and has either allow_all_scopes: true or at least one granted scope.

  2. String exactness: The audience parameter sent in /authorize matches the API Identifier registered in Applications > APIs character-for-character (case sensitivity, protocol https://, and any trailing slashes).


3. Recommended diagnostic steps

To isolate whether the issue stems from grant policy, request parameters, or token issuance:

  1. Inspect the Client Grant record via Management API:
    Call the Management API to inspect the grant object directly:

    GET /api/v2/client-grants?client_id={NATIVE_CLIENT_ID}&audience=https%3A%2F%2Fconsumer-api.example.com

    Verify:

    • Does a grant exist for this specific client_id and audience?

    • What are the values of "scope" and "allow_all_scopes"? (If "scope": [] and "allow_all_scopes": false, this confirms the grant is not authorizing the audience).

  2. Inspect the returned Access Token’s aud claim:

    • If the token is a JWT, decode the payload without verification and inspect the "aud" field.

    • If "aud" points to https://<tenant>.auth0.com/userinfo (or if an opaque token was returned), Auth0 rejected the custom audience and fell back to the userinfo audience.

  3. Inspect Auth0 Tenant Logs (Monitoring > Logs):

    • Filter for the Successful Login (s) and Success Exchange (seacft) log events for your client ID.

    • Expand the event details and check the details.request and details.response sections:

      • Check details.request.query.audience on the s event to verify the exact string Auth0 received.

      • Check whether any warning flags or fallback notices were logged.


4. Should audience be specified only in /authorize, or can including it again in /oauth/token affect the resulting access token?

  • audience must be specified in /authorize.

  • Including it in /oauth/token has no effect.

In the OAuth 2.0 Authorization Code Flow with PKCE, the authorization code (code) is an opaque, short-lived reference bound on the server side to all parameters negotiated during /authorize (including client_id, redirect_uri, user identity, authorized scopes, and the target audience).

When your application posts to /oauth/token with grant_type=authorization_code, Auth0 issues tokens based strictly on the parameters bound to the code. Repeating or adding audience to the /oauth/token POST body is ignored and cannot alter or override the audience assigned to the grant.

Kind Regards,
Nik