Integrate two applications: one for the mobile application and the other for entity verification via Keycloak.

Hello,

We have a mobile application that authenticates users directly through Auth0, using Authorization Code Flow with PKCE.

Authentication works correctly.

However, our application needs to access a third-party DataHub API protected by Keycloak, with individual permissions for each user.

Our desired flow is:

Mobile App → Auth0 (authentication) → Keycloak (user authorization) → DataHub API

We want to keep Auth0 as the main authentication system without requiring users to log in again through Keycloak.

My questions are:

  1. Can Keycloak recognize or exchange an Auth0 token to issue its own access token?

  2. What needs to be configured in Auth0 (audience, application, scopes, etc.)?

  3. What information should we exchange with the Keycloak provider?

We would like to minimize changes to our existing Auth0 authentication flow.

Thank you for your help!

Hi @lmarzolf

Welcome to the Auth0 Community!

I understand you are looking for configuration advice when it comes to implementing the following flow where Auth0 is the main authentication system: Mobile App → Auth0 (authentication) → Keycloak (user authorization) → DataHub API.

Overview

Yes, this architecture is fully supported without requiring users to log in again. You can achieve this using Custom Token Exchange or JSON Web Tokens.

Auth0 remains your primary authentication authority, while Keycloak acts as an Identity Broker and authorization engine that validates the Auth0 token and mints its own token for the DataHub API.

Official Recommendations

1. Can Keycloak recognize or exchange an Auth0 token to issue its own access token?

Yes. Keycloak supports **External-to-Internal Token Exchange **:

  • How it operates: Keycloak registers Auth0 as an external OpenID Connect (OIDC) Identity Provider.

  • The Exchange: After your mobile app authenticates against Auth0, it (or your backend proxy) makes a non-interactive HTTP POST request directly to Keycloak’s token endpoint. Keycloak validates the Auth0 signature against Auth0’s JWKS endpoint, links or auto-provisions the user (Just-in-Time provisioning), and mints a local Keycloak access token populated with the user’s DataHub roles and permissions.

2. What needs to be configured in Auth0?

To keep changes to your current PKCE implementation to a minimum, configure the following in Auth0:

A. Register a Custom API (Audience)

  • Why: By default, Auth0 issues an opaque token for mobile logins unless an API audience is requested. Keycloak requires a cryptographically signed JWT.

  • Configuration: In Auth0 Dashboard > Applications > APIs, click Create API:

    • Identifier (Audience): Set a unique URI (e.g., https://datahub.keycloak.local or the Keycloak realm/client identifier);

    • Signing Algorithm: Ensure it is set to RS256 (asymmetric signing using tenant public keys).

B. Update Mobile App Authorization Request

  • Append the audience parameter to your existing PKCE /authorize call alongside standard scopes.

C. Add Custom Claims via Post-Login Action (If Needed)

  • If Keycloak or the DataHub API requires user attributes not included in standard OIDC claims (e.g., tenant IDs, organizational roles), attach them using an Auth0 Post-Login Action with namespaced custom claims:
exports.onExecutePostLogin = async (event, api) => {
  const namespace = 'https://datahub.keycloak.local/';
  if (event.authorization?.roles) {
    api.accessToken.setCustomClaim(`${namespace}roles`, event.authorization.roles);
  }
};

3. What information should be exchanged with the Keycloak provider?

Information You Must Provide to Keycloak (Auth0 ➔ Keycloak)

Keycloak requires these parameters to configure Auth0 as an trusted external Identity Provider (IdP) and verify incoming tokens:

  • OIDC Discovery URL: https://{your-tenant}.auth0.com/.well-known/openid-configuration

    • Purpose: Allows Keycloak to automatically discover Auth0’s configuration endpoints and protocol metadata.
  • JWKS URI: https://{your-tenant}.auth0.com/.well-known/jwks.json

    • Purpose: The public key set Keycloak calls to fetch the keys needed to verify the cryptographic signature of Auth0’s tokens.
  • Issuer URL (iss): https://{your-tenant}.auth0.com/

    • Purpose: Keycloak matches this value against the iss claim in the incoming JWT to ensure authenticity.
  • Audience (aud): Your configured Auth0 API Identifier (e.g., https://datahub.keycloak.local) or the Mobile Client ID (if you are exchanging an ID Token instead of an Access Token).

    • Purpose: Keycloak validates this to prevent token misuse.
  • Identity Mapping Claim: Typically set to sub (representing the unique Auth0 user ID auth0|...) or email.

    • Purpose: Instructs Keycloak which claim to map to Keycloak’s local username or primary key database.

Information You Must Receive from Keycloak (Keycloak ➔ Mobile App / Backend)

Your development team needs these variables to point the mobile application (or backend client proxy) to Keycloak’s token endpoint for exchange:

  • Keycloak Token Endpoint: https://{keycloak-host}/realms/{realm}/protocol/openid-connect/token

    • Purpose: The endpoint your application will call to submit the Auth0 token and receive the Keycloak token.
  • Identity Provider (IdP) Alias: The unique identifier assigned to Auth0 when registered inside the Keycloak admin panel.

    • Purpose: Sent in the subject_issuer parameter of the Token Exchange request.
  • Keycloak Client ID: The Client ID created within Keycloak that represents your application context.

    • Purpose: Identifies which client is executing the exchange request.
  • Target Scope / Audience: The specific scopes or target Client ID needed for the DataHub API.

    • Purpose: Ensures Keycloak scopes the minted access token with the appropriate roles and resources.

We hope the above information helped implement your desired flow!

Have a great one,
Gerald