Skip to content

Commit b3be88b

Browse files
author
Kai Song
committed
Merge branch 'dev' into kasong/2914053-common-interface
2 parents 28e84c5 + e1107cd commit b3be88b

32 files changed

+717
-49
lines changed

IdentityCore/IdentityCore.xcodeproj/project.pbxproj

Lines changed: 30 additions & 0 deletions
Large diffs are not rendered by default.

IdentityCore/src/MSIDBrokerConstants.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ extern NSString * _Nonnull const MSID_SKIP_VALIDATE_RESULT_ACCOUNT_KEY;
9797
extern NSString * _Nonnull const MSID_JIT_TROUBLESHOOTING_HOST;
9898
extern NSString * _Nonnull const MSID_IS_CALLER_MANAGED_KEY;
9999
extern NSString * _Nonnull const MSID_BROKER_PREFERRED_AUTH_CONFIGURATION_KEY;
100+
extern NSString * _Nonnull const MSID_BROKER_CLIENT_FLIGHTS_KEY;
100101
extern NSString * _Nonnull const MSID_BROKER_SDM_WPJ_ATTEMPTED;
101102
extern NSString * _Nonnull const MSID_EXP_RETRY_ON_NETWORK;
102103
extern NSString * _Nonnull const MSID_EXP_ENABLE_CONNECTION_CLOSE;

IdentityCore/src/MSIDBrokerConstants.m

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@
7878
NSString *const MSID_BROKER_TYPES_OF_HEADER = @"types_of_header";
7979
NSString *const MSID_BROKER_REQUEST_SENT_TIMESTAMP = @"request_sent_timestamp";
8080
NSString *const MSID_BROKER_PREFERRED_AUTH_CONFIGURATION_KEY = @"preferred_auth_config";
81+
NSString *const MSID_BROKER_CLIENT_FLIGHTS_KEY = @"client_flights";
8182
NSString *const MSID_BROKER_ACCOUNT_HOME_TENANT_ID = @"account_home_tenant_id";
8283
NSString *const MSID_CLIENT_SKU_KEY = @"client_sku";
8384
NSString *const MSID_SKIP_VALIDATE_RESULT_ACCOUNT_KEY = @"skip_validate_result_account";
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
2+
//
3+
// Copyright (c) Microsoft Corporation.
4+
// All rights reserved.
5+
//
6+
// This code is licensed under the MIT License.
7+
//
8+
// Permission is hereby granted, free of charge, to any person obtaining a copy
9+
// of this software and associated documentation files(the "Software"), to deal
10+
// in the Software without restriction, including without limitation the rights
11+
// to use, copy, modify, merge, publish, distribute, sublicense, and / or sell
12+
// copies of the Software, and to permit persons to whom the Software is
13+
// furnished to do so, subject to the following conditions :
14+
//
15+
// The above copyright notice and this permission notice shall be included in
16+
// all copies or substantial portions of the Software.
17+
//
18+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24+
// THE SOFTWARE.
25+
26+
#import <Foundation/Foundation.h>
27+
#import "MSIDFlightManager.h"
28+
29+
NS_ASSUME_NONNULL_BEGIN
30+
31+
@interface MSIDBrokerFlightProvider : NSObject <MSIDFlightManagerInterface>
32+
33+
- (instancetype _Nullable)initWithBase64EncodedFlightsPayload:(nullable NSString *)base64EncodedFlightsPayload NS_DESIGNATED_INITIALIZER;
34+
35+
- (instancetype _Nullable)init NS_UNAVAILABLE;
36+
+ (instancetype _Nullable)new NS_UNAVAILABLE;
37+
38+
@end
39+
40+
NS_ASSUME_NONNULL_END
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
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 "MSIDBrokerFlightProvider.h"
26+
#import "NSJSONSerialization+MSIDExtensions.h"
27+
28+
@interface MSIDBrokerFlightProvider()
29+
30+
@property (nonatomic, nullable, readonly) NSDictionary *clientFlightsPayload;
31+
32+
@end
33+
34+
@implementation MSIDBrokerFlightProvider
35+
36+
- (instancetype _Nullable)initWithBase64EncodedFlightsPayload:(nullable NSString *)base64EncodedFlightsPayload
37+
{
38+
self = [super init];
39+
40+
if (self)
41+
{
42+
if ([NSString msidIsStringNilOrBlank:base64EncodedFlightsPayload])
43+
{
44+
MSID_LOG_WITH_CTX(MSIDLogLevelInfo,nil, @"Broker client flights is nil or empty");
45+
return nil;
46+
}
47+
48+
NSDictionary *clientFlightsDict = nil;
49+
50+
NSData *decodedJsonData = [[base64EncodedFlightsPayload msidBase64UrlDecode] dataUsingEncoding:NSUTF8StringEncoding];
51+
if (decodedJsonData && [decodedJsonData length])
52+
{
53+
clientFlightsDict = [NSJSONSerialization msidNormalizedDictionaryFromJsonData:decodedJsonData error:nil];
54+
55+
if (![clientFlightsDict isKindOfClass:[NSDictionary class]])
56+
{
57+
MSID_LOG_WITH_CTX(MSIDLogLevelWarning,nil, @"Invalid broker client flight format");
58+
return nil;
59+
}
60+
}
61+
else
62+
{
63+
MSID_LOG_WITH_CTX(MSIDLogLevelWarning,nil, @"Failed to decode base64encoded client flights from broker");
64+
return nil;
65+
}
66+
67+
if (clientFlightsDict)
68+
{
69+
_clientFlightsPayload = clientFlightsDict;
70+
MSID_LOG_WITH_CTX(MSIDLogLevelInfo, nil, @"Client flights from broker is decoded successfully");
71+
}
72+
}
73+
74+
return self;
75+
}
76+
77+
#pragma mark - MSIDFlightManagerInterface
78+
79+
- (BOOL)boolForKey:(nonnull NSString *)flightKey
80+
{
81+
if (self.clientFlightsPayload)
82+
{
83+
id value = self.clientFlightsPayload[flightKey];
84+
85+
if ([value isKindOfClass:[NSNumber class]] || [value isKindOfClass:[NSString class]])
86+
{
87+
return [value boolValue];
88+
}
89+
}
90+
91+
return NO;
92+
}
93+
94+
- (nullable NSString *)stringForKey:(nonnull NSString *)flightKey
95+
{
96+
if (self.clientFlightsPayload)
97+
{
98+
id value = self.clientFlightsPayload[flightKey];
99+
100+
if ([value isKindOfClass:[NSString class]])
101+
{
102+
return value;
103+
}
104+
}
105+
106+
return nil;
107+
}
108+
109+
110+
@end

IdentityCore/src/MSIDConstants.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,5 +184,6 @@ extern NSString * _Nonnull const MSID_BROWSER_RESPONSE_SWITCH_BROWSER_RESUME;
184184

185185
extern NSString * _Nonnull const MSID_FLIGHT_USE_V2_WEB_RESPONSE_FACTORY;
186186
extern NSString * _Nonnull const MSID_FLIGHT_SUPPORT_DUNA_CBA;
187+
extern NSString * _Nonnull const MSID_FLIGHT_CLIENT_SFRT_STATUS;
187188

188189
#define METHODANDLINE [NSString stringWithFormat:@"%s [Line %d]", __PRETTY_FUNCTION__, __LINE__]

IdentityCore/src/MSIDConstants.m

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,8 @@
7777
NSString *const MSID_BROWSER_RESPONSE_SWITCH_BROWSER_RESUME = @"switch_browser_resume";
7878

7979
NSString *const MSID_FLIGHT_USE_V2_WEB_RESPONSE_FACTORY = @"use_v2_web_response_factory";
80-
NSString *const MSID_FLIGHT_SUPPORT_DUNA_CBA = @"support_duna_cba";
80+
NSString *const MSID_FLIGHT_SUPPORT_DUNA_CBA = @"support_duna_cba_v2";
81+
NSString *const MSID_FLIGHT_CLIENT_SFRT_STATUS = @"sfrt_status";
8182

8283

8384
#define METHODANDLINE [NSString stringWithFormat:@"%s [Line %d]", __PRETTY_FUNCTION__, __LINE__]

IdentityCore/src/MSIDFlightManager.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,14 @@ NS_ASSUME_NONNULL_BEGIN
3030
@protocol MSIDFlightManagerInterface <NSObject>
3131

3232
- (BOOL)boolForKey:(NSString *)flightKey;
33+
- (nullable NSString *)stringForKey:(NSString *)key;
34+
3335

3436
@end
3537

3638
@interface MSIDFlightManager : NSObject <MSIDFlightManagerInterface>
3739

38-
@property (nonatomic) id<MSIDFlightManagerInterface> flightProvider;
40+
@property (nonatomic, nullable) id<MSIDFlightManagerInterface> flightProvider;
3941

4042
+ (instancetype)sharedInstance;
4143

IdentityCore/src/MSIDFlightManager.m

Lines changed: 53 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,26 +25,76 @@
2525

2626
#import "MSIDFlightManager.h"
2727

28+
@interface MSIDFlightManager()
29+
30+
@property (nonatomic) dispatch_queue_t synchronizationQueue;
31+
32+
@end
33+
34+
2835
@implementation MSIDFlightManager
2936

3037
+ (instancetype)sharedInstance
3138
{
3239
static MSIDFlightManager *sharedInstance = nil;
3340
static dispatch_once_t onceToken;
3441
dispatch_once(&onceToken, ^{
35-
sharedInstance = [[self.class alloc] init];
42+
sharedInstance = [[self.class alloc] initInternal];
3643
});
3744

3845
return sharedInstance;
3946
}
4047

48+
- (instancetype)initInternal
49+
{
50+
self = [super init];
51+
if (self)
52+
{
53+
_synchronizationQueue = [self initializeDispatchQueue];
54+
}
55+
return self;
56+
}
57+
58+
- (dispatch_queue_t)initializeDispatchQueue
59+
{
60+
NSString *queueName = [NSString stringWithFormat:@"com.microsoft.msidflightmanager-%@", [NSUUID UUID].UUIDString];
61+
return dispatch_queue_create([queueName cStringUsingEncoding:NSASCIIStringEncoding], DISPATCH_QUEUE_CONCURRENT);
62+
}
63+
64+
- (void)setFlightProvider:(id<MSIDFlightManagerInterface>)flightProvider
65+
{
66+
dispatch_barrier_async(self.synchronizationQueue, ^{
67+
self->_flightProvider = flightProvider;
68+
});
69+
}
70+
4171
#pragma mark - MSIDFlightManagerInterface
4272

4373
- (BOOL)boolForKey:(nonnull NSString *)flightKey
4474
{
45-
if (self.flightProvider) { return [self.flightProvider boolForKey:flightKey]; }
75+
__block BOOL result = NO;
76+
if (self.flightProvider)
77+
{
78+
dispatch_sync(self.synchronizationQueue, ^{
79+
result = [self.flightProvider boolForKey:flightKey];
80+
});
81+
}
4682

47-
return NO;
83+
return result;
4884
}
4985

86+
- (nullable NSString *)stringForKey:(nonnull NSString *)flightKey
87+
{
88+
__block NSString* result = nil;
89+
if (self.flightProvider)
90+
{
91+
dispatch_sync(self.synchronizationQueue, ^{
92+
result = [self.flightProvider stringForKey:flightKey];
93+
});
94+
}
95+
96+
return result;
97+
}
98+
99+
50100
@end

IdentityCore/src/MSIDJsonSerializableTypes.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,13 @@ extern MSIDJsonSerializableType const MSID_JSON_TYPE_OPERATION_REQUEST_GET_ACCOU
3636
extern MSIDJsonSerializableType const MSID_JSON_TYPE_OPERATION_REQUEST_GET_DEVICE_INFO;
3737
extern MSIDJsonSerializableType const MSID_JSON_TYPE_OPERATION_REQUEST_GET_PRT;
3838
extern MSIDJsonSerializableType const MSID_JSON_TYPE_OPERATION_REQUEST_GET_SSO_COOKIES;
39-
extern MSIDJsonSerializableType const MSID_JSON_TYPE_OPERATION_REQUEST_BROWSER_NATIVE_MESSAGE;
4039
extern MSIDJsonSerializableType const MSID_JSON_TYPE_OPERATION_REQUEST_PASSKEY_ASSERTION;
4140
extern MSIDJsonSerializableType const MSID_JSON_TYPE_OPERATION_REQUEST_PASSKEY_CREDENTIAL;
41+
extern MSIDJsonSerializableType const MSID_JSON_TYPE_OPERATION_REQUEST_BROWSER_NATIVE_MESSAGE;
42+
extern MSIDJsonSerializableType const MSID_JSON_TYPE_OPERATION_REQUEST_BROWSER_NATIVE_GET_SUPPORTED_CONTRACTS;
4243

4344
extern MSIDJsonSerializableType const MSID_JSON_TYPE_BROKER_OPERATION_BROWSER_NATIVE_MESSAGE_RESPONSE;
45+
extern MSIDJsonSerializableType const MSID_JSON_TYPE_BROKER_OPERATION_BROWSER_NATIVE_GET_SUPPORTED_CONTRACTS_RESPONSE;
4446
extern MSIDJsonSerializableType const MSID_JSON_TYPE_BROKER_OPERATION_GET_ACCOUNTS_RESPONSE;
4547
extern MSIDJsonSerializableType const MSID_JSON_TYPE_BROKER_OPERATION_GENERIC_RESPONSE;
4648
extern MSIDJsonSerializableType const MSID_JSON_TYPE_BROKER_OPERATION_TOKEN_RESPONSE;

0 commit comments

Comments
 (0)