You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: EXAMPLES.md
+39Lines changed: 39 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -484,6 +484,45 @@ credentialsManager
484
484
> [!CAUTION]
485
485
> To ensure that no concurrent renewal requests get made, do not call this method from multiple Credentials Manager instances. The Credentials Manager cannot synchronize requests across instances.
486
486
487
+
#### Automatic retry on transient errors
488
+
489
+
The Credentials Manager includes automatic retry logic for credential renewal when transient errors occur. This helps handle scenarios where network requests fail temporarily, such as:
490
+
491
+
- Network connectivity issues (timeouts, connection lost, DNS failures)
492
+
- Rate limiting responses (HTTP 429)
493
+
- Server errors (HTTP 5xx)
494
+
495
+
**How it works:**
496
+
497
+
When a renewal request fails due to a transient error, the Credentials Manager will automatically retry the request with exponential backoff (0.5s, 1s, 2s, 4s, etc.). This addresses the following scenario:
498
+
499
+
1. Request A calls `credentials()` and starts a token refresh
500
+
2. Request A successfully hits the server and gets new credentials
501
+
3. Request A fails on the way back (network issue), never reaching the client
502
+
4. Later, request B retries with the same (old) refresh token
503
+
504
+
To fully leverage the retry mechanism, ensure your Auth0 tenant's **Rotation Overlap Period** is set to at least 180 seconds. This overlap window ensures the old refresh token remains valid during retry attempts even if the backend resource was already updated. You can configure this setting in your Auth0 Dashboard under **Applications > [Your Application] > Settings > Refresh Token Rotation**.
505
+
506
+
**Configure retry behavior:**
507
+
508
+
By default, retries are disabled. You can enable retries by specifying a maximum retry count when creating the Credentials Manager. It is advisable to set a maximum of 2 retries, which provides sufficient resilience without introducing excessive delays or unnecessary network requests.
509
+
510
+
```swift
511
+
// Enable up to 2 retry attempts (recommended maximum)
512
+
let credentialsManager =CredentialsManager(
513
+
authentication: Auth0.authentication(),
514
+
maxRetries: 2
515
+
)
516
+
```
517
+
518
+
519
+
**Important considerations:**
520
+
521
+
- Retries only occur for transient errors (network issues, rate limiting, server errors)
522
+
- Permanent errors (invalid refresh token, authorization failures) will not be retried
523
+
- Each retry uses exponential backoff to avoid overwhelming the server
524
+
- The 180-second refresh token overlap window ensures retries can succeed even after a successful backend renewal
525
+
487
526
### Renew stored credentials
488
527
489
528
The `credentials()` method automatically renews the stored credentials when needed, using the [refresh token](https://auth0.com/docs/secure/tokens/refresh-tokens). However, you can also force a renewal using the `renew()` method. **This method is thread-safe**.
0 commit comments