Skip to content

Commit 8ab2e4f

Browse files
chore: fix aswebauthenticationsession issue for automated tests
1 parent 86bdfd3 commit 8ab2e4f

File tree

2 files changed

+51
-1
lines changed

2 files changed

+51
-1
lines changed

Source/Immutable/Private/Immutable/Mac/ImmutableMac.cpp

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,19 @@
11
#include "ImmutableMac.h"
2+
3+
#include "Engine/GameEngine.h"
4+
25
#include "Immutable/ImmutablePassport.h"
36
#include "Immutable/ImmutableSubsystem.h"
4-
#include "Engine/GameEngine.h"
57

68
#if WITH_EDITOR
79
#include "Editor.h"
810
#endif
911

1012
ASWebAuthenticationSession *_authSession;
1113

14+
// Remove the global automation mode variable
15+
static NSString* _pendingRedirectScheme = nil;
16+
1217
@implementation ImmutableMac
1318

1419
- (instancetype)init {
@@ -67,6 +72,13 @@ ASWebAuthenticationSession *_authSession;
6772
}
6873

6974
- (void)launchUrl:(const char *)url forRedirectUri:(const char *)redirectUri {
75+
// For automation, use the browser-based method
76+
if (GIsAutomationTesting) {
77+
NSLog(@"Using automation mode for authentication (GIsAutomationTesting is true)");
78+
[self launchUrlInBrowser:url forRedirectUri:redirectUri];
79+
return;
80+
}
81+
7082
if (@available(macOS 10.15, *)) {
7183
NSURL *URL =
7284
[NSURL URLWithString:[[NSString alloc] initWithUTF8String:url]];
@@ -104,6 +116,43 @@ ASWebAuthenticationSession *_authSession;
104116
}
105117
}
106118

119+
- (void)launchUrlInBrowser:(const char *)url forRedirectUri:(const char *)redirectUri {
120+
// Add redundant check to ensure this only runs for automated testing
121+
if (!GIsAutomationTesting) {
122+
return;
123+
}
124+
125+
// Create URL object
126+
NSURL *URL = [NSURL URLWithString:[[NSString alloc] initWithUTF8String:url]];
127+
128+
// Extract the callback scheme from redirect URI
129+
NSString *redirectUriString = [[NSString alloc] initWithUTF8String:redirectUri];
130+
NSString *callbackURLScheme = [[redirectUriString componentsSeparatedByString:@":"] objectAtIndex:0];
131+
132+
// Store the redirect scheme for use when handling the callback
133+
_pendingRedirectScheme = callbackURLScheme;
134+
135+
// Register for custom URL scheme notifications (will need to be implemented in AppDelegate)
136+
[[NSNotificationCenter defaultCenter] addObserverForName:@"ImmutableCustomURLSchemeCallback"
137+
object:nil
138+
queue:[NSOperationQueue mainQueue]
139+
usingBlock:^(NSNotification *notification) {
140+
if (notification.userInfo) {
141+
NSString *callbackURLString = notification.userInfo[@"url"];
142+
if (callbackURLString) {
143+
UImmutablePassport* passport = [ImmutableMac getPassport];
144+
if (passport) {
145+
passport->HandleDeepLink(callbackURLString);
146+
}
147+
}
148+
}
149+
}];
150+
151+
// Open URL in default browser
152+
[[NSWorkspace sharedWorkspace] openURL:URL];
153+
NSLog(@"Opened URL in browser for automation: %@", URL);
154+
}
155+
107156
- (ASPresentationAnchor)presentationAnchorForWebAuthenticationSession:
108157
(ASWebAuthenticationSession *)session API_AVAILABLE(macos(10.15)) {
109158
return [[[NSApplication sharedApplication] windows] firstObject];

Source/Immutable/Private/Immutable/Mac/ImmutableMac.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,5 @@
77
: NSObject <ASWebAuthenticationPresentationContextProviding>
88
+ (ImmutableMac *)instance;
99
- (void)launchUrl:(const char *)url forRedirectUri:(const char *)redirectUri;
10+
- (void)launchUrlInBrowser:(const char *)url forRedirectUri:(const char *)redirectUri;
1011
@end

0 commit comments

Comments
 (0)