Skip to content

Commit

Permalink
adding network error check before fallback
Browse files Browse the repository at this point in the history
  • Loading branch information
fidelianawar committed Oct 3, 2024
1 parent 5a86414 commit f526a38
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
12 changes: 9 additions & 3 deletions IdentityCore/src/controllers/MSIDSilentController.m
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#import "MSIDTelemetryEventStrings.h"
#import "MSIDTokenResult.h"
#import "MSIDAccount.h"
#import "MSIDAADRequestErrorHandler.h"
#if TARGET_OS_IPHONE
#import "MSIDBackgroundTaskManager.h"
#endif
Expand Down Expand Up @@ -88,7 +89,7 @@ - (void)acquireToken:(nonnull MSIDRequestCompletionBlock)completionBlock
MSIDRequestCompletionBlock completionBlockWrapper = ^(MSIDTokenResult * _Nullable result, NSError * _Nullable error)
{
#if TARGET_OS_IPHONE
[[MSIDBackgroundTaskManager sharedInstance] stopOperationWithType:MSIDBackgroundTaskTypeSilentRequest];
[[MSIDBackgroundTaskManager sharedInstance] stopOperationWithType:MSIDBackgroundTaskTypeSilentRequest];
#endif
MSID_LOG_WITH_CTX(MSIDLogLevelInfo, self.requestParameters, @"Silent flow finished. Result %@, error: %ld error domain: %@", _PII_NULLIFY(result), (long)error.code, error.domain);
completionBlock(result, error);
Expand All @@ -114,7 +115,12 @@ - (void)acquireTokenWithRequest:(MSIDSilentTokenRequest *)request
CONDITIONAL_START_EVENT(CONDITIONAL_SHARED_INSTANCE, self.requestParameters.telemetryRequestId, MSID_TELEMETRY_EVENT_API_EVENT);
self.currentRequest = request;
[request executeRequestWithCompletion:^(MSIDTokenResult *result, NSError *error)
{
{
MSIDAADRequestErrorHandler *handler = [[MSIDAADRequestErrorHandler alloc] init];
if (error && [handler shouldRetryNetworkingFailure:error.code]) {
completionBlock(result, error);
}

if (result || !self.fallbackController)
{
#if !EXCLUDE_FROM_MSALCPP
Expand All @@ -123,7 +129,7 @@ - (void)acquireTokenWithRequest:(MSIDSilentTokenRequest *)request
[telemetryEvent setIsExtendedLifeTimeToken:result.extendedLifeTimeToken ? MSID_TELEMETRY_VALUE_YES : MSID_TELEMETRY_VALUE_NO];
if (self.isLocalFallbackMode)
{
[telemetryEvent setSsoExtFallBackFlow:1];
[telemetryEvent setSsoExtFallBackFlow:1];
}

[self stopTelemetryEvent:telemetryEvent error:error];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,6 @@

@interface MSIDAADRequestErrorHandler : NSObject <MSIDHttpRequestErrorHandling>

- (BOOL)shouldRetryNetworkingFailure:(NSInteger)errorCode;

@end

0 comments on commit f526a38

Please sign in to comment.