From f9784609866507e77b70bf840f9394d3b33a089d Mon Sep 17 00:00:00 2001 From: Subhankar Maiti Date: Mon, 12 Jan 2026 10:29:58 +0530 Subject: [PATCH 1/3] feat: add maxRetries parameter for getCredentials method --- A0Auth0.podspec | 2 +- EXAMPLES.md | 189 ++++++++++++++++++ .../java/com/auth0/react/A0Auth0Module.kt | 5 + .../oldarch/com/auth0/react/A0Auth0Spec.kt | 1 + example/ios/Podfile.lock | 10 +- ios/A0Auth0.mm | 7 +- ios/NativeBridge.swift | 6 +- .../native/adapters/NativeAuth0Client.ts | 4 +- src/platforms/native/bridge/INativeBridge.ts | 5 +- .../native/bridge/NativeBridgeManager.ts | 6 +- src/specs/NativeA0Auth0.ts | 3 +- src/types/common.ts | 9 + 12 files changed, 231 insertions(+), 16 deletions(-) diff --git a/A0Auth0.podspec b/A0Auth0.podspec index bf37d2a3..d9571722 100644 --- a/A0Auth0.podspec +++ b/A0Auth0.podspec @@ -16,7 +16,7 @@ Pod::Spec.new do |s| s.source_files = 'ios/**/*.{h,m,mm,swift}' s.requires_arc = true - s.dependency 'Auth0', '2.16.1' + s.dependency 'Auth0', '2.16.2' install_modules_dependencies(s) end diff --git a/EXAMPLES.md b/EXAMPLES.md index 62a11e86..8437a581 100644 --- a/EXAMPLES.md +++ b/EXAMPLES.md @@ -13,6 +13,13 @@ - [Set global headers during initialization](#set-global-headers-during-initialization) - [Using custom headers with Auth0Provider component](#using-custom-headers-with-auth0provider-component) - [Set request-specific headers](#set-request-specific-headers) +- [Credential Renewal Retry](#credential-renewal-retry) + - [Overview](#credential-renewal-retry-overview) + - [Prerequisites](#credential-renewal-retry-prerequisites) + - [Using Retry with Hooks](#using-retry-with-hooks) + - [Using Retry with Auth0 Class](#using-retry-with-auth0-class) + - [Platform Support](#credential-renewal-retry-platform-support) + - [Error Handling](#credential-renewal-retry-error-handling) - [Biometric Authentication](#biometric-authentication) - [Biometric Policy Types](#biometric-policy-types) - [Using with Auth0Provider (Hooks)](#using-with-auth0provider-hooks) @@ -259,6 +266,188 @@ auth0.auth .catch(console.error); ``` +## Credential Renewal Retry + +> **Platform Support:** iOS only. + +Automatic retry mechanism for credential renewal to improve reliability in unstable network conditions, particularly important for mobile applications with refresh token rotation enabled. + + + +### Overview + +When your application operates on unstable mobile networks, credential renewal requests may fail due to transient network issues. This is especially problematic with refresh token rotation enabled, as a failed response can invalidate the refresh token even though the server successfully issued new credentials. + +The `maxRetries` configuration option enables automatic retry with exponential backoff for the following error scenarios: + +- **Network errors**: Connection timeouts, DNS failures, unreachable hosts +- **Rate limiting**: HTTP 429 (Too Many Requests) +- **Server errors**: HTTP 5xx responses + +**Example scenario this solves:** + +1. Request A calls `getCredentials()` and starts a token refresh +2. Request A successfully hits the server and gets new credentials +3. Request A fails on the way back (network issue), never reaching the client +4. The retry mechanism automatically retries the failed request using the same (old) refresh token +5. The retry succeeds within the refresh token rotation overlap window + + + +### Prerequisites + +To use the retry mechanism effectively: + +1. **SDK Version**: Requires react-native-auth0 v5.4.0 or later +2. **Refresh Token Rotation**: Should be enabled in your Auth0 tenant +3. **Token Overlap Period**: Configure refresh token rotation with an overlap period of at least **180 seconds** (3 minutes) in your Auth0 tenant settings +4. **Scope**: Ensure your authentication requests include the `offline_access` scope to receive refresh tokens + + + +### Using Retry with Hooks + +```jsx +import React from 'react'; +import { View, Button, Alert } from 'react-native'; +import { Auth0Provider, useAuth0 } from 'react-native-auth0'; + +function App() { + return ( + + + + ); +} + +function MyComponent() { + const { getCredentials } = useAuth0(); + + const fetchCredentialsWithRetry = async () => { + try { + // The retry mechanism is automatically applied to all credential renewal attempts + const credentials = await getCredentials(); + + console.log('Access Token:', credentials.accessToken); + // Use credentials for API calls... + } catch (error) { + console.error('Failed to get credentials after retries:', error); + Alert.alert( + 'Error', + 'Unable to refresh credentials. Please log in again.' + ); + } + }; + + return ( + +