Skip to content

[ID-3775] chore: Migrate tests that use Device Code Auth to PKCE #209

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
60 changes: 37 additions & 23 deletions Source/Immutable/Private/Immutable/Mac/ImmutableMac.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
#include "ImmutableMac.h"

#include "Engine/GameEngine.h"

#include "Immutable/ImmutablePassport.h"
#include "Immutable/ImmutableSubsystem.h"
#include "Engine/GameEngine.h"

#if WITH_EDITOR
#include "Editor.h"
Expand All @@ -26,17 +28,24 @@ ASWebAuthenticationSession *_authSession;
}

+ (UImmutablePassport*) getPassport {
UWorld* World = nullptr;

#if WITH_EDITOR
if (GEditor)
{
for (const auto& Context : GEditor->GetWorldContexts())
{
if (Context.WorldType == EWorldType::PIE && Context.World())
if (auto* World = Context.World())
{
World = Context.World();
break;
if (auto GameInstance = World->GetGameInstance())
{
if (auto ImmutableSubsystem = GameInstance->GetSubsystem<UImmutableSubsystem>())
{
auto WeakPassport = ImmutableSubsystem->GetPassport();
if (auto Passport = WeakPassport.Get())
{
return Passport;
}
}
}
}
}
}
Expand All @@ -47,26 +56,17 @@ ASWebAuthenticationSession *_authSession;
}
#endif

if (!World) {
return nil;
}

auto ImmutableSubsystem = World->GetGameInstance()->GetSubsystem<UImmutableSubsystem>();

if (!ImmutableSubsystem) {
return nil;
}

auto Passport = ImmutableSubsystem->GetPassport();

if (!Passport.IsValid()) {
return nil;
}

return Passport.Get();
return nil;
}

- (void)launchUrl:(const char *)url forRedirectUri:(const char *)redirectUri {
// For automation, use the browser-based method
if (GIsAutomationTesting) {
NSLog(@"Using automation mode for authentication (GIsAutomationTesting is true)");
[self launchUrlInBrowser:url];
return;
}

if (@available(macOS 10.15, *)) {
NSURL *URL =
[NSURL URLWithString:[[NSString alloc] initWithUTF8String:url]];
Expand Down Expand Up @@ -104,6 +104,20 @@ ASWebAuthenticationSession *_authSession;
}
}

- (void)launchUrlInBrowser:(const char *)url {
// Add redundant check to ensure this only runs for automated testing
if (!GIsAutomationTesting) {
return;
}

// Create URL object
NSURL *URL = [NSURL URLWithString:[[NSString alloc] initWithUTF8String:url]];

// Open URL in default browser
[[NSWorkspace sharedWorkspace] openURL:URL];
NSLog(@"Opened URL in browser for automation: %@", URL);
}

- (ASPresentationAnchor)presentationAnchorForWebAuthenticationSession:
(ASWebAuthenticationSession *)session API_AVAILABLE(macos(10.15)) {
return [[[NSApplication sharedApplication] windows] firstObject];
Expand Down
1 change: 1 addition & 0 deletions Source/Immutable/Private/Immutable/Mac/ImmutableMac.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@
: NSObject <ASWebAuthenticationPresentationContextProviding>
+ (ImmutableMac *)instance;
- (void)launchUrl:(const char *)url forRedirectUri:(const char *)redirectUri;
- (void)launchUrlInBrowser:(const char *)url;
@end
Loading