Skip to content

Commit 9eafe64

Browse files
committed
Extract flag check to common function
1 parent 08fe9c8 commit 9eafe64

File tree

1 file changed

+25
-28
lines changed

1 file changed

+25
-28
lines changed

IdentityCore/src/oauth2/aad_base/MSIDAADWebviewFactory.m

Lines changed: 25 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,29 @@
4949

5050
@implementation MSIDAADWebviewFactory
5151

52+
#pragma mark - Private Methods
53+
54+
- (BOOL)isDUNASupportedForTenantId:(NSString *)tenantId
55+
{
56+
BOOL allowDUNAByTenant = NO;
57+
BOOL allowDUNAGlobal = NO;
58+
MSIDFlightManager* flightManager;
59+
60+
if (![NSString msidIsStringNilOrBlank:tenantId])
61+
{
62+
flightManager = [MSIDFlightManager sharedInstanceByQueryKey:tenantId keyType:MSIDFlightManagerQueryKeyTypeTenantId];
63+
}
64+
if (flightManager)
65+
{
66+
allowDUNAByTenant = [flightManager boolForKey:MSID_FLIGHT_SUPPORT_DUNA_CBA];
67+
}
68+
allowDUNAGlobal = [[MSIDFlightManager sharedInstance] boolForKey:MSID_FLIGHT_SUPPORT_DUNA_CBA];
69+
70+
return allowDUNAGlobal || allowDUNAByTenant;
71+
}
72+
73+
#pragma mark - Public Methods
74+
5275
- (NSMutableDictionary<NSString *, NSString *> *)authorizationParametersFromRequestParameters:(MSIDInteractiveTokenRequestParameters *)parameters
5376
pkce:(MSIDPkce *)pkce
5477
requestState:(NSString *)state
@@ -86,22 +109,9 @@ @implementation MSIDAADWebviewFactory
86109
[result addEntriesFromDictionary:MSIDDeviceId.deviceId];
87110

88111
NSString* tenantId = parameters.accountIdentifier.utid;
89-
BOOL allowDUNAByTenant = NO;
90-
BOOL allowDUNAGlobal = NO;
91-
MSIDFlightManager* flightManager;
92-
93-
if (![NSString msidIsStringNilOrBlank:tenantId])
94-
{
95-
flightManager = [MSIDFlightManager sharedInstanceByQueryKey:tenantId keyType:MSIDFlightManagerQueryKeyTypeTenantId];
96-
}
97-
if (flightManager)
98-
{
99-
allowDUNAByTenant = [flightManager boolForKey:MSID_FLIGHT_SUPPORT_DUNA_CBA];
100-
}
101-
allowDUNAGlobal = [[MSIDFlightManager sharedInstance] boolForKey:MSID_FLIGHT_SUPPORT_DUNA_CBA];
102112

103113
#if TARGET_OS_IPHONE
104-
if (allowDUNAGlobal || allowDUNAByTenant)
114+
if ([self isDUNASupportedForTenantId:tenantId])
105115
{
106116
// Let server know that we support new cba flow
107117
result[MSID_BROWSER_RESPONSE_SWITCH_BROWSER] = @"1";
@@ -219,21 +229,8 @@ - (MSIDWebviewResponse *)oAuthResponseWithURL:(NSURL *)url
219229
if (browserResponse) return browserResponse;
220230

221231
NSString* tenantId = wpjResponse.clientInfo.utid;
222-
BOOL allowDUNAByTenant = NO;
223-
BOOL allowDUNAGlobal = NO;
224-
MSIDFlightManager* flightManager;
225-
226-
if (![NSString msidIsStringNilOrBlank:tenantId])
227-
{
228-
flightManager = [MSIDFlightManager sharedInstanceByQueryKey:tenantId keyType:MSIDFlightManagerQueryKeyTypeTenantId];
229-
}
230-
if (flightManager)
231-
{
232-
allowDUNAByTenant = [flightManager boolForKey:MSID_FLIGHT_SUPPORT_DUNA_CBA];
233-
}
234-
allowDUNAGlobal = [[MSIDFlightManager sharedInstance] boolForKey:MSID_FLIGHT_SUPPORT_DUNA_CBA];
235232

236-
if (allowDUNAGlobal || allowDUNAByTenant)
233+
if ([self isDUNASupportedForTenantId:tenantId])
237234
{
238235
MSIDSwitchBrowserResponse *switchBrowserResponse = [[MSIDSwitchBrowserResponse alloc] initWithURL:url
239236
redirectUri:endRedirectUri

0 commit comments

Comments
 (0)