From 53740e87ce02770dbe736a1296b3dccf17f58026 Mon Sep 17 00:00:00 2001 From: Subhankar Maiti Date: Tue, 13 Jan 2026 10:48:53 +0530 Subject: [PATCH 1/8] feat: implement Custom Token Exchange (RFC 8693) functionality --- EXAMPLES.md | 95 +++++++++++++++++++ .../java/com/auth0/react/A0Auth0Module.kt | 34 +++++++ .../oldarch/com/auth0/react/A0Auth0Spec.kt | 11 +++ ios/A0Auth0.mm | 10 ++ ios/NativeBridge.swift | 24 +++++ src/Auth0.ts | 31 +++++- src/core/interfaces/IAuth0Client.ts | 18 +++- src/hooks/Auth0Context.ts | 25 +++++ src/hooks/Auth0Provider.tsx | 9 ++ .../native/adapters/NativeAuth0Client.ts | 43 +++++++-- src/platforms/native/bridge/INativeBridge.ts | 19 ++++ .../native/bridge/NativeBridgeManager.ts | 18 ++++ src/platforms/web/adapters/WebAuth0Client.ts | 48 +++++++++- src/specs/NativeA0Auth0.ts | 12 +++ src/types/parameters.ts | 49 ++++++++++ 15 files changed, 435 insertions(+), 11 deletions(-) diff --git a/EXAMPLES.md b/EXAMPLES.md index 62a11e86..d663f413 100644 --- a/EXAMPLES.md +++ b/EXAMPLES.md @@ -37,6 +37,11 @@ - [Using MRRT with Hooks](#using-mrrt-with-hooks) - [Using MRRT with Auth0 Class](#using-mrrt-with-auth0-class) - [Web Platform Configuration](#web-platform-configuration) +- [Custom Token Exchange (RFC 8693)](#custom-token-exchange-rfc-8693) + - [Using Custom Token Exchange with Hooks](#using-custom-token-exchange-with-hooks) + - [Using Custom Token Exchange with Auth0 Class](#using-custom-token-exchange-with-auth0-class) + - [With Organization Context](#with-organization-context) + - [Subject Token Type Requirements](#subject-token-type-requirements) - [Native to Web SSO (Early Access)](#native-to-web-sso-early-access) - [Overview](#native-to-web-sso-overview) - [Prerequisites](#native-to-web-sso-prerequisites) @@ -563,6 +568,96 @@ function App() { } ``` +## Custom Token Exchange (RFC 8693) + +Custom Token Exchange allows you to exchange external identity provider tokens for Auth0 tokens using the [RFC 8693 OAuth 2.0 Token Exchange](https://www.rfc-editor.org/rfc/rfc8693) specification. This enables scenarios where users authenticate with an external system and that token needs to be exchanged for Auth0 tokens. + +> ⚠️ **Important**: The external token must be validated in Auth0 Actions using cryptographic verification. See the [Auth0 Custom Token Exchange documentation](https://auth0.com/docs/authenticate/login/custom-token-exchange) for setup instructions. + +### Using Custom Token Exchange with Hooks + +```typescript +import React from 'react'; +import { Button, Alert } from 'react-native'; +import { useAuth0 } from 'react-native-auth0'; + +function TokenExchangeScreen() { + const { customTokenExchange, user, error } = useAuth0(); + + const handleExchange = async () => { + try { + // Exchange an external token for Auth0 tokens + const credentials = await customTokenExchange({ + subjectToken: 'token-from-external-provider', + subjectTokenType: 'urn:acme:legacy-system-token', + scope: 'openid profile email', + audience: 'https://api.example.com', + }); + + Alert.alert('Success', `Logged in as ${user?.name}`); + } catch (e) { + console.error('Token exchange failed:', e); + } + }; + + return