Skip to content

Conversation

@subhankarmaiti
Copy link
Contributor

@subhankarmaiti subhankarmaiti commented Jan 13, 2026

Adds support for Custom Token Exchange using RFC 8693, enabling users to exchange external identity provider tokens for Auth0 tokens.

What's New

  • customTokenExchange() method on Auth0 class and useAuth0() hook
  • 📱 Full native (iOS/Android) and web platform support

Usage

Basic Example

import Auth0 from 'react-native-auth0';

const auth0 = new Auth0({
  domain: 'YOUR_DOMAIN',
  clientId: 'YOUR_CLIENT_ID',
});

try {
  const credentials = await auth0.customTokenExchange({
    subjectToken: 'external-token',
    subjectTokenType: 'urn:acme:legacy-token',
    audience: 'https://api.example.com',
    scope: 'openid profile email',
  });
  
  console.log('Access Token:', credentials.accessToken);
} catch (error) {
  console.error('Token exchange failed:', error.code, error.message);
}

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This pull request adds Custom Token Exchange support using RFC 8693, enabling users to exchange external identity provider tokens for Auth0 tokens. The implementation provides full native (iOS/Android) and web platform support.

Changes:

  • Added customTokenExchange() method to Auth0 class and useAuth0() hook
  • Implemented CustomTokenExchangeError class with platform-agnostic error codes for unified error handling
  • Added complete native bridge support for iOS (Swift) and Android (Kotlin) implementations

Reviewed changes

Copilot reviewed 23 out of 23 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
src/types/parameters.ts Defines CustomTokenExchangeParameters interface with comprehensive documentation
src/specs/NativeA0Auth0.ts Adds native module spec for customTokenExchange method
src/platforms/web/adapters/WebAuth0Client.ts Implements web platform token exchange using auth0-spa-js
src/platforms/native/bridge/NativeBridgeManager.ts Adds native bridge implementation with proper error wrapping
src/platforms/native/adapters/NativeAuth0Client.ts Integrates customTokenExchange with guarded bridge pattern
src/core/models/CustomTokenExchangeError.ts Implements comprehensive error class with multi-platform error code mapping
src/hooks/Auth0Provider.tsx Integrates customTokenExchange into React context and hooks
src/hooks/Auth0Context.ts Adds interface definition for the new method
src/Auth0.ts Exposes customTokenExchange on main Auth0 class
src/index.ts Exports CustomTokenExchangeError and error codes
ios/NativeBridge.swift Implements iOS native token exchange
ios/A0Auth0.mm Adds React Native bridge method for iOS
android/src/main/oldarch/com/auth0/react/A0Auth0Spec.kt Adds Android spec method
android/src/main/java/com/auth0/react/A0Auth0Module.kt Implements Android native token exchange
EXAMPLES.md Provides comprehensive usage examples and error handling guide
Test files Comprehensive test coverage for all implementations

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

pmathew92
pmathew92 previously approved these changes Jan 21, 2026
@subhankarmaiti subhankarmaiti merged commit eca5a32 into master Jan 21, 2026
3 checks passed
@subhankarmaiti subhankarmaiti deleted the feat/custom-token-exchange branch January 21, 2026 10:24
@subhankarmaiti subhankarmaiti mentioned this pull request Jan 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants