Skip to content

Commit ba02efc

Browse files
committed
Added tenant based flighting
1 parent 053b90e commit ba02efc

File tree

7 files changed

+208
-2
lines changed

7 files changed

+208
-2
lines changed

IdentityCore/IdentityCore.xcodeproj/project.pbxproj

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -555,6 +555,10 @@
555555
2A59B4452D7A0CB500304FB1 /* MSIDXpcInteractiveTokenRequestController.m in Sources */ = {isa = PBXBuildFile; fileRef = 2A59B4422D7A0CB500304FB1 /* MSIDXpcInteractiveTokenRequestController.m */; };
556556
2AADDAC72DADB84D00CB7740 /* MSIDSSOXpcSilentTokenRequest.m in Sources */ = {isa = PBXBuildFile; fileRef = 2AADDAC62DADB84D00CB7740 /* MSIDSSOXpcSilentTokenRequest.m */; };
557557
2AADDAC82DADB84D00CB7740 /* MSIDSSOXpcSilentTokenRequest.h in Headers */ = {isa = PBXBuildFile; fileRef = 2AADDAC52DADB84D00CB7740 /* MSIDSSOXpcSilentTokenRequest.h */; };
558+
4B6D22262E831B0B00546EC8 /* MSIDFlightManagerQueryKeyDelegate.h in Headers */ = {isa = PBXBuildFile; fileRef = 4B6D22252E831AEA00546EC8 /* MSIDFlightManagerQueryKeyDelegate.h */; };
559+
4B6D222C2E8342C200546EC8 /* MSIDFlightManagerQueryKeyType.h in Headers */ = {isa = PBXBuildFile; fileRef = 4B6D222A2E8342C200546EC8 /* MSIDFlightManagerQueryKeyType.h */; };
560+
4B6D222D2E8342C200546EC8 /* MSIDFlightManagerQueryKeyType.m in Sources */ = {isa = PBXBuildFile; fileRef = 4B6D222B2E8342C200546EC8 /* MSIDFlightManagerQueryKeyType.m */; };
561+
4B6D222E2E8342C200546EC8 /* MSIDFlightManagerQueryKeyType.m in Sources */ = {isa = PBXBuildFile; fileRef = 4B6D222B2E8342C200546EC8 /* MSIDFlightManagerQueryKeyType.m */; };
558562
580E25402719FD10003D1795 /* MSIDPrtHeader.h in Headers */ = {isa = PBXBuildFile; fileRef = 580E253E2719FD10003D1795 /* MSIDPrtHeader.h */; };
559563
580E25412719FD10003D1795 /* MSIDPrtHeader.m in Sources */ = {isa = PBXBuildFile; fileRef = 580E253F2719FD10003D1795 /* MSIDPrtHeader.m */; };
560564
580E25422719FD10003D1795 /* MSIDPrtHeader.m in Sources */ = {isa = PBXBuildFile; fileRef = 580E253F2719FD10003D1795 /* MSIDPrtHeader.m */; };
@@ -2484,6 +2488,9 @@
24842488
2A59B4422D7A0CB500304FB1 /* MSIDXpcInteractiveTokenRequestController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MSIDXpcInteractiveTokenRequestController.m; sourceTree = "<group>"; };
24852489
2AADDAC52DADB84D00CB7740 /* MSIDSSOXpcSilentTokenRequest.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MSIDSSOXpcSilentTokenRequest.h; sourceTree = "<group>"; };
24862490
2AADDAC62DADB84D00CB7740 /* MSIDSSOXpcSilentTokenRequest.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MSIDSSOXpcSilentTokenRequest.m; sourceTree = "<group>"; };
2491+
4B6D22252E831AEA00546EC8 /* MSIDFlightManagerQueryKeyDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MSIDFlightManagerQueryKeyDelegate.h; sourceTree = "<group>"; };
2492+
4B6D222A2E8342C200546EC8 /* MSIDFlightManagerQueryKeyType.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MSIDFlightManagerQueryKeyType.h; sourceTree = "<group>"; };
2493+
4B6D222B2E8342C200546EC8 /* MSIDFlightManagerQueryKeyType.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MSIDFlightManagerQueryKeyType.m; sourceTree = "<group>"; };
24872494
51E364572863C0F300A97F82 /* MSIDTelemetryConditionalCompile.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MSIDTelemetryConditionalCompile.h; sourceTree = "<group>"; };
24882495
580E253E2719FD10003D1795 /* MSIDPrtHeader.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MSIDPrtHeader.h; sourceTree = "<group>"; };
24892496
580E253F2719FD10003D1795 /* MSIDPrtHeader.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MSIDPrtHeader.m; sourceTree = "<group>"; };
@@ -5708,6 +5715,9 @@
57085715
728209CB26FE951900B5F018 /* MSIDJwtAlgorithm.h */,
57095716
237F8F2C2D5166FE0095F164 /* MSIDFlightManager.h */,
57105717
237F8F2D2D5166FE0095F164 /* MSIDFlightManager.m */,
5718+
4B6D222A2E8342C200546EC8 /* MSIDFlightManagerQueryKeyType.h */,
5719+
4B6D222B2E8342C200546EC8 /* MSIDFlightManagerQueryKeyType.m */,
5720+
4B6D22252E831AEA00546EC8 /* MSIDFlightManagerQueryKeyDelegate.h */,
57115721
B48FC02E2D726A48007B80DB /* MSIDBrokerFlightProvider.h */,
57125722
B48FC0302D726A64007B80DB /* MSIDBrokerFlightProvider.m */,
57135723
);
@@ -6298,6 +6308,7 @@
62986308
B2E2A923239221A000BA2EA3 /* MSIDBrokerOperationSignoutFromDeviceRequest.h in Headers */,
62996309
B2C708B3219A620B00D917B8 /* MSIDBrokerKeyProvider.h in Headers */,
63006310
23B39ABC209BD47D000AA905 /* MSIDB2CAuthorityResolver.h in Headers */,
6311+
4B6D22262E831B0B00546EC8 /* MSIDFlightManagerQueryKeyDelegate.h in Headers */,
63016312
B443EFF62AD62BB900782168 /* MSIDPasskeyCredential.h in Headers */,
63026313
B286B99D2389DCA6007833AD /* MSIDSSOExtensionTokenRequestDelegate.h in Headers */,
63036314
B210F4551FDDFA7B005A8F76 /* MSIDBrokerResponse.h in Headers */,
@@ -6360,6 +6371,7 @@
63606371
74F04D4D246CB5B100094017 /* MSIDCurrentRequestTelemetrySerializedItem+Internal.h in Headers */,
63616372
238E19DD2086FE28004DF483 /* MSIDAADAuthorizationCodeRequest.h in Headers */,
63626373
B227037622A4C29800030ADC /* MSIDExtendedTokenCacheDataSource.h in Headers */,
6374+
4B6D222C2E8342C200546EC8 /* MSIDFlightManagerQueryKeyType.h in Headers */,
63636375
B251CC49204105A7005E0179 /* MSIDIdToken.h in Headers */,
63646376
B2F671EC2467AB4500649855 /* MSIDInteractiveRequestControlling.h in Headers */,
63656377
B443F0002AD6327700782168 /* MSIDBrokerOperationPasskeyCredentialRequest.h in Headers */,
@@ -7593,6 +7605,7 @@
75937605
96B8D57C20946D2600E3F4A6 /* MSIDPkce.m in Sources */,
75947606
2A59B42E2D776F3400304FB1 /* MSIDXpcConfiguration.m in Sources */,
75957607
6057EE9120B5FDF8007976EB /* MSIDAADOAuthEmbeddedWebviewController.m in Sources */,
7608+
4B6D222D2E8342C200546EC8 /* MSIDFlightManagerQueryKeyType.m in Sources */,
75967609
238E19DF2086FE28004DF483 /* MSIDTokenRequest.m in Sources */,
75977610
B2CDB5741FE2F4DF003A4B5C /* NSOrderedSet+MSIDExtensions.m in Sources */,
75987611
1E74094A24197E9200133EF7 /* NSDictionary+MSIDLogging.m in Sources */,
@@ -8043,6 +8056,7 @@
80438056
8878C62E29DCA0E2002F5F4B /* MSIDCIAMTokenResponse.m in Sources */,
80448057
1E00D282248F27ED006E4BAE /* MSIDAuthScheme.m in Sources */,
80458058
600D19AE20964CC00004CD43 /* MSIDRegistrationInformation.m in Sources */,
8059+
4B6D222E2E8342C200546EC8 /* MSIDFlightManagerQueryKeyType.m in Sources */,
80468060
B2C07482246B70F70008D701 /* MSIDAssymetricKeyPair.m in Sources */,
80478061
B227035F22A367A000030ADC /* MSIDMaskedHashableLogParameter.m in Sources */,
80488062
B2C7B3B4213C681F009FFCC1 /* MSIDErrorConverter.m in Sources */,

IdentityCore/src/MSIDFlightManager.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424

2525

2626
#import <Foundation/Foundation.h>
27+
#import "MSIDFlightManagerQueryKeyDelegate.h"
2728

2829
NS_ASSUME_NONNULL_BEGIN
2930

@@ -38,8 +39,11 @@ NS_ASSUME_NONNULL_BEGIN
3839
@interface MSIDFlightManager : NSObject <MSIDFlightManagerInterface>
3940

4041
@property (nonatomic, nullable) id<MSIDFlightManagerInterface> flightProvider;
42+
@property (nonatomic, nullable) id<MSIDFlightManagerQueryKeyDelegate> queryKeyFlightProvider;
4143

4244
+ (instancetype)sharedInstance;
45+
+ (instancetype)sharedInstanceByQueryKey:(NSString *)queryKey
46+
keyType:(MSIDFlightManagerQueryKeyType)keyType;
4347

4448
@end
4549

IdentityCore/src/MSIDFlightManager.m

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,56 @@ + (instancetype)sharedInstance
4545
return sharedInstance;
4646
}
4747

48+
+ (instancetype)sharedInstanceByQueryKey:(NSString *)queryKey
49+
keyType:(MSIDFlightManagerQueryKeyType)keyType
50+
{
51+
if ([NSString msidIsStringNilOrBlank:queryKey])
52+
{
53+
// Use shared flight manager if tenant id is nil or empty
54+
return [MSIDFlightManager sharedInstance];
55+
}
56+
57+
static NSMutableDictionary<NSString *, MSIDFlightManager *> *instancesByQueryKey = nil;
58+
static dispatch_once_t onceToken;
59+
static dispatch_queue_t synchronizationQueue;
60+
61+
dispatch_once(&onceToken, ^{
62+
instancesByQueryKey = [NSMutableDictionary new];
63+
synchronizationQueue = dispatch_queue_create("com.microsoft.msidflightmanager.querykey", DISPATCH_QUEUE_CONCURRENT);
64+
});
65+
66+
__block MSIDFlightManager *instance = nil;
67+
68+
// First, try to read the instance concurrently
69+
dispatch_sync(synchronizationQueue, ^{
70+
instance = instancesByQueryKey[queryKey];
71+
});
72+
73+
if (!instance)
74+
{
75+
// If not found, create and insert with a barrier write
76+
dispatch_barrier_sync(synchronizationQueue, ^{
77+
instance = instancesByQueryKey[queryKey];
78+
if (!instance)
79+
{
80+
instance = [[self.class alloc] initInternal];
81+
82+
id<MSIDFlightManagerInterface> flightProvider = [[MSIDFlightManager sharedInstance].queryKeyFlightProvider
83+
flightProviderForQueryKey:queryKey
84+
keyType:keyType];
85+
if (flightProvider)
86+
{
87+
instance.flightProvider = flightProvider;
88+
}
89+
90+
instancesByQueryKey[queryKey] = instance;
91+
}
92+
});
93+
}
94+
95+
return instance;
96+
}
97+
4898
- (instancetype)initInternal
4999
{
50100
self = [super init];
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
//
2+
// Copyright (c) Microsoft Corporation.
3+
// All rights reserved.
4+
//
5+
// This code is licensed under the MIT License.
6+
//
7+
// Permission is hereby granted, free of charge, to any person obtaining a copy
8+
// of this software and associated documentation files(the "Software"), to deal
9+
// in the Software without restriction, including without limitation the rights
10+
// to use, copy, modify, merge, publish, distribute, sublicense, and / or sell
11+
// copies of the Software, and to permit persons to whom the Software is
12+
// furnished to do so, subject to the following conditions :
13+
//
14+
// The above copyright notice and this permission notice shall be included in
15+
// all copies or substantial portions of the Software.
16+
//
17+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23+
// THE SOFTWARE.
24+
25+
#import <Foundation/Foundation.h>
26+
#import "MSIDFlightManagerQueryKeyType.h"
27+
28+
@protocol MSIDFlightManagerInterface;
29+
30+
@protocol MSIDFlightManagerQueryKeyDelegate <NSObject>
31+
32+
- (nullable id<MSIDFlightManagerInterface>)flightProviderForQueryKey:(nonnull NSString *)queryKey
33+
keyType:(nonnull MSIDFlightManagerQueryKeyType)keyType;
34+
35+
@end
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
//
2+
// Copyright (c) Microsoft Corporation.
3+
// All rights reserved.
4+
//
5+
// This code is licensed under the MIT License.
6+
//
7+
// Permission is hereby granted, free of charge, to any person obtaining a copy
8+
// of this software and associated documentation files(the "Software"), to deal
9+
// in the Software without restriction, including without limitation the rights
10+
// to use, copy, modify, merge, publish, distribute, sublicense, and / or sell
11+
// copies of the Software, and to permit persons to whom the Software is
12+
// furnished to do so, subject to the following conditions :
13+
//
14+
// The above copyright notice and this permission notice shall be included in
15+
// all copies or substantial portions of the Software.
16+
//
17+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23+
// THE SOFTWARE.
24+
25+
#import <Foundation/Foundation.h>
26+
27+
NS_ASSUME_NONNULL_BEGIN
28+
29+
typedef NSString * MSIDFlightManagerQueryKeyType NS_STRING_ENUM;
30+
31+
extern MSIDFlightManagerQueryKeyType const MSIDFlightManagerQueryKeyTypeTenantId;
32+
extern MSIDFlightManagerQueryKeyType const MSIDFlightManagerQueryKeyTypeAppBundleId;
33+
extern MSIDFlightManagerQueryKeyType const MSIDFlightManagerQueryKeyTypeEcsRegion;
34+
extern MSIDFlightManagerQueryKeyType const MSIDFlightManagerQueryKeyTypePlatform;
35+
extern MSIDFlightManagerQueryKeyType const MSIDFlightManagerQueryKeyTypeUpn;
36+
extern MSIDFlightManagerQueryKeyType const MSIDFlightManagerQueryKeyTypeUserId;
37+
extern MSIDFlightManagerQueryKeyType const MSIDFlightManagerQueryKeyTypeVersionNumber;
38+
39+
NS_ASSUME_NONNULL_END
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
//
2+
// Copyright (c) Microsoft Corporation.
3+
// All rights reserved.
4+
//
5+
// This code is licensed under the MIT License.
6+
//
7+
// Permission is hereby granted, free of charge, to any person obtaining a copy
8+
// of this software and associated documentation files(the "Software"), to deal
9+
// in the Software without restriction, including without limitation the rights
10+
// to use, copy, modify, merge, publish, distribute, sublicense, and / or sell
11+
// copies of the Software, and to permit persons to whom the Software is
12+
// furnished to do so, subject to the following conditions :
13+
//
14+
// The above copyright notice and this permission notice shall be included in
15+
// all copies or substantial portions of the Software.
16+
//
17+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23+
// THE SOFTWARE.
24+
25+
#import "MSIDFlightManagerQueryKeyType.h"
26+
27+
MSIDFlightManagerQueryKeyType const MSIDFlightManagerQueryKeyTypeTenantId = @"tenantId";
28+
MSIDFlightManagerQueryKeyType const MSIDFlightManagerQueryKeyTypeAppBundleId = @"appBundleId";
29+
MSIDFlightManagerQueryKeyType const MSIDFlightManagerQueryKeyTypeEcsRegion = @"ecsRegion";
30+
MSIDFlightManagerQueryKeyType const MSIDFlightManagerQueryKeyTypePlatform = @"platform";
31+
MSIDFlightManagerQueryKeyType const MSIDFlightManagerQueryKeyTypeUpn = @"upn";
32+
MSIDFlightManagerQueryKeyType const MSIDFlightManagerQueryKeyTypeUserId = @"userId";
33+
MSIDFlightManagerQueryKeyType const MSIDFlightManagerQueryKeyTypeVersionNumber = @"version_number";

IdentityCore/src/oauth2/aad_base/MSIDAADWebviewFactory.m

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
#import "MSIDSwitchBrowserResponse.h"
4242
#import "MSIDSwitchBrowserResumeResponse.h"
4343
#import "MSIDFlightManager.h"
44+
#import "MSIDAccountIdentifier.h"
4445

4546
#if !EXCLUDE_FROM_MSALCPP
4647
#import "MSIDJITTroubleshootingResponse.h"
@@ -84,8 +85,23 @@ @implementation MSIDAADWebviewFactory
8485
result[@"haschrome"] = @"1";
8586
[result addEntriesFromDictionary:MSIDDeviceId.deviceId];
8687

88+
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];
102+
87103
#if TARGET_OS_IPHONE
88-
if ([MSIDFlightManager.sharedInstance boolForKey:MSID_FLIGHT_SUPPORT_DUNA_CBA])
104+
if (allowDUNAGlobal || allowDUNAByTenant)
89105
{
90106
// Let server know that we support new cba flow
91107
result[MSID_BROWSER_RESPONSE_SWITCH_BROWSER] = @"1";
@@ -202,7 +218,22 @@ - (MSIDWebviewResponse *)oAuthResponseWithURL:(NSURL *)url
202218
error:nil];
203219
if (browserResponse) return browserResponse;
204220

205-
if ([MSIDFlightManager.sharedInstance boolForKey:MSID_FLIGHT_SUPPORT_DUNA_CBA])
221+
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];
235+
236+
if (allowDUNAGlobal || allowDUNAByTenant)
206237
{
207238
MSIDSwitchBrowserResponse *switchBrowserResponse = [[MSIDSwitchBrowserResponse alloc] initWithURL:url
208239
redirectUri:endRedirectUri

0 commit comments

Comments
 (0)