Skip to content

Commit

Permalink
fix: updated event handler for deeplink event on android and ios
Browse files Browse the repository at this point in the history
  • Loading branch information
YermekG committed Jan 10, 2024
1 parent 848800d commit b1b9267
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 44 deletions.
Binary file modified Content/BlueprintSampleContent/PassportLoginWidget4_26.uasset
Binary file not shown.
59 changes: 16 additions & 43 deletions Source/Immutable/Private/Immutable/ImmutablePassport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,10 +132,6 @@ FString FImmutablePassportZkEvmGetBalanceData::ToJsonString() const
return OutString;
}

#if PLATFORM_ANDROID
FString UImmutablePassport::LoginPKCEUrl(TEXT(""));
#endif

// @param Environment can be one of ImmutablePassportAction::EnvSandbox or
// ImmutablePassportAction::EnvProduction
void UImmutablePassport::Initialize(const FImmutablePassportInitData& Data,
Expand All @@ -151,6 +147,9 @@ void UImmutablePassport::Initialize(const FImmutablePassportInitData& Data,

void UImmutablePassport::Logout(const FImtblPassportResponseDelegate& ResponseDelegate)
{
#if PLATFORM_ANDROID | PLATFORM_IOS | PLATFORM_MAC
PKCELogoutResponseDelegate = ResponseDelegate;
#endif
CallJS(ImmutablePassportAction::Logout, TEXT(""), ResponseDelegate,
FImtblJSResponseDelegate::CreateUObject(this, &UImmutablePassport::OnLogoutResponse));
}
Expand Down Expand Up @@ -395,8 +394,6 @@ void UImmutablePassport::OnLogoutResponse(FImtblJSResponse Response)
{
if (Response.success)
{
IMTBL_LOG("Logged out.")

FString Url;
FString Err;

Expand All @@ -406,11 +403,13 @@ void UImmutablePassport::OnLogoutResponse(FImtblJSResponse Response)
#if PLATFORM_ANDROID | PLATFORM_IOS | PLATFORM_MAC
if (IsPKCEConnected)
{
PKCELogoutResponseDelegate = ResponseDelegate.GetValue();
OnHandleDeepLink = FImtblPassportHandleDeepLinkDelegate::CreateUObject(this, &UImmutablePassport::OnDeepLinkActivated);
#if PLATFORM_ANDROID
LaunchAndroidUrl(Url);
#elif PLATFORM_IOS || PLATFORM_MAC
#elif PLATFORM_IOS
[[ImmutableIOS instance] launchUrl:TCHAR_TO_ANSI(*Url)];
#elif PLATFORM_MAC
[[ImmutableMac instance] launchUrl:TCHAR_TO_ANSI(*Url) forRedirectUri:TCHAR_TO_ANSI(*InitData.logoutRedirectUri)];
#endif
}
else
Expand All @@ -424,7 +423,7 @@ void UImmutablePassport::OnLogoutResponse(FImtblJSResponse Response)
ResponseDelegate->ExecuteIfBound(FImmutablePassportResult{ false, Msg, Response });
return;
}

IMTBL_LOG("Logged out.")
ResponseDelegate->ExecuteIfBound(FImmutablePassportResult{ Response.success, "Logged out" });
#if PLATFORM_ANDROID | PLATFORM_IOS | PLATFORM_MAC
}
Expand Down Expand Up @@ -533,22 +532,19 @@ void UImmutablePassport::OnGetPKCEAuthUrlResponse(FImtblJSResponse Response)
Msg = Response.JsonObject->GetStringField(TEXT("result")).Replace(TEXT(" "), TEXT("+"));
#if PLATFORM_ANDROID
OnPKCEDismissed = FImtblPassportOnPKCEDismissedDelegate::CreateUObject(this, &UImmutablePassport::HandleOnLoginPKCEDismissed);
LoginPKCEUrl = Msg;
LaunchAndroidUrl(Msg);
#elif PLATFORM_IOS
[[ImmutableIOS instance] launchUrl:TCHAR_TO_ANSI(*Msg)];
#elif PLATFORM_MAC
[[ImmutableMac instance] launchUrl:TCHAR_TO_ANSI(*Msg) forRedirectUri:TCHAR_TO_ANSI(*InitData.redirectUri)];
#endif
}
#if PLATFORM_IOS || PLATFORM_MAC
PKCEResponseDelegate.ExecuteIfBound(FImmutablePassportResult{ bSuccess, Msg });
PKCEResponseDelegate = nullptr;
#endif
}
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 @@ -886,17 +882,15 @@ void UImmutablePassport::OnDeepLinkActivated(FString DeepLink)
{
IMTBL_LOG_FUNC("URL : %s", *DeepLink);
OnHandleDeepLink = nullptr;
// if (DeepLink.StartsWith(InitData.logoutRedirectUri))
// {
// }
// else
if (DeepLink.StartsWith(InitData.redirectUri))
if (DeepLink.StartsWith(InitData.logoutRedirectUri) && PKCELogoutResponseDelegate.ExecuteIfBound(FImmutablePassportResult{ true, "Logged out" }))
{
PKCELogoutResponseDelegate = nullptr;
IsPKCEConnected = false;
}
else if (DeepLink.StartsWith(InitData.redirectUri))
{
CompleteLoginPKCEFlow(DeepLink);
}
#if PLATFORM_ANDROID
LoginPKCEUrl.Empty();
#endif
}

void UImmutablePassport::CompleteLoginPKCEFlow(FString Url)
Expand Down Expand Up @@ -996,27 +990,6 @@ void UImmutablePassport::HandleCustomTabsDismissed(FString Url)
{
IMTBL_LOG("On PKCE Dismissed");

// Dismiss routine for logout
IMTBL_LOG("PKCE received url %s", *Url);

TOptional<FString> Parameter = FGenericPlatformHttp::GetUrlParameter(Url, TEXT("resultTo"));

if (Parameter.IsSet())
{
IMTBL_LOG("PKCE received url resultTo parameter %s", *Parameter.GetValue());
}
if (IsPKCEConnected)
{
if (PKCELogoutResponseDelegate.IsBound())
{
PKCELogoutResponseDelegate.ExecuteIfBound(FImmutablePassportResult{ true, "Logged out" });
PKCELogoutResponseDelegate = nullptr;
}
IsPKCEConnected = false;

return;
}

if (!OnPKCEDismissed.ExecuteIfBound())
{
IMTBL_WARN("OnPKCEDismissed delegate was not called");
Expand Down
1 change: 0 additions & 1 deletion Source/Immutable/Public/Immutable/ImmutablePassport.h
Original file line number Diff line number Diff line change
Expand Up @@ -531,7 +531,6 @@ class IMMUTABLE_API UImmutablePassport : public UObject
FImtblPassportOnPKCEDismissedDelegate OnPKCEDismissed;

bool completingPKCE = false; // Used for the PKCE callback
static FString LoginPKCEUrl;
#endif

TWeakObjectPtr<UImtblJSConnector> JSConnector;
Expand Down

0 comments on commit b1b9267

Please sign in to comment.