-
Notifications
You must be signed in to change notification settings - Fork 83
SDK-199 Auth Retry policy completely bypassed #987
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -67,8 +67,16 @@ class AuthManager: IterableAuthManagerProtocol { | |
| } | ||
|
|
||
| private func shouldPauseRetry(_ shouldIgnoreRetryPolicy: Bool) -> Bool { | ||
| return (!shouldIgnoreRetryPolicy && pauseAuthRetry) || | ||
| (retryCount >= authRetryPolicy.maxRetry && !shouldIgnoreRetryPolicy) | ||
| if pauseAuthRetry { | ||
| return true | ||
| } | ||
|
|
||
| // Scheduled refresh should never bypass retry safety limits. | ||
| if isInScheduledRefreshCallback { | ||
| return retryCount >= authRetryPolicy.maxRetry | ||
| } | ||
|
|
||
| return retryCount >= authRetryPolicy.maxRetry && !shouldIgnoreRetryPolicy | ||
| } | ||
|
|
||
| private func shouldUseLastValidToken(_ shouldIgnoreRetryPolicy: Bool) -> Bool { | ||
|
|
@@ -113,6 +121,7 @@ class AuthManager: IterableAuthManagerProtocol { | |
| private var isLastAuthTokenValid: Bool = false | ||
| private var pauseAuthRetry: Bool = false | ||
| private var isTimerScheduled: Bool = false | ||
| private var isInScheduledRefreshCallback: Bool = false | ||
|
|
||
| private var pendingSuccessCallbacks: [AuthTokenRetrievalHandler] = [] | ||
| private let callbackQueue = DispatchQueue(label: "com.iterable.authCallbackQueue") | ||
|
|
@@ -205,6 +214,7 @@ class AuthManager: IterableAuthManagerProtocol { | |
| let timeIntervalToRefresh = TimeInterval(expirationDate) - dateProvider.currentDate.timeIntervalSince1970 - expirationRefreshPeriod | ||
| if timeIntervalToRefresh > 0 { | ||
| scheduleAuthTokenRefreshTimer(interval: timeIntervalToRefresh, isScheduledRefresh: true, successCallback: onSuccess) | ||
| resetRetryCount() | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Schedule wont necessarily guarantees successful retrieval of token. Should we reset the count here?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. My understanding is that since the schedule is fired, we can reset the retries. regardless of its success. |
||
| return true // Only return true when we successfully queue a refresh | ||
| } | ||
| return false | ||
|
|
@@ -228,14 +238,17 @@ class AuthManager: IterableAuthManagerProtocol { | |
| addPendingCallback(successCallback) | ||
|
|
||
| expirationRefreshTimer = Timer.scheduledTimer(withTimeInterval: interval, repeats: false) { [weak self] _ in | ||
| self?.isTimerScheduled = false | ||
| if self?.localStorage.email != nil || self?.localStorage.userId != nil { | ||
| self?.requestNewAuthToken(hasFailedPriorAuth: false, onSuccess: { [weak self] token in | ||
| guard let self else { return } | ||
| self.isTimerScheduled = false | ||
| if self.localStorage.email != nil || self.localStorage.userId != nil { | ||
| self.isInScheduledRefreshCallback = isScheduledRefresh | ||
| self.requestNewAuthToken(hasFailedPriorAuth: false, onSuccess: { [weak self] token in | ||
| self?.invokePendingCallbacks(with: token) | ||
| }, shouldIgnoreRetryPolicy: isScheduledRefresh) | ||
| self.isInScheduledRefreshCallback = false | ||
| } else { | ||
| ITBDebug("Email or userId is not available. Skipping token refresh") | ||
| self?.clearPendingCallbacks() | ||
| self.clearPendingCallbacks() | ||
| } | ||
| } | ||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.