Skip to content

Commit 0ac33e5

Browse files
authored
Merge pull request #1563 from AzureAD/sedemche/sign_out_corr_id
Parse sign out correlation id
2 parents f02d905 + 1c96689 commit 0ac33e5

File tree

7 files changed

+109
-3
lines changed

7 files changed

+109
-3
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/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

changelog.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ TBD
22
* Query and populate ECC STK in Workplacejoin information for iOS (#1555)
33
* Return MATS blob for GetToken api response #1551
44
* Introduce a class and cache item class to represent bound refresh tokens (#1548)
5+
* Parse sign out correlation id #1563
56

67
Version 1.14.0
78
* Added state validation to DUNA flow (#1543)

0 commit comments

Comments
 (0)