Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add SsoExt identifier into MSIDDeviceInfo #1488

Open
wants to merge 3 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions IdentityCore/src/MSIDBrokerConstants.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ extern NSString * _Nonnull const MSID_BROKER_DEVICE_MODE_KEY;
extern NSString * _Nonnull const MSID_BROKER_SSO_EXTENSION_MODE_KEY;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This pull request does not update changelog.txt.

Please consider if this change would be noticeable to a partner or user and either update changelog.txt or resolve this conversation.

extern NSString * _Nonnull const MSID_BROKER_WPJ_STATUS_KEY;
extern NSString * _Nonnull const MSID_BROKER_BROKER_VERSION_KEY;
extern NSString * _Nonnull const MSID_BROKER_BROKER_TYPE_KEY;
extern NSString * _Nonnull const MSID_BROKER_IS_PERFORMING_CBA;
extern NSString * _Nonnull const MSID_ADAL_BROKER_MESSAGE_VERSION;
extern NSString * _Nonnull const MSID_MSAL_BROKER_MESSAGE_VERSION;
Expand Down
1 change: 1 addition & 0 deletions IdentityCore/src/MSIDBrokerConstants.m
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
NSString *const MSID_BROKER_SSO_EXTENSION_MODE_KEY = @"sso_extension_mode";
NSString *const MSID_BROKER_WPJ_STATUS_KEY = @"wpj_status";
NSString *const MSID_BROKER_BROKER_VERSION_KEY = @"broker_version";
NSString *const MSID_BROKER_BROKER_TYPE_KEY = @"broker_type";
NSString *const MSID_BROKER_IS_PERFORMING_CBA = @"broker_is_performing_cba";
NSString *const MSID_ADAL_BROKER_MESSAGE_VERSION = @"2";
NSString *const MSID_MSAL_BROKER_MESSAGE_VERSION = @"3";
Expand Down
10 changes: 9 additions & 1 deletion IdentityCore/src/broker_operation/response/MSIDDeviceInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,12 @@ typedef NS_ENUM(NSInteger, MSIDPreferredAuthMethod)
MSIDPreferredAuthMethodQRPIN
};

typedef NS_ENUM(NSInteger, MSIDSsoProviderType)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be beneficial to make this enum available in a separate header file?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are other enums in this file as of today, we can move out when more enums coming for better management

{
MSIDUnknownSsoProvider = 0,
MSIDMacBrokerSsoProvider,
MSIDCompanyPortalSsoProvider
};

NS_ASSUME_NONNULL_BEGIN

Expand All @@ -64,6 +70,7 @@ NS_ASSUME_NONNULL_BEGIN
@property (nonatomic) MSIDSSOExtensionMode ssoExtensionMode;
@property (nonatomic) MSIDWorkPlaceJoinStatus wpjStatus;
@property (nonatomic, nullable) NSString *brokerVersion;
@property (nonatomic) MSIDSsoProviderType ssoProviderType;
@property (nonatomic) NSDictionary *additionalExtensionData;
@property (nonatomic) MSIDPreferredAuthMethod preferredAuthConfig;

Expand All @@ -77,7 +84,8 @@ NS_ASSUME_NONNULL_BEGIN
- (instancetype)initWithDeviceMode:(MSIDDeviceMode)deviceMode
ssoExtensionMode:(MSIDSSOExtensionMode)ssoExtensionMode
isWorkPlaceJoined:(BOOL)isWorkPlaceJoined
brokerVersion:(NSString *)brokerVersion;
brokerVersion:(NSString *)brokerVersion
ssoProviderType:(MSIDSsoProviderType)ssoProviderType;

@end

Expand Down
25 changes: 24 additions & 1 deletion IdentityCore/src/broker_operation/response/MSIDDeviceInfo.m
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@

@implementation MSIDDeviceInfo


- (instancetype)initWithDeviceMode:(MSIDDeviceMode)deviceMode
ssoExtensionMode:(MSIDSSOExtensionMode)ssoExtensionMode
isWorkPlaceJoined:(BOOL)isWorkPlaceJoined
brokerVersion:(NSString *)brokerVersion
ssoProviderType:(MSIDSsoProviderType)ssoProviderType
{
self = [super init];

Expand All @@ -45,6 +45,7 @@ - (instancetype)initWithDeviceMode:(MSIDDeviceMode)deviceMode
_ssoExtensionMode = ssoExtensionMode;
_wpjStatus = isWorkPlaceJoined ? MSIDWorkPlaceJoinStatusJoined : MSIDWorkPlaceJoinStatusNotJoined;
_brokerVersion = brokerVersion;
_ssoProviderType = ssoProviderType;
}

return self;
Expand All @@ -66,6 +67,7 @@ - (instancetype)initWithJSONDictionary:(NSDictionary *)json error:(__unused NSEr

#if TARGET_OS_OSX
_platformSSOStatus = [self platformSSOStatusEnumFromString:[json msidStringObjectForKey:MSID_PLATFORM_SSO_STATUS_KEY]];
_ssoProviderType = [self ssoProviderTypeEnumFromString:[json msidStringObjectForKey:MSID_BROKER_BROKER_TYPE_KEY]];
#endif

NSString *jsonDataString = [json msidStringObjectForKey:MSID_ADDITIONAL_EXTENSION_DATA_KEY];
Expand Down Expand Up @@ -97,6 +99,7 @@ - (NSDictionary *)jsonDictionary
json[MSID_BROKER_PREFERRED_AUTH_CONFIGURATION_KEY] = [self preferredAuthConfigurationStringFromEnum:self.preferredAuthConfig];
#if TARGET_OS_OSX
json[MSID_PLATFORM_SSO_STATUS_KEY] = [self platformSSOStatusStringFromEnum:self.platformSSOStatus];
json[MSID_BROKER_BROKER_TYPE_KEY] = [self ssoProviderTypeStringFromEnum:self.ssoProviderType];
#endif
json[MSID_ADDITIONAL_EXTENSION_DATA_KEY] = [self.additionalExtensionData msidJSONSerializeWithContext:nil];
if (self.extraDeviceInfo)
Expand Down Expand Up @@ -215,4 +218,24 @@ - (MSIDPreferredAuthMethod)preferredAuthConfigurationEnumFromString:(NSString *)
return MSIDPreferredAuthMethodNotConfigured;
}

- (NSString *)ssoProviderTypeStringFromEnum:(MSIDSsoProviderType)deviceMode
{
switch (deviceMode) {
case MSIDCompanyPortalSsoProvider:
return @"companyPortal";
case MSIDMacBrokerSsoProvider:
return @"macBroker";
default:
return @"unknown";
}
}

- (MSIDSsoProviderType)ssoProviderTypeEnumFromString:(NSString *)deviceModeString
{
if ([deviceModeString isEqualToString:@"companyPortal"]) return MSIDCompanyPortalSsoProvider;
Copy link
Contributor

@ameyapat ameyapat Feb 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Create a static dictionary <string, MSIDSsoProviderType> instead of if statements and return value for key. Return unknown by default in no matching key

Copy link
Contributor Author

@kaisong1990 kaisong1990 Feb 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @ameyapat, cannot put MSIDSsoProviderType into dictionary as NSInteger is not supported neither as a key or value. I can convert MSIDSsoProviderType value to an NSNumber and save it into a dict, let me know.

if ([deviceModeString isEqualToString:@"macBroker"]) return MSIDMacBrokerSsoProvider;

return MSIDUnknownSsoProvider;
}

@end
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@ - (void)testJsonDictionary_whenAllPropertiesSet_shouldReturnJson

NSDictionary *json = [response jsonDictionary];
#if TARGET_OS_OSX
XCTAssertEqual(11, json.allKeys.count);
XCTAssertEqual(12, json.allKeys.count);
XCTAssertEqualObjects(json[MSID_BROKER_BROKER_TYPE_KEY], @"unknown");
#else
XCTAssertEqual(10, json.allKeys.count);
#endif
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,8 @@ - (void)testJsonDictionary_whenInitWithDictionary_shouldBeConvertedBackToDiction
@"wpj_status": @"notJoined",
@"preferred_auth_config": @"preferredAuthNotConfigured",
#if TARGET_OS_OSX
@"platform_sso_status": @"platformSSONotEnabled"
@"platform_sso_status": @"platformSSONotEnabled",
@"broker_type": @"unknown"
#endif
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,8 @@ - (void)testJsonDictionary_whenInitWithDictionary_shouldBeConvertedBackToDiction
@"wpj_status": @"notJoined",
@"preferred_auth_config": @"preferredAuthNotConfigured",
#if TARGET_OS_OSX
@"platform_sso_status": @"platformSSONotEnabled"
@"platform_sso_status": @"platformSSONotEnabled",
@"broker_type": @"unknown"
#endif
};

Expand Down
8 changes: 5 additions & 3 deletions IdentityCore/tests/MSIDBrokerOperationResponseTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,12 @@ - (void)testJsonDictionary_whenAllPropertiesSet_shouldReturnJson
response.operation = @"login";
response.success = true;
response.clientAppVersion = @"1.0";
response.deviceInfo = [[MSIDDeviceInfo alloc] initWithDeviceMode:MSIDDeviceModeShared ssoExtensionMode:MSIDSSOExtensionModeSilentOnly isWorkPlaceJoined:YES brokerVersion:@"1.2.3"];
response.deviceInfo = [[MSIDDeviceInfo alloc] initWithDeviceMode:MSIDDeviceModeShared ssoExtensionMode:MSIDSSOExtensionModeSilentOnly isWorkPlaceJoined:YES brokerVersion:@"1.2.3" ssoProviderType:MSIDCompanyPortalSsoProvider];

NSDictionary *json = [response jsonDictionary];
#if TARGET_OS_OSX
XCTAssertEqual(10, json.allKeys.count);
XCTAssertEqual(11, json.allKeys.count);
XCTAssertEqualObjects(json[MSID_BROKER_BROKER_TYPE_KEY], @"companyPortal");
#else
XCTAssertEqual(9, json.allKeys.count);
#endif
Expand All @@ -93,7 +94,8 @@ - (void)testJsonDictionary_whenRequiredPropertiesSet_shouldReturnJson

NSDictionary *json = [response jsonDictionary];
#if TARGET_OS_OSX
XCTAssertEqual(8, json.allKeys.count);
XCTAssertEqual(9, json.allKeys.count);
XCTAssertEqualObjects(json[MSID_BROKER_BROKER_TYPE_KEY], @"unknown");
#else
XCTAssertEqual(7, json.allKeys.count);
#endif
Expand Down
10 changes: 6 additions & 4 deletions IdentityCore/tests/MSIDBrokerOperationTokenResponseTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ - (void)testJsonDictionary_whenAllPropertiesSetForSuccessResponse_shouldReturnJs
tokenResponse.idToken = [MSIDTestIdTokenUtil idTokenWithPreferredUsername:DEFAULT_TEST_ID_TOKEN_USERNAME
subject:DEFAULT_TEST_ID_TOKEN_SUBJECT];
__auto_type response = [[MSIDBrokerOperationTokenResponse alloc] initWithDeviceInfo:[MSIDDeviceInfo new]];
response.deviceInfo.ssoProviderType = MSIDMacBrokerSsoProvider;;
response.operation = @"login";
response.success = true;
response.clientAppVersion = @"1.0";
Expand All @@ -61,7 +62,8 @@ - (void)testJsonDictionary_whenAllPropertiesSetForSuccessResponse_shouldReturnJs

NSDictionary *json = [response jsonDictionary];
#if TARGET_OS_OSX
XCTAssertEqual(22, json.allKeys.count);
XCTAssertEqual(23, json.allKeys.count);
XCTAssertEqualObjects(json[@"broker_type"], @"macBroker");
#else
XCTAssertEqual(21, json.allKeys.count);
#endif
Expand Down Expand Up @@ -108,7 +110,7 @@ - (void)testJsonDictionary_whenNoAdditionalTokenResponseForSuccessResponse_shoul

NSDictionary *json = [response jsonDictionary];
#if TARGET_OS_OSX
XCTAssertEqual(21, json.allKeys.count);
XCTAssertEqual(22, json.allKeys.count);
#else
XCTAssertEqual(20, json.allKeys.count);
#endif
Expand Down Expand Up @@ -181,7 +183,7 @@ - (void)testJsonDictionary_whenNoAuthorityForFailureResponse_shouldReturnJson

NSDictionary *json = [response jsonDictionary];
#if TARGET_OS_OSX
XCTAssertEqual(21, json.allKeys.count);
XCTAssertEqual(22, json.allKeys.count);
#else
XCTAssertEqual(20, json.allKeys.count);
#endif
Expand Down Expand Up @@ -222,7 +224,7 @@ - (void)testJsonDictionary_whenNoAdditionalTokenResponseForFailureResponse_shoul

NSDictionary *json = [response jsonDictionary];
#if TARGET_OS_OSX
XCTAssertEqual(20, json.allKeys.count);
XCTAssertEqual(21, json.allKeys.count);
#else
XCTAssertEqual(19, json.allKeys.count);
#endif
Expand Down
37 changes: 34 additions & 3 deletions IdentityCore/tests/MSIDDeviceInfoTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,8 @@ - (void)testJsonDictionary_whenDeserialize_shouldGenerateCorrectJson {
MSID_BROKER_BROKER_VERSION_KEY : @"1.2.3",
MSID_PLATFORM_SSO_STATUS_KEY : @"platformSSONotEnabled",
MSID_ADDITIONAL_EXTENSION_DATA_KEY: @"{\"dict\":{\"key\":\"value\"},\"feature_flag1\":1,\"token\":\"\"}",
MSID_BROKER_PREFERRED_AUTH_CONFIGURATION_KEY : @"preferredAuthNotConfigured"
MSID_BROKER_PREFERRED_AUTH_CONFIGURATION_KEY : @"preferredAuthNotConfigured",
MSID_BROKER_BROKER_TYPE_KEY : @"unknown"
};
#else
NSDictionary *expectedJson = @{
Expand Down Expand Up @@ -284,7 +285,8 @@ - (void)testJsonDictionaryFromOldSDK_whenDeserialize_shouldGenerateCorrectJson {
MSID_BROKER_BROKER_VERSION_KEY : @"1.2.3",
MSID_PLATFORM_SSO_STATUS_KEY : @"platformSSONotEnabled",
MSID_ADDITIONAL_EXTENSION_DATA_KEY: @"{\"dict\":{\"key\":\"value\"},\"feature_flag1\":1,\"token\":\"\"}",
MSID_BROKER_PREFERRED_AUTH_CONFIGURATION_KEY : @"preferredAuthNotConfigured"
MSID_BROKER_PREFERRED_AUTH_CONFIGURATION_KEY : @"preferredAuthNotConfigured",
MSID_BROKER_BROKER_TYPE_KEY : @"unknown"
};
#else
NSDictionary *expectedJson = @{
Expand Down Expand Up @@ -332,6 +334,7 @@ - (void)testJsonDictionaryWithPlatformSSOStatus_whenDeserialize_shouldGenerateCo
deviceInfo.wpjStatus = MSIDWorkPlaceJoinStatusJoined;
deviceInfo.brokerVersion = @"1.2.3";
deviceInfo.platformSSOStatus = MSIDPlatformSSOEnabledAndRegistered;
deviceInfo.ssoProviderType = MSIDMacBrokerSsoProvider;

NSDictionary *additionalData = @{@"feature_flag1":@1,@"token":@"",@"dict":@{@"key":@"value"}};
deviceInfo.additionalExtensionData = additionalData;
Expand All @@ -344,7 +347,35 @@ - (void)testJsonDictionaryWithPlatformSSOStatus_whenDeserialize_shouldGenerateCo
MSID_PLATFORM_SSO_STATUS_KEY :
@"platformSSOEnabledAndRegistered",
MSID_BROKER_PREFERRED_AUTH_CONFIGURATION_KEY : @"preferredAuthNotConfigured",
MSID_ADDITIONAL_EXTENSION_DATA_KEY: @"{\"dict\":{\"key\":\"value\"},\"feature_flag1\":1,\"token\":\"\"}"
MSID_ADDITIONAL_EXTENSION_DATA_KEY: @"{\"dict\":{\"key\":\"value\"},\"feature_flag1\":1,\"token\":\"\"}",
MSID_BROKER_BROKER_TYPE_KEY : @"macBroker",
};

XCTAssertEqualObjects(expectedJson, [deviceInfo jsonDictionary]);
}

- (void)testJsonDictionaryWithCompanyPortalAsSsoProvider_whenDeserialize_shouldGenerateCorrectJson
{
MSIDDeviceInfo *deviceInfo = [MSIDDeviceInfo new];
deviceInfo.deviceMode = MSIDDeviceModePersonal;
deviceInfo.wpjStatus = MSIDWorkPlaceJoinStatusJoined;
deviceInfo.brokerVersion = @"1.2.3";
deviceInfo.platformSSOStatus = MSIDPlatformSSOEnabledAndRegistered;
deviceInfo.ssoProviderType = MSIDCompanyPortalSsoProvider;

NSDictionary *additionalData = @{@"feature_flag1":@1,@"token":@"",@"dict":@{@"key":@"value"}};
deviceInfo.additionalExtensionData = additionalData;

NSDictionary *expectedJson = @{
MSID_BROKER_DEVICE_MODE_KEY : @"personal",
MSID_BROKER_SSO_EXTENSION_MODE_KEY : @"full",
MSID_BROKER_WPJ_STATUS_KEY : @"joined",
MSID_BROKER_BROKER_VERSION_KEY : @"1.2.3",
MSID_PLATFORM_SSO_STATUS_KEY :
@"platformSSOEnabledAndRegistered",
MSID_BROKER_PREFERRED_AUTH_CONFIGURATION_KEY : @"preferredAuthNotConfigured",
MSID_ADDITIONAL_EXTENSION_DATA_KEY: @"{\"dict\":{\"key\":\"value\"},\"feature_flag1\":1,\"token\":\"\"}",
MSID_BROKER_BROKER_TYPE_KEY : @"companyPortal",
};

XCTAssertEqualObjects(expectedJson, [deviceInfo jsonDictionary]);
Expand Down
Loading