Skip to content

Commit db67e3f

Browse files
committed
Merge branch 'dev' into ameyapat/msid-jwe-decryptor
* dev: Add showHeadsUp param. Align protocol nullable/nonnull with xpc service remove a line that coule causing crash when XPC service refuse to take connections check corr_id in correct format. modified: changelog.txt nit Add correlationId field to SignOut API in BrowserCore flow Initial plan
2 parents 3c7bb89 + 8742e2a commit db67e3f

11 files changed

+116
-8
lines changed

IdentityCore/src/broker_operation/request/browser_native_message_request/MSIDBrowserNativeMessageGetTokenRequest.m

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
#import "MSIDConstants.h"
3131
#import "MSIDPromptType_Internal.h"
3232

33-
NSString *const MSID_BROWSER_NATIVE_MESSAGE_CORRELATION_KEY = @"correlationId";
3433
NSString *const MSID_BROWSER_NATIVE_MESSAGE_CLIENT_ID_KEY = @"clientId";
3534
NSString *const MSID_BROWSER_NATIVE_MESSAGE_AUTHORITY_KEY = @"authority";
3635
NSString *const MSID_BROWSER_NATIVE_MESSAGE_SCOPE_KEY = @"scope";
@@ -160,7 +159,13 @@ - (instancetype)initWithJSONDictionary:(NSDictionary *)json error:(NSError *__au
160159

161160
if (![requestJson msidAssertType:NSString.class ofKey:MSID_BROWSER_NATIVE_MESSAGE_CORRELATION_KEY required:NO error:error]) return nil;
162161
NSString *uuidString = requestJson[MSID_BROWSER_NATIVE_MESSAGE_CORRELATION_KEY];
163-
_correlationId = uuidString ? [[NSUUID alloc] initWithUUIDString:uuidString] : [NSUUID UUID];
162+
_correlationId = [[NSUUID alloc] initWithUUIDString:uuidString];
163+
if (!_correlationId)
164+
{
165+
_correlationId = [NSUUID UUID];
166+
MSID_LOG_WITH_CTX_PII(MSIDLogLevelWarning, nil, @"CorrelationID is invalid or not in UUID format: %@. Use new correlationId: %@", uuidString, _correlationId);
167+
}
168+
164169
_platformSequence = [requestJson msidStringObjectForKey:MSID_BROWSER_NATIVE_MESSAGE_PLATFORM_SEQUENCE_KEY];
165170

166171
id canShowUIValue = requestJson[MSID_BROWSER_NATIVE_MESSAGE_CAN_SHOW_UI_KEY];

IdentityCore/src/broker_operation/request/browser_native_message_request/MSIDBrowserNativeMessageRequest.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,7 @@ NS_ASSUME_NONNULL_BEGIN
3838
@end
3939

4040
NS_ASSUME_NONNULL_END
41+
42+
extern NSString * _Nonnull const MSID_BROWSER_NATIVE_MESSAGE_SENDER_KEY;
43+
extern NSString * _Nonnull const MSID_BROWSER_NATIVE_MESSAGE_METHOD_KEY;
44+
extern NSString * _Nonnull const MSID_BROWSER_NATIVE_MESSAGE_CORRELATION_KEY;

IdentityCore/src/broker_operation/request/browser_native_message_request/MSIDBrowserNativeMessageRequest.m

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828

2929
NSString *const MSID_BROWSER_NATIVE_MESSAGE_SENDER_KEY = @"sender";
3030
NSString *const MSID_BROWSER_NATIVE_MESSAGE_METHOD_KEY = @"method";
31+
NSString *const MSID_BROWSER_NATIVE_MESSAGE_CORRELATION_KEY = @"correlationId";
3132

3233
@implementation MSIDBrowserNativeMessageRequest
3334

IdentityCore/src/broker_operation/request/browser_native_message_request/MSIDBrowserNativeMessageSignOutRequest.m

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ - (NSString *)description
4444
{
4545
__auto_type parentDescription = [super description];
4646

47-
return [NSString stringWithFormat:@"%@ accountId: (homeAccountId: %@ displayableId: %@)", parentDescription, MSID_PII_LOG_TRACKABLE(self.accountId.homeAccountId), MSID_PII_LOG_EMAIL(self.accountId.displayableId)];
47+
return [NSString stringWithFormat:@"%@ accountId: (homeAccountId: %@ displayableId: %@), correlationId: %@", parentDescription, MSID_PII_LOG_TRACKABLE(self.accountId.homeAccountId), MSID_PII_LOG_EMAIL(self.accountId.displayableId), self.correlationId.UUIDString];
4848
}
4949

5050
#pragma mark - MSIDJsonSerializable
@@ -59,6 +59,16 @@ - (instancetype)initWithJSONDictionary:(NSDictionary *)json error:(NSError *__au
5959

6060
_accountId = [[MSIDAccountIdentifier alloc] initWithDisplayableId:nil homeAccountId:homeAccountId];
6161

62+
// Parse correlationId from JSON - optional field
63+
if (![json msidAssertType:NSString.class ofKey:MSID_BROWSER_NATIVE_MESSAGE_CORRELATION_KEY required:NO error:error]) return nil;
64+
NSString *uuidString = [json msidStringObjectForKey:MSID_BROWSER_NATIVE_MESSAGE_CORRELATION_KEY];
65+
_correlationId = [[NSUUID alloc] initWithUUIDString:uuidString];
66+
if (!_correlationId)
67+
{
68+
_correlationId = [NSUUID UUID];
69+
MSID_LOG_WITH_CTX_PII(MSIDLogLevelWarning, nil, @"CorrelationID is invalid or not in UUID format: %@. Use new correlationId: %@", uuidString, _correlationId);
70+
}
71+
6272
return self;
6373
}
6474

IdentityCore/src/broker_operation/request/token_request/MSIDBrokerOperationTokenRequest.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ NS_ASSUME_NONNULL_BEGIN
5151
@property (nonatomic) BOOL forceRefresh;
5252
@property (nonatomic) BOOL ignoreScopeValidation;
5353
@property (nonatomic) BOOL bypassRedirectURIValidation;
54+
@property (nonatomic) BOOL showHeadsUp;
5455

5556
+ (BOOL)fillRequest:(MSIDBrokerOperationTokenRequest *)request
5657
withParameters:(MSIDRequestParameters *)parameters

IdentityCore/src/broker_operation/request/token_request/MSIDBrokerOperationTokenRequest.m

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ + (BOOL)fillRequest:(MSIDBrokerOperationTokenRequest *)request
6969
request.allowAnyExtraURLQueryParameters = parameters.allowAnyExtraURLQueryParameters;
7070
request.ignoreScopeValidation = parameters.ignoreScopeValidation;
7171
request.bypassRedirectURIValidation = parameters.bypassRedirectURIValidation;
72+
request.showHeadsUp = parameters.showHeadsUp;
7273
return YES;
7374
}
7475

IdentityCore/src/parameters/MSIDRequestParameters.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@
6464
// - When set by the MSAL app: brokered flows are disabled, and MSAL falls back to local auth flows.
6565
@property (nonatomic) BOOL bypassRedirectURIValidation;
6666

67+
@property (nonatomic) BOOL showHeadsUp;
68+
6769
// Telemetry metadata
6870
@property (nonatomic) NSString *platformSequence;
6971

IdentityCore/src/util/mac/MSIDXpcSingleSignOnProvider.m

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ @protocol MSIDXpcBrokerInstanceProtocol <NSObject>
7070

7171
- (void)handleXpcWithRequestParams:(NSDictionary *)passedInParams
7272
parentViewFrame:(NSRect)frame
73-
completionBlock:(void (^)(NSDictionary<NSString *,id> * _Nonnull, NSDate * _Nonnull, NSString * _Nonnull, NSError * _Nullable))blockName;
73+
completionBlock:(void (^)(NSDictionary<NSString *,id> * _Nullable, NSDate * _Nonnull, NSString * _Nonnull, NSError * _Nullable))blockName;
7474

7575
- (void)canPerformWithMetadata:(NSDictionary *)passedInParams
7676
completionBlock:(void (^)(BOOL))blockName;
@@ -115,7 +115,7 @@ - (void)handleRequestParam:(NSDictionary *)requestParam
115115
return;
116116
}
117117

118-
[xpcService handleXpcWithRequestParams:requestParam parentViewFrame:frame completionBlock:^(NSDictionary<NSString *,id> * _Nonnull replyParam, NSDate * _Nonnull __unused xpcStartDate, NSString * _Nonnull __unused processId, NSError * _Nonnull callbackError) {
118+
[xpcService handleXpcWithRequestParams:requestParam parentViewFrame:frame completionBlock:^(NSDictionary<NSString *,id> * _Nullable replyParam, NSDate * _Nonnull __unused xpcStartDate, NSString * _Nonnull __unused processId, NSError * _Nullable callbackError) {
119119
[directConnection suspend];
120120
[directConnection invalidate];
121121

@@ -415,8 +415,6 @@ - (void)getXpcService:(id<MSIDXpcProviderCaching>)xpcProviderCache withContinueB
415415
continueBlock(nil, nil, xpcError);
416416
return;
417417
}
418-
419-
if (continueBlock) continueBlock(nil, nil, xpcError);
420418
}];
421419

422420
id<MSIDXpcBrokerDispatcherProtocol> parentXpcService = [connection remoteObjectProxyWithErrorHandler:^(NSError * _Nonnull error) {

IdentityCore/tests/MSIDBrowserNativeMessageGetTokenRequestTests.m

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,30 @@ - (void)testInitWithJSONDictionary_whenJsonValidAndRequiredOnlyFieldsProvided_sh
126126
XCTAssertNotNil(request.correlationId.UUIDString);
127127
}
128128

129+
- (void)testInitWithJSONDictionary_whenCorrelationIdProvidedInWrongFormat_shouldGenerateCorrelationId
130+
{
131+
__auto_type json = @{
132+
@"sender": @"https://login.microsoft.com",
133+
@"request": @{
134+
@"clientId": @"29a788ca-7bcf-4732-b23c-c8d294347e5b",
135+
@"scope": @"user.read openid profile offline_access",
136+
@"redirectUri": @"https://login.microsoft.com",
137+
@"correlationId": @"abc",
138+
}
139+
};
140+
141+
NSError *error;
142+
__auto_type request = [[MSIDBrowserNativeMessageGetTokenRequest alloc] initWithJSONDictionary:json error:&error];
143+
144+
XCTAssertNil(error);
145+
XCTAssertNotNil(request);
146+
XCTAssertEqualObjects(@"29a788ca-7bcf-4732-b23c-c8d294347e5b", request.clientId);
147+
XCTAssertEqualObjects(@"user.read openid profile offline_access", request.scopes);
148+
XCTAssertEqualObjects(@"https://login.microsoft.com", request.redirectUri);
149+
XCTAssertTrue(request.canShowUI);
150+
XCTAssertNotNil(request.correlationId.UUIDString);
151+
}
152+
129153
- (void)testInitWithJSONDictionary_whenAuthorityInvalid_shouldFail
130154
{
131155
__auto_type json = @{

IdentityCore/tests/MSIDBrowserNativeMessageSignOutRequestTests.m

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ - (void)testInitWithJSONDictionary_whenAccountIdIsValid_shouldInit
5454
XCTAssertEqualObjects(@"https://login.microsoft.com", request.sender.absoluteString);
5555
XCTAssertEqualObjects(@"uid", request.accountId.uid);
5656
XCTAssertEqualObjects(@"utid", request.accountId.utid);
57+
XCTAssertNotNil(request.correlationId); // Should generate a UUID if not provided
5758
}
5859

5960
- (void)testInitWithJSONDictionary_whenAccountIdIsInvalid_shouldFail
@@ -72,4 +73,64 @@ - (void)testInitWithJSONDictionary_whenAccountIdIsInvalid_shouldFail
7273
XCTAssertEqualObjects(error.userInfo[MSIDErrorDescriptionKey], @"account Id is invalid.");
7374
}
7475

76+
- (void)testInitWithJSONDictionary_whenCorrelationIdProvided_shouldUseProvidedCorrelationId
77+
{
78+
__auto_type json = @{
79+
@"method": @"SignOut",
80+
@"accountId": @"uid.utid",
81+
@"correlationId": @"2e34a931-fc34-442a-a248-a044e42d3027",
82+
@"sender": @"https://localhost:8000"
83+
};
84+
85+
NSError *error;
86+
__auto_type request = [[MSIDBrowserNativeMessageSignOutRequest alloc] initWithJSONDictionary:json error:&error];
87+
88+
XCTAssertNil(error);
89+
XCTAssertNotNil(request);
90+
XCTAssertEqualObjects(@"https://localhost:8000", request.sender.absoluteString);
91+
XCTAssertEqualObjects(@"uid", request.accountId.uid);
92+
XCTAssertEqualObjects(@"utid", request.accountId.utid);
93+
XCTAssertEqualObjects(@"2E34A931-FC34-442A-A248-A044E42D3027", request.correlationId.UUIDString);
94+
}
95+
96+
- (void)testInitWithJSONDictionary_whenCorrelationIdNotProvided_shouldGenerateCorrelationId
97+
{
98+
__auto_type json = @{
99+
@"method": @"SignOut",
100+
@"accountId": @"uid.utid",
101+
@"sender": @"https://localhost:8000"
102+
};
103+
104+
NSError *error;
105+
__auto_type request = [[MSIDBrowserNativeMessageSignOutRequest alloc] initWithJSONDictionary:json error:&error];
106+
107+
XCTAssertNil(error);
108+
XCTAssertNotNil(request);
109+
XCTAssertEqualObjects(@"https://localhost:8000", request.sender.absoluteString);
110+
XCTAssertEqualObjects(@"uid", request.accountId.uid);
111+
XCTAssertEqualObjects(@"utid", request.accountId.utid);
112+
XCTAssertNotNil(request.correlationId);
113+
XCTAssertNotNil(request.correlationId.UUIDString);
114+
}
115+
116+
- (void)testInitWithJSONDictionary_whenCorrelationIdProvidedInWrongFormat_shouldGenerateCorrelationId
117+
{
118+
__auto_type json = @{
119+
@"method": @"SignOut",
120+
@"accountId": @"uid.utid",
121+
@"correlationId": @"abc",
122+
@"sender": @"https://localhost:8000"
123+
};
124+
125+
NSError *error;
126+
__auto_type request = [[MSIDBrowserNativeMessageSignOutRequest alloc] initWithJSONDictionary:json error:&error];
127+
128+
XCTAssertNil(error);
129+
XCTAssertNotNil(request);
130+
XCTAssertEqualObjects(@"https://localhost:8000", request.sender.absoluteString);
131+
XCTAssertEqualObjects(@"uid", request.accountId.uid);
132+
XCTAssertEqualObjects(@"utid", request.accountId.utid);
133+
XCTAssertNotNil(request.correlationId.UUIDString);
134+
}
135+
75136
@end

0 commit comments

Comments
 (0)