-
Notifications
You must be signed in to change notification settings - Fork 254
feat: Add automatic retry mechanism for credential renewal to improve the reliability in unstable network conditions #1063
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
| self.storeKey = storeKey | ||
| self.authentication = authentication | ||
| self.sendableStorage = SendableBox(value: storage) | ||
| self.maxRetries = max(0, maxRetries) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i havent added automatic retry at network request level because that would be ebhavioral changes . so currently only looking to address the github issue where credential renwewal can fail in mobile patch network scenario.
currently there is dpop hanlding for retry but its a bit coupled. Will plan in major release to move retry at network level and make it more reusable across SDK . this would need more changes.
There was a problem hiding this 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 PR introduces an automatic retry mechanism for credential renewal operations to improve reliability when facing transient network failures, particularly important for mobile applications operating on unstable networks.
Key Changes
- Adds configurable retry support with exponential backoff for credential renewal failures
- Implements
isRetryableproperty onAuth0APIErrorto identify transient errors (network issues, rate limiting, server errors) - Includes comprehensive test coverage for various retry scenarios including success, exhaustion, and non-retryable errors
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| EXAMPLES.md | Adds comprehensive documentation explaining the retry mechanism, configuration, and Auth0 tenant setup requirements |
| Auth0Tests/Responses.swift | Adds test helper functions for simulating network errors, rate limiting, and server errors |
| Auth0Tests/CredentialsManagerSpec.swift | Adds extensive test suite covering retry scenarios, exponential backoff, and compatibility with async/await and Combine |
| Auth0/CredentialsManager.swift | Implements retry logic with exponential backoff in credential renewal flow, adds maxRetries parameter |
| Auth0/Auth0APIError.swift | Adds isRetryable property to identify transient errors suitable for retry |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
EXAMPLES.md
Outdated
| 1. Request A calls `credentials()` 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. Later, request B retries with the same (old) refresh token |
Copilot
AI
Jan 7, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The wording in step 4 could be misleading. It says "Later, request B retries with the same (old) refresh token" which suggests a different, separate request happens later. However, the retry mechanism implemented automatically retries the SAME request. Consider rephrasing to clarify this is an automatic retry of the failed request, not a separate subsequent request. For example: "The retry mechanism automatically retries the request with the same (old) refresh token".
| 4. Later, request B retries with the same (old) refresh token | |
| 4. The retry mechanism automatically retries the failed request using the same (old) refresh token |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
Auth0/CredentialsManager.swift
Outdated
| callback: callback) | ||
| } | ||
| } else { | ||
| complete() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lets call complete() as soon as failure block is recieved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
| forceRenewal: Bool, | ||
| retryCount: Int, | ||
| callback: @escaping (CredentialsManagerResult<Credentials>) -> Void) { | ||
| SynchronizationBarrier.shared.execute { complete in |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[weak self]
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Credential Manager is a struct
📋 Changes
Summary
This change addresses *auth0/react-native-auth0#1374 by improving the reliability of token renewal in unstable network conditions.
Background / Problem
A scenario highlighted by the community:
getCredentials()and initiates a token refresh.On mobile networks, which are often unreliable, this scenario is realistic. In such cases, even if the user retries later on a stable network, the refresh attempt may fail because the refresh token could already be expired by that time.
Proposed Solution
This PR introduces retry support for transient failures to better leverage Auth0’s refresh token rotation overlap period, allowing safe retries when the server-side renewal succeeds but the response never reaches the client.
Changes Included
Implement exponential backoff retry logic for transient errors in
CredentialsManagerAdd a configurable
maxRetriesparameter (default:0, disabled)Introduce
Auth0APIError.isRetryableutility for SDK-wide retry detectionAdd comprehensive documentation to
EXAMPLES.md, covering:429), and server errors (5xx)Outcome
The retry mechanism improves resilience in real-world mobile conditions by safely retrying renewal requests within the refresh token overlap window, reducing unnecessary authentication failures without changing default behavior.
📎 References
🎯 Testing