Skip to content

Commit

Permalink
Merge pull request #1412 from AzureAD/mipetriu/visionOS_final
Browse files Browse the repository at this point in the history
IdentityCore visionOS support
  • Loading branch information
mipetriu authored Sep 4, 2024
2 parents ef53d43 + ab42695 commit 966af8e
Show file tree
Hide file tree
Showing 20 changed files with 184 additions and 25 deletions.
22 changes: 20 additions & 2 deletions IdentityCore/IdentityCore.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -8083,10 +8083,11 @@
PRODUCT_NAME = "$(TARGET_NAME)";
SDKROOT = iphoneos;
SKIP_INSTALL = YES;
SUPPORTED_PLATFORMS = "iphonesimulator iphoneos xrsimulator xros";
SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG;
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = "1,2";
TARGETED_DEVICE_FAMILY = "1,2,7";
};
name = Debug;
};
Expand Down Expand Up @@ -8143,9 +8144,10 @@
PRODUCT_NAME = "$(TARGET_NAME)";
SDKROOT = iphoneos;
SKIP_INSTALL = YES;
SUPPORTED_PLATFORMS = "iphonesimulator iphoneos xrsimulator xros";
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = "1,2";
TARGETED_DEVICE_FAMILY = "1,2,7";
VALIDATE_PRODUCT = YES;
};
name = Release;
Expand Down Expand Up @@ -8203,6 +8205,8 @@
PRODUCT_BUNDLE_IDENTIFIER = com.microsoft.MSIDTestsHostApp;
PRODUCT_NAME = "$(TARGET_NAME)";
SDKROOT = iphoneos;
SUPPORTED_PLATFORMS = "iphoneos iphonesimulator xros xrsimulator";
TARGETED_DEVICE_FAMILY = "1,2,7";
};
name = Debug;
};
Expand Down Expand Up @@ -8252,6 +8256,8 @@
PRODUCT_BUNDLE_IDENTIFIER = com.microsoft.MSIDTestsHostApp;
PRODUCT_NAME = "$(TARGET_NAME)";
SDKROOT = iphoneos;
SUPPORTED_PLATFORMS = "iphoneos iphonesimulator xros xrsimulator";
TARGETED_DEVICE_FAMILY = "1,2,7";
VALIDATE_PRODUCT = YES;
};
name = Release;
Expand Down Expand Up @@ -8776,9 +8782,11 @@
IPHONEOS_DEPLOYMENT_TARGET = 14.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PROVISIONING_PROFILE_SPECIFIER = "";
SUPPORTED_PLATFORMS = "iphoneos iphonesimulator xros xrsimulator";
SWIFT_OBJC_BRIDGING_HEADER = "tests/IdentityCoreTests iOS-Bridging-Header.h";
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = "1,2,7";
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/MSIDTestsHostApp.app/MSIDTestsHostApp";
};
name = Debug;
Expand All @@ -8796,8 +8804,10 @@
IPHONEOS_DEPLOYMENT_TARGET = 14.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PROVISIONING_PROFILE_SPECIFIER = "";
SUPPORTED_PLATFORMS = "iphoneos iphonesimulator xros xrsimulator";
SWIFT_OBJC_BRIDGING_HEADER = "tests/IdentityCoreTests iOS-Bridging-Header.h";
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = "1,2,7";
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/MSIDTestsHostApp.app/MSIDTestsHostApp";
};
name = Release;
Expand Down Expand Up @@ -8866,6 +8876,8 @@
ENABLE_BITCODE = NO;
GCC_OPTIMIZATION_LEVEL = 0;
IPHONEOS_DEPLOYMENT_TARGET = 14.0;
SUPPORTED_PLATFORMS = "iphonesimulator iphoneos xros xrsimulator";
TARGETED_DEVICE_FAMILY = "1,2,7";
};
name = Debug;
};
Expand All @@ -8875,6 +8887,8 @@
buildSettings = {
ENABLE_BITCODE = NO;
IPHONEOS_DEPLOYMENT_TARGET = 14.0;
SUPPORTED_PLATFORMS = "iphonesimulator iphoneos xros xrsimulator";
TARGETED_DEVICE_FAMILY = "1,2,7";
};
name = Release;
};
Expand Down Expand Up @@ -8941,6 +8955,8 @@
"$(MSID_SYSTEMWV)",
);
IPHONEOS_DEPLOYMENT_TARGET = 14.0;
SUPPORTED_PLATFORMS = "iphonesimulator iphoneos xrsimulator xros";
TARGETED_DEVICE_FAMILY = "1,2,7";
};
name = Debug;
};
Expand All @@ -8954,6 +8970,8 @@
"$(MSID_WEBKIT)",
);
IPHONEOS_DEPLOYMENT_TARGET = 14.0;
SUPPORTED_PLATFORMS = "iphonesimulator iphoneos xrsimulator xros";
TARGETED_DEVICE_FAMILY = "1,2,7";
};
name = Release;
};
Expand Down
8 changes: 7 additions & 1 deletion IdentityCore/src/oauth2/MSIDWebviewFactory.m
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,10 @@ @implementation MSIDWebviewFactory
{
MSIDWebviewType webviewType = [MSIDSystemWebViewControllerFactory availableWebViewTypeWithPreferredType:requestParameters.webviewType];

#if !MSID_EXCLUDE_SYSTEMWV
BOOL useSession = YES;
BOOL allowSafariViewController = NO;
#endif

switch (webviewType)
{
Expand All @@ -81,11 +83,15 @@ @implementation MSIDWebviewFactory
default:
break;
}


#if !MSID_EXCLUDE_SYSTEMWV
return [self systemWebviewFromConfiguration:configuration
useAuthenticationSession:useSession
allowSafariViewController:allowSafariViewController
context:context];
#else
return nil;
#endif
}

- (NSObject<MSIDWebviewInteracting> *)embeddedWebviewFromConfiguration:(MSIDBaseWebRequestConfiguration *)configuration
Expand Down
4 changes: 4 additions & 0 deletions IdentityCore/src/util/ios/MSIDAppExtensionUtil.m
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,11 @@ + (void)sharedApplicationOpenURL:(NSURL*)url
#pragma clang diagnostic ignored "-Warc-performSelector-leaks"

[MSIDMainThreadUtil executeOnMainThreadIfNeeded:^{
#if defined TARGET_OS_VISION && TARGET_OS_VISION
[[self sharedApplication] openURL:url options:@{} completionHandler:nil];
#else
[[self sharedApplication] performSelector:NSSelectorFromString(@"openURL:") withObject:url];
#endif
}];
#pragma clang diagnostic pop
}
Expand Down
13 changes: 13 additions & 0 deletions IdentityCore/src/util/ios/UIApplication+MSIDExtensions.m
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,20 @@ + (UIViewController *)msidCurrentViewController:(UIViewController *)parentContro

if ([MSIDAppExtensionUtil isExecutingInAppExtension]) return nil;

#if defined TARGET_OS_VISION && TARGET_OS_VISION
NSArray<UIScene *> *scenes; NSArray<UIWindow *> *windows;

scenes = [[[MSIDAppExtensionUtil sharedApplication] connectedScenes] allObjects];

if (scenes && scenes.count != 0)
{
windows = [(UIWindowScene *)[scenes objectAtIndex:0] windows];
}

for (UIWindow *window in windows)
#else
for (UIWindow *window in [MSIDAppExtensionUtil sharedApplication].windows)
#endif
{
if (window.isKeyWindow)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,9 @@ + (BOOL)isCertAuthInProgress

+ (void)resetHandler
{
#if TARGET_OS_IPHONE && !MSID_EXCLUDE_SYSTEMWV
s_certAuthInProgress = NO;
#endif
}

+ (BOOL)handleChallenge:(NSURLAuthenticationChallenge *)challenge
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,51 @@
#import "MSIDBackgroundTaskManager.h"
#import "MSIDMainThreadUtil.h"

#if defined TARGET_OS_VISION && TARGET_OS_VISION
static inline CGRect ActiveScreenBounds(void)
{
// this code is also compiled for extensions where UIApplication.sharedApplication is not available
UIApplication *sharedApp = nil;
if ([UIApplication respondsToSelector:NSSelectorFromString(@"sharedApplication")])
{
sharedApp = [UIApplication performSelector:NSSelectorFromString(@"sharedApplication")];
}

UIWindowScene *activeScene = nil;
for (UIWindowScene *scene in sharedApp.connectedScenes)
{
if (scene.activationState == UISceneActivationStateForegroundActive)
{
activeScene = scene;
break;
}
}

if ((activeScene == nil) && (sharedApp.connectedScenes.count > 0))
{
activeScene = (UIWindowScene *)sharedApp.connectedScenes.anyObject;
}

if (activeScene != nil)
{
return activeScene.coordinateSpace.bounds;
}

return CGRectZero;
}

static inline CGRect ActiveSceneBoundsForView(UIView *view)
{
UIWindowScene *activeScene = view.window.windowScene;
if(activeScene != nil)
{
return activeScene.coordinateSpace.bounds;
}

return ActiveScreenBounds();
}
#endif

static WKWebViewConfiguration *s_webConfig;

@interface MSIDWebviewUIController ()
Expand Down Expand Up @@ -127,7 +172,12 @@ - (BOOL)loadView:(NSError *__autoreleasing*)error
return NO;
}
UIView *rootView = [self view];
[rootView setFrame:[[UIScreen mainScreen] bounds]];
#if defined TARGET_OS_VISION && TARGET_OS_VISION
CGRect screenBounds = ActiveSceneBoundsForView(rootView);
#else
CGRect screenBounds = [[UIScreen mainScreen] bounds];
#endif
[rootView setFrame:screenBounds];
[rootView setAutoresizesSubviews:YES];
[rootView setAutoresizingMask:UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
//
//------------------------------------------------------------------------------

#if !MSID_EXCLUDE_SYSTEMWV
#if !MSID_EXCLUDE_SYSTEMWV && !(defined TARGET_OS_VISION && TARGET_OS_VISION)

#import "MSIDSafariViewController.h"
#import "MSIDSystemWebviewController.h"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,15 @@ + (MSIDWebviewType)availableWebViewTypeWithPreferredType:(MSIDWebviewType)prefer
{
return authSession;
}


#if !MSID_EXCLUDE_SYSTEMWV && !(defined TARGET_OS_VISION && TARGET_OS_VISION)
return [[MSIDSafariViewController alloc] initWithURL:startURL
parentController:parentController
presentationType:presentationType
context:context];
#else
return nil;
#endif
}

#endif
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@
#if TARGET_OS_IPHONE
#import "MSIDBackgroundTaskManager.h"
#import "UIApplication+MSIDExtensions.h"
#if !defined TARGET_OS_VISION || !TARGET_OS_VISION
#import "MSIDSafariViewController.h"
#endif
#import "MSIDURLResponseHandling.h"
#endif
#import "MSIDTelemetry+Internal.h"
Expand Down Expand Up @@ -223,6 +225,11 @@ - (void)dismiss
useEmpheralSession:self.prefersEphemeralWebBrowserSession
context:self.context];
}

#if defined TARGET_OS_VISION && TARGET_OS_VISION
MSID_LOG_WITH_CTX(MSIDLogLevelInfo, nil, @"Couldn't create session on visionOS. Safari allowed flag %d", safariAllowed);
return nil;
#else

#if TARGET_OS_IPHONE

Expand All @@ -241,6 +248,7 @@ - (void)dismiss
#endif

return nil;
#endif
}

- (void)notifyEndWebAuthWithURL:(NSURL *)url
Expand Down
2 changes: 1 addition & 1 deletion IdentityCore/tests/MSIDAccountCredentialsCacheTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ - (void)setUp
{
id<MSIDExtendedTokenCacheDataSource> dataSource = nil;

#if TARGET_OS_IOS
#if !TARGET_OS_OSX
dataSource = [[MSIDKeychainTokenCache alloc] initWithGroup:nil error:nil];
#else
// TODO: this should be replaced with a real macOS datasource instead
Expand Down
3 changes: 2 additions & 1 deletion IdentityCore/tests/MSIDAccountMetadataCacheAccessorTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -599,9 +599,10 @@ - (void)testRemoveAccountMetadataForHomeAccountId_whenHomeAccountNotNil_shouldRe
XCTAssertNil(error);
XCTAssertEqual(accountMetadataItems.count, 2);

MSIDAccountMetadataCacheItem *firstItem = accountMetadataItems[0];
MSIDAccountMetadataCacheItem *cacheItem1;
MSIDAccountMetadataCacheItem *cacheItem2;
if ([[accountMetadataItems[0] clientId] isEqualToString:@"my-client-id-1"])
if ([[firstItem clientId] isEqualToString:@"my-client-id-1"])
{
cacheItem1 = accountMetadataItems[0];
cacheItem2 = accountMetadataItems[1];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ - (void)testAcquireToken_whenBrokerInstallPrompt_andSuccessfulResponse_shouldRet
[expectation fulfill];
}];

[self waitForExpectationsWithTimeout:3.0 handler:nil];
[self waitForExpectationsWithTimeout:7.0 handler:nil];
}

- (void)testAcquireToken_whenWPJRequest_shouldReturnWorkplaceJoinRequiredError
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1982,17 +1982,18 @@ - (void)testClearCacheForAccount_whenTokensInCacheInMultipleAccessors_shouldRemo
XCTAssertEqual([remainingAccessTokens count], 1);
MSIDLegacyAccessToken *remainingAccessToken = remainingAccessTokens[0];
XCTAssertEqualObjects(remainingAccessToken.accountIdentifier.displayableId, @"upn@test.com");
XCTAssertEqualObjects([remainingAccessTokens[0] clientId], @"test_client_id2");
XCTAssertEqualObjects([remainingAccessToken clientId], @"test_client_id2");

NSArray *remaininRefreshTokens = [MSIDTestCacheAccessorHelper getAllLegacyRefreshTokens:_legacyAccessor];
XCTAssertEqual([remaininRefreshTokens count], 1);
MSIDLegacyRefreshToken *remainingRefreshToken = remaininRefreshTokens[0];
XCTAssertEqualObjects(remainingRefreshToken.accountIdentifier.displayableId, @"upn@test.com");
XCTAssertEqualObjects([remaininRefreshTokens[0] clientId], @"test_client_id2");
XCTAssertEqualObjects([remainingRefreshToken clientId], @"test_client_id2");

NSArray *otherRemainingRefreshTokens = [MSIDTestCacheAccessorHelper getAllDefaultRefreshTokens:_otherAccessor];
XCTAssertEqual([otherRemainingRefreshTokens count], 1);
XCTAssertEqualObjects([otherRemainingRefreshTokens[0] clientId], @"test_client_id2");
MSIDLegacyRefreshToken *otherRemainingToken = otherRemainingRefreshTokens[0];
XCTAssertEqualObjects([otherRemainingToken clientId], @"test_client_id2");
}

- (void)testClearCacheForAccountAndClientId_whenTokensInCache_shouldRemoveCorrectTokens
Expand Down Expand Up @@ -2038,11 +2039,13 @@ - (void)testClearCacheForAccountAndClientId_whenTokensInCache_shouldRemoveCorrec

NSArray *remainingAccessTokens = [MSIDTestCacheAccessorHelper getAllLegacyAccessTokens:_legacyAccessor];
XCTAssertEqual([remainingAccessTokens count], 1);
XCTAssertEqualObjects([remainingAccessTokens[0] clientId], @"test_client_id2");
MSIDLegacyAccessToken *remainingAccessToken = remainingAccessTokens[0];
XCTAssertEqualObjects([remainingAccessToken clientId], @"test_client_id2");

NSArray *remaininRefreshTokens = [MSIDTestCacheAccessorHelper getAllLegacyRefreshTokens:_legacyAccessor];
XCTAssertEqual([remaininRefreshTokens count], 1);
XCTAssertEqualObjects([remaininRefreshTokens[0] clientId], @"test_client_id2");
NSArray *remainingRefreshTokens = [MSIDTestCacheAccessorHelper getAllLegacyRefreshTokens:_legacyAccessor];
XCTAssertEqual([remainingRefreshTokens count], 1);
MSIDLegacyRefreshToken *remainingRefreshToken = remainingRefreshTokens[0];
XCTAssertEqualObjects([remainingRefreshToken clientId], @"test_client_id2");
}

- (void)testRemoveAccessToken_whenNilTokenProvided_shouldReturnError
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -913,7 +913,7 @@ - (void)testInteractiveRequestFlow_whenNestedAuth_shouldReturnResultWithBrokerPa
[self waitForExpectationsWithTimeout:1 handler:nil];
}

#if TARGET_OS_IPHONE
#if TARGET_OS_IPHONE && !(defined TARGET_OS_VISION && TARGET_OS_VISION)
- (void)testInteractiveRequestFlow_whenOpenBrowserResponse_shouldOpenLink
{
__block NSUUID *correlationId = [NSUUID new];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
#import "MSIDTestWebviewInteractingViewController.h"
#import "MSIDWebviewAuthorization.h"

#if TARGET_OS_IPHONE
#if TARGET_OS_IPHONE && !MSID_EXCLUDE_SYSTEMWV
#import "MSIDSystemWebviewController.h"
#endif

Expand Down
3 changes: 2 additions & 1 deletion IdentityCore/xcconfig/identitycore__common__ios.xcconfig
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
SDKROOT = iphoneos
CODE_SIGN_IDENTITY = "iPhone Developer"
IPHONEOS_DEPLOYMENT_TARGET = 14.0
XROS_DEPLOYMENT_TARGET = 1.0
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"
TARGETED_DEVICE_FAMILY = 1,2
TARGETED_DEVICE_FAMILY = 1,2,7
ENABLE_BITCODE = YES
SKIP_INSTALL = YES
1 change: 1 addition & 0 deletions IdentityCore/xcconfig/identitycore__idlib__ios.xcconfig
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@

// Activate full bitcode on release configuration for real devices.
OTHER_CFLAGS[config=Release][sdk=iphoneos*] = $(OTHER_CFLAGS) -fembed-bitcode
OTHER_CFLAGS[config=Release][sdk=xros*] = $(OTHER_CFLAGS) -fembed-bitcode
Loading

0 comments on commit 966af8e

Please sign in to comment.