Skip to content

Commit

Permalink
Merge branch 'dev' into jarias/update-deprecated-openURL-method
Browse files Browse the repository at this point in the history
# Conflicts:
#	changelog.txt
  • Loading branch information
juan-arias committed Oct 5, 2024
2 parents 00b4cfb + 78912f7 commit e9b04c4
Show file tree
Hide file tree
Showing 8 changed files with 190 additions and 0 deletions.
4 changes: 4 additions & 0 deletions IdentityCore/IdentityCore.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -8108,6 +8108,7 @@
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = "1,2,7";
XROS_DEPLOYMENT_TARGET = 1.2;
};
name = Debug;
};
Expand Down Expand Up @@ -8169,6 +8170,7 @@
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = "1,2,7";
VALIDATE_PRODUCT = YES;
XROS_DEPLOYMENT_TARGET = 1.2;
};
name = Release;
};
Expand Down Expand Up @@ -8227,6 +8229,7 @@
SDKROOT = iphoneos;
SUPPORTED_PLATFORMS = "iphoneos iphonesimulator xros xrsimulator";
TARGETED_DEVICE_FAMILY = "1,2,7";
XROS_DEPLOYMENT_TARGET = 1.2;
};
name = Debug;
};
Expand Down Expand Up @@ -8279,6 +8282,7 @@
SUPPORTED_PLATFORMS = "iphoneos iphonesimulator xros xrsimulator";
TARGETED_DEVICE_FAMILY = "1,2,7";
VALIDATE_PRODUCT = YES;
XROS_DEPLOYMENT_TARGET = 1.2;
};
name = Release;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,15 @@ NS_ASSUME_NONNULL_BEGIN
@interface MSIDBrokerOperationBrowserNativeMessageRequest : MSIDBrokerOperationRequest

@property (nonatomic) NSDictionary *payloadJson;
@property (nonatomic) NSString *parentProcessBundleIdentifier;
@property (nonatomic) NSString *parentProcessTeamId;
@property (nonatomic) NSString *parentProcessLocalizedName;

@property (nonatomic, readonly) NSString *callerBundleIdentifier;
@property (nonatomic, readonly) NSString *callerTeamIdentifier API_AVAILABLE(ios(14.0), macos(11.0)) API_UNAVAILABLE(watchos, tvos);
@property (nonatomic, readonly) NSString *localizedCallerDisplayName API_AVAILABLE(ios(14.0), macos(11.0)) API_UNAVAILABLE(watchos, tvos);
@property (nonatomic, readonly) NSString *localizedApplicationInfo API_AVAILABLE(ios(14.0), macos(11.0)) API_UNAVAILABLE(watchos, tvos);

@property (nonatomic, readonly) NSString *method;

@end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,13 @@
#import "MSIDJsonSerializableTypes.h"
#import "MSIDJsonSerializableFactory.h"
#import "NSDictionary+MSIDExtensions.h"
#import "MSIDBrowserNativeMessageRequest.h"

NSString *const MSID_BROWSER_NATIVE_MESSAGE_REQUEST_PAYLOAD_KEY = @"payload";
NSString *const MSID_BROWSER_NATIVE_MESSAGE_REQUEST_METHOD_KEY = @"method";
NSString *const MSID_BROWSER_NATIVE_MESSAGE_REQUEST_PPTID_KEY = @"parent_process_teamId";
NSString *const MSID_BROWSER_NATIVE_MESSAGE_REQUEST_PPBI_KEY = @"parent_process_bundle_identifier";
NSString *const MSID_BROWSER_NATIVE_MESSAGE_REQUEST_PPLN_KEY = @"parent_process_localized_name";

@implementation MSIDBrokerOperationBrowserNativeMessageRequest

Expand All @@ -50,6 +54,37 @@ + (NSString *)operation
return MSID_JSON_TYPE_OPERATION_REQUEST_BROWSER_NATIVE_MESSAGE;
}

- (NSString *)callerBundleIdentifier
{
return self.parentProcessBundleIdentifier ?: NSLocalizedString(@"N/A", nil);
}

- (NSString *)callerTeamIdentifier
{
return self.parentProcessTeamId ?: NSLocalizedString(@"N/A", nil);
}

- (NSString *)localizedCallerDisplayName
{
return self.parentProcessLocalizedName ?: NSLocalizedString(@"N/A", nil);
}

- (NSString *)localizedApplicationInfo
{
NSString *method = self.payloadJson[MSID_BROWSER_NATIVE_MESSAGE_REQUEST_METHOD_KEY];
MSIDBrowserNativeMessageRequest *brokerOperationRequest = [MSIDJsonSerializableFactory createFromJSONDictionary:self.payloadJson
classType:method
assertKindOfClass:MSIDBrowserNativeMessageRequest.class
error:nil];

if (![NSString msidIsStringNilOrBlank:brokerOperationRequest.localizedApplicationInfo])
{
return brokerOperationRequest.localizedApplicationInfo;
}

return NSLocalizedString(@"N/A", nil);
}

#pragma mark - MSIDJsonSerializable

- (instancetype)initWithJSONDictionary:(NSDictionary *)json error:(NSError *__autoreleasing*)error
Expand Down Expand Up @@ -81,6 +116,10 @@ - (instancetype)initWithJSONDictionary:(NSDictionary *)json error:(NSError *__au

return nil;
}

_parentProcessTeamId = [json msidStringObjectForKey:MSID_BROWSER_NATIVE_MESSAGE_REQUEST_PPTID_KEY];
_parentProcessBundleIdentifier = [json msidStringObjectForKey:MSID_BROWSER_NATIVE_MESSAGE_REQUEST_PPBI_KEY];
_parentProcessLocalizedName = [json msidStringObjectForKey:MSID_BROWSER_NATIVE_MESSAGE_REQUEST_PPLN_KEY];
}

return self;
Expand All @@ -94,6 +133,10 @@ - (NSDictionary *)jsonDictionary

json[MSID_BROWSER_NATIVE_MESSAGE_REQUEST_PAYLOAD_KEY] = [self.payloadJson msidJSONSerializeWithContext:nil];

json[MSID_BROWSER_NATIVE_MESSAGE_REQUEST_PPTID_KEY] = self.parentProcessTeamId;
json[MSID_BROWSER_NATIVE_MESSAGE_REQUEST_PPBI_KEY] = self.parentProcessBundleIdentifier;
json[MSID_BROWSER_NATIVE_MESSAGE_REQUEST_PPLN_KEY] = self.parentProcessLocalizedName;

return json;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,22 @@ + (NSString *)operation
return @"GetToken";
}

#pragma mark - MSIDBrokerOperationRequest

- (NSString *)localizedApplicationInfo
{
// clientId && redirectUri are requered params and should be validated during init.
NSParameterAssert(self.clientId);
NSParameterAssert(self.redirectUri);
__auto_type clientId = self.clientId ?: @"";
__auto_type redirectUri = self.redirectUri ?: @"";

NSString *clientIdKey = NSLocalizedString(@"Client ID", nil);
NSString *redirectUriKey = NSLocalizedString(@"Redirect URI", nil);

return [NSString stringWithFormat:@"%@: %@ %@: %@", clientIdKey, clientId, redirectUriKey, redirectUri];
}

#pragma mark - MSIDJsonSerializable

- (instancetype)initWithJSONDictionary:(NSDictionary *)json error:(NSError *__autoreleasing*)error
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ NS_ASSUME_NONNULL_BEGIN
/// Url of the request sender.
@property (nonatomic) NSURL *sender;

@property (nonatomic, readonly) NSString *localizedApplicationInfo;

@end

NS_ASSUME_NONNULL_END
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,33 @@

#import <XCTest/XCTest.h>
#import "MSIDBrokerOperationBrowserNativeMessageRequest.h"
#import "MSIDJsonSerializableFactory.h"
#import "MSIDBrowserNativeMessageRequest.h"

@interface MSIDBrokerOperationBrowserNativeMockRequest : MSIDBrowserNativeMessageRequest

@end

@implementation MSIDBrokerOperationBrowserNativeMockRequest

#pragma mark - MSIDBrokerOperationRequest

- (NSString *)localizedApplicationInfo
{
return @"mock_app_info";
}

- (instancetype)initWithJSONDictionary:(NSDictionary *)json error:(NSError *__autoreleasing *)error
{
return [self init];
}

- (NSDictionary *)jsonDictionary
{
return @{};
}

@end

@interface MSIDBrokerOperationBrowserNativeMessageRequestTests : XCTestCase

Expand All @@ -34,6 +61,7 @@ @implementation MSIDBrokerOperationBrowserNativeMessageRequestTests

- (void)setUp
{
[MSIDJsonSerializableFactory registerClass:MSIDBrokerOperationBrowserNativeMockRequest.class forClassType:@"BrowserNativeMockRequest"];
}

- (void)tearDown
Expand All @@ -60,12 +88,68 @@ - (void)testJsonDictionary_whenPayloadExist_shouldBeCorrect
request.payloadJson = @{@"a": @"b"};
request.brokerKey = @"some key";
request.protocolVersion = 1;
request.parentProcessBundleIdentifier = @"com.qwe";
request.parentProcessTeamId = @"12345";
request.parentProcessLocalizedName = @"name1";

__auto_type expectedJson = @{@"broker_key": @"some key",
@"msg_protocol_ver": @"1",
@"parent_process_bundle_identifier": @"com.qwe",
@"parent_process_localized_name": @"name1",
@"parent_process_teamId": @"12345",
@"payload": @"{\"a\":\"b\"}"};
XCTAssertEqualObjects(expectedJson, [request jsonDictionary]);
}

- (void)testInitWithJSONDictionary_whenAllValuesSet_shoudlInit
{
__auto_type json = @{@"broker_key": @"some key",
@"msg_protocol_ver": @"1",
@"parent_process_bundle_identifier": @"com.qwe",
@"parent_process_teamId": @"12345",
@"parent_process_localized_name": @"name1",
@"payload": @"{\"method\":\"BrowserNativeMockRequest\"}"};

NSError *error;
__auto_type request = [[MSIDBrokerOperationBrowserNativeMessageRequest alloc] initWithJSONDictionary:json error:&error];

XCTAssertNil(error);
XCTAssertEqualObjects(request.brokerKey, @"some key");
XCTAssertEqual(request.protocolVersion, 1);
XCTAssertEqualObjects(request.payloadJson, @{@"method":@"BrowserNativeMockRequest"});
XCTAssertEqualObjects(request.parentProcessBundleIdentifier, @"com.qwe");
XCTAssertEqualObjects(request.parentProcessTeamId, @"12345");
XCTAssertEqualObjects(request.parentProcessLocalizedName, @"name1");
XCTAssertEqualObjects(request.callerBundleIdentifier, @"com.qwe");
if (@available(macOS 11.0, *)) {
XCTAssertEqualObjects(request.callerTeamIdentifier, @"12345");
XCTAssertEqualObjects(request.localizedCallerDisplayName, @"name1");
XCTAssertEqualObjects(request.localizedApplicationInfo, @"mock_app_info");
}
}

- (void)testInitWithJSONDictionary_whenNoParentProcessInfo_shouldReturnNA
{
__auto_type json = @{@"broker_key": @"some key",
@"msg_protocol_ver": @"1",
@"payload": @"{\"method\":\"GetCookies\"}"};

NSError *error;
__auto_type request = [[MSIDBrokerOperationBrowserNativeMessageRequest alloc] initWithJSONDictionary:json error:&error];

XCTAssertNil(error);
XCTAssertEqualObjects(request.brokerKey, @"some key");
XCTAssertEqual(request.protocolVersion, 1);
XCTAssertEqualObjects(request.payloadJson, @{@"method":@"GetCookies"});
XCTAssertEqualObjects(request.callerBundleIdentifier, @"N/A");
if (@available(macOS 11.0, *)) {
XCTAssertEqualObjects(request.callerTeamIdentifier, @"N/A");
XCTAssertEqualObjects(request.localizedCallerDisplayName, @"N/A");
XCTAssertEqualObjects(request.localizedApplicationInfo, @"N/A");
}
XCTAssertNil(request.parentProcessBundleIdentifier);
XCTAssertNil(request.parentProcessTeamId);
XCTAssertNil(request.parentProcessLocalizedName);
}

@end
31 changes: 31 additions & 0 deletions IdentityCore/tests/MSIDBrowserNativeMessageGetTokenRequestTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -167,4 +167,35 @@ - (void)testInitWithJSONDictionary_whenAccountIdInvalid_shouldFail
}


- (void)testLocalizedApplicationInfo_whenClientIdAndRedirectUri_shouldReturnClientIDandRedirectUri
{
__auto_type json = @{
@"sender": @"https://login.microsoft.com",
@"request": @{
@"accountId": @"uid.utid",
@"clientId": @"29a788ca-7bcf-4732-b23c-c8d294347e5b",
@"authority": @"https://login.microsoftonline.com/common",
@"scope": @"user.read openid profile offline_access",
@"redirectUri": @"https://login.microsoft.com",
@"correlationId": @"9BBCA391-33A9-4EC9-A00E-A0FBFA71013D",
@"prompt": @"login",
@"isSts": @(YES),
@"canShowUI": @(NO),
@"nonce": @"e98aba90-bc47-4ff9-8809-b6e1c7e7cd47",
@"state": @"state1",
@"loginHint": @"user@microsoft.com",
@"instance_aware": @(YES),
}
};

NSError *error;
__auto_type request = [[MSIDBrowserNativeMessageGetTokenRequest alloc] initWithJSONDictionary:json error:&error];

XCTAssertNil(error);
XCTAssertNotNil(request);
if (@available(macOS 11.0, *)) {
XCTAssertEqualObjects(@"Client ID: 29a788ca-7bcf-4732-b23c-c8d294347e5b Redirect URI: https://login.microsoft.com", request.localizedApplicationInfo);
}
}

@end
1 change: 1 addition & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
Version TBD
* Support extra query parameters on signout (#1243)
* Wrap ASAuthorizationProviderExtensionAuthorizationRequest methods (#1427)
* Replace deprecated method UIApplication.openURL(_:) (#1424)

Version 1.7.41
Expand Down

0 comments on commit e9b04c4

Please sign in to comment.