Skip to content

Commit 9905d2d

Browse files
authored
Merge pull request #1558 from AzureAD/copilot/fix-a085362b-c3b3-4eea-9d68-93444657b3d6
Add correlationId field to SignOut API in BrowserCore flow
2 parents 8d78d3c + e7533b9 commit 9905d2d

File tree

5 files changed

+52
-2
lines changed

5 files changed

+52
-2
lines changed

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

Lines changed: 0 additions & 1 deletion
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";

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: 6 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,11 @@ - (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 = uuidString ? [[NSUUID alloc] initWithUUIDString:uuidString] : [NSUUID UUID];
66+
6267
return self;
6368
}
6469

IdentityCore/tests/MSIDBrowserNativeMessageSignOutRequestTests.m

Lines changed: 41 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,44 @@ - (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+
75116
@end

0 commit comments

Comments
 (0)