Skip to content

Commit

Permalink
fix: improved passport retrieval for macos and ios
Browse files Browse the repository at this point in the history
  • Loading branch information
YermekG committed Jan 10, 2024
1 parent b1b9267 commit 5edf82f
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 34 deletions.
Binary file modified Content/BlueprintSampleContent/PassportFeaturesWidget4_26.uasset
Binary file not shown.
5 changes: 5 additions & 0 deletions Source/Immutable/Immutable.Build.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,11 @@ public Immutable(ReadOnlyTargetRules Target) : base(Target)
// ... add any modules that your module loads dynamically here ...
}
);

if (Target.bBuildEditor == true)
{
PrivateDependencyModuleNames.Add("UnrealEd");
}

if (Target.Platform == UnrealTargetPlatform.Android)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ void UImtblPassportLogoutAsyncAction::Activate()
{
FString Err = "Logout failed due to missing world or world context object.";
IMTBL_WARN("%s", *Err)
Failed.Broadcast(Err);
OnFailure.Broadcast(Err);
return;
}

Expand All @@ -36,14 +36,14 @@ void UImtblPassportLogoutAsyncAction::DoLogout(TWeakObjectPtr<UImtblJSConnector>
Passport->Logout(UImmutablePassport::FImtblPassportResponseDelegate::CreateUObject(this, &UImtblPassportLogoutAsyncAction::OnLogoutResponse));
}

void UImtblPassportLogoutAsyncAction::OnLogoutResponse(FImmutablePassportResult Result)
void UImtblPassportLogoutAsyncAction::OnLogoutResponse(FImmutablePassportResult Result) const
{
if (Result.Success)
{
LoggedOut.Broadcast(Result.Message);
OnSuccess.Broadcast(Result.Message);
}
else
{
Failed.Broadcast(Result.Message);
OnFailure.Broadcast(Result.Message);
}
}
10 changes: 6 additions & 4 deletions Source/Immutable/Private/Immutable/ImmutablePassport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,10 @@ void UImmutablePassport::Initialize(const FImmutablePassportInitData& Data,
void UImmutablePassport::Logout(const FImtblPassportResponseDelegate& ResponseDelegate)
{
#if PLATFORM_ANDROID | PLATFORM_IOS | PLATFORM_MAC
PKCELogoutResponseDelegate = ResponseDelegate;
if (bIsLoggedIn && IsPKCEConnected)
{
PKCELogoutResponseDelegate = ResponseDelegate;
}
#endif
CallJS(ImmutablePassportAction::Logout, TEXT(""), ResponseDelegate,
FImtblJSResponseDelegate::CreateUObject(this, &UImmutablePassport::OnLogoutResponse));
Expand Down Expand Up @@ -543,8 +546,6 @@ void UImmutablePassport::OnGetPKCEAuthUrlResponse(FImtblJSResponse Response)
else
{
IMTBL_ERR("Unable to return a response for Connect PKCE");
PKCEResponseDelegate.ExecuteIfBound(FImmutablePassportResult{ false, "Response delegate is not assigned" });
PKCEResponseDelegate = nullptr;
}
}

Expand Down Expand Up @@ -882,8 +883,9 @@ void UImmutablePassport::OnDeepLinkActivated(FString DeepLink)
{
IMTBL_LOG_FUNC("URL : %s", *DeepLink);
OnHandleDeepLink = nullptr;
if (DeepLink.StartsWith(InitData.logoutRedirectUri) && PKCELogoutResponseDelegate.ExecuteIfBound(FImmutablePassportResult{ true, "Logged out" }))
if (DeepLink.StartsWith(InitData.logoutRedirectUri))
{
PKCELogoutResponseDelegate.ExecuteIfBound(FImmutablePassportResult{ true, "Logged out" });
PKCELogoutResponseDelegate = nullptr;
IsPKCEConnected = false;
}
Expand Down
29 changes: 23 additions & 6 deletions Source/Immutable/Private/Immutable/Mac/ImmutableMac.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
#include "Immutable/ImmutableSubsystem.h"
#include "Engine/GameEngine.h"

#if WITH_EDITOR
#include "Editor.h"
#endif

ASWebAuthenticationSession *_authSession;

@implementation ImmutableMac
Expand All @@ -22,13 +26,26 @@ ASWebAuthenticationSession *_authSession;
}

+ (UImmutablePassport*) getPassport {
UGameEngine* GameEngine = Cast<UGameEngine>(GEngine);

if (!GameEngine) {
return nil;
UWorld* World = nullptr;

#if WITH_EDITOR
if (GEditor)
{
for (const auto& Context : GEditor->GetWorldContexts())
{
if (Context.WorldType == EWorldType::PIE && Context.World())
{
World = Context.World();
break;
}
}
}

UWorld* World = GameEngine ? GameEngine->GetGameWorld() : NULL;
#else
if (UGameEngine* GameEngine = Cast<UGameEngine>(GEngine))
{
World = GameEngine->GetGameWorld();
}
#endif

if (!World) {
return nil;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
// Fill out your copyright notice in the Description page of Project Settings.

#pragma once
#pragma once

#include "CoreMinimal.h"
#include "Immutable/ImmutablePassport.h"
Expand All @@ -12,28 +10,29 @@
*/
// UCLASS(meta = (HasDedicatedAsyncNode))
UCLASS()
class IMMUTABLE_API UImtblPassportLogoutAsyncAction
: public UImtblBlueprintAsyncAction {
GENERATED_BODY()
class IMMUTABLE_API UImtblPassportLogoutAsyncAction : public UImtblBlueprintAsyncAction
{
GENERATED_BODY()

DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FPassportLogoutOutputPin, FString,
ErrorMessage);
DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FPassportLogoutOutPin, FString, Message);

public:
UFUNCTION(BlueprintCallable,
meta = (WorldContext = "WorldContextObject",
BlueprintInternalUseOnly = "true"),
Category = "Immutable")
static UImtblPassportLogoutAsyncAction *Logout(UObject *WorldContextObject);

UFUNCTION(BlueprintCallable, meta = (WorldContext = "WorldContextObject", BlueprintInternalUseOnly = "true"), Category = "Immutable")
static UImtblPassportLogoutAsyncAction* Logout(UObject* WorldContextObject);

virtual void Activate() override;

private:

void Activate() override;
void DoLogout(TWeakObjectPtr<class UImtblJSConnector> JSConnector);
void OnLogoutResponse(FImmutablePassportResult Result) const;

private:
void DoLogout(TWeakObjectPtr<class UImtblJSConnector> JSConnector);
void OnLogoutResponse(FImmutablePassportResult Result);

UPROPERTY(BlueprintAssignable)
FPassportLogoutOutputPin LoggedOut;
UPROPERTY(BlueprintAssignable)
FPassportLogoutOutputPin Failed;
UPROPERTY(BlueprintAssignable)
FPassportLogoutOutPin OnSuccess;
UPROPERTY(BlueprintAssignable)
FPassportLogoutOutPin OnFailure;

};

0 comments on commit 5edf82f

Please sign in to comment.