Skip to content

Commit 95fe5ab

Browse files
chore: sunet device code auth
1 parent b117a84 commit 95fe5ab

File tree

9 files changed

+13
-265
lines changed

9 files changed

+13
-265
lines changed
Binary file not shown.
Binary file not shown.

Source/Immutable/Private/Immutable/Actions/ImtblConnectImxAsyncAction.cpp

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -7,28 +7,6 @@
77
#include "Immutable/Misc/ImtblLogging.h"
88

99

10-
UImtblConnectionAsyncActions* UImtblConnectionAsyncActions::Login(UObject* WorldContextObject, bool UseCachedSession)
11-
{
12-
UImtblConnectionAsyncActions* PassportInitBlueprintNode = NewObject<UImtblConnectionAsyncActions>();
13-
14-
PassportInitBlueprintNode->WorldContextObject = WorldContextObject;
15-
PassportInitBlueprintNode->bUseCachedSession = UseCachedSession;
16-
PassportInitBlueprintNode->bIsConnectImx = false;
17-
18-
return PassportInitBlueprintNode;
19-
}
20-
21-
UImtblConnectionAsyncActions* UImtblConnectionAsyncActions::ConnectImx(UObject* WorldContextObject, bool UseCachedSession)
22-
{
23-
UImtblConnectionAsyncActions* PassportInitBlueprintNode = NewObject<UImtblConnectionAsyncActions>();
24-
25-
PassportInitBlueprintNode->WorldContextObject = WorldContextObject;
26-
PassportInitBlueprintNode->bUseCachedSession = UseCachedSession;
27-
PassportInitBlueprintNode->bIsConnectImx = true;
28-
29-
return PassportInitBlueprintNode;
30-
}
31-
3210
UImtblConnectionAsyncActions* UImtblConnectionAsyncActions::LoginPKCE(UObject* WorldContextObject)
3311
{
3412
UImtblConnectionAsyncActions* PassportInitBlueprintNode = NewObject<UImtblConnectionAsyncActions>();
@@ -77,10 +55,6 @@ void UImtblConnectionAsyncActions::DoConnect(TWeakObjectPtr<UImtblJSConnector> J
7755
Passport->ConnectPKCE(bIsConnectImx, UImmutablePassport::FImtblPassportResponseDelegate::CreateUObject(this, &UImtblConnectionAsyncActions::OnConnect));
7856
#endif
7957
}
80-
else
81-
{
82-
Passport->Connect(bIsConnectImx, bUseCachedSession, UImmutablePassport::FImtblPassportResponseDelegate::CreateUObject(this, &UImtblConnectionAsyncActions::OnConnect));
83-
}
8458
}
8559
else
8660
{

Source/Immutable/Private/Immutable/ImmutableDataTypes.cpp

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -29,18 +29,7 @@ FString FImmutablePassportInitData::ToJsonString() const
2929
return OutString;
3030
}
3131

32-
TOptional<FImmutablePassportInitDeviceFlowData> FImmutablePassportInitDeviceFlowData::FromJsonString(const FString& JsonObjectString)
33-
{
34-
FImmutablePassportInitDeviceFlowData PassportConnect;
3532

36-
if (!FJsonObjectConverter::JsonObjectStringToUStruct(JsonObjectString, &PassportConnect, 0, 0))
37-
{
38-
IMTBL_WARN("Could not parse response from JavaScript into the expected " "Passport connect format")
39-
return TOptional<FImmutablePassportInitDeviceFlowData>();
40-
}
41-
42-
return PassportConnect;
43-
}
4433

4534
FString FImmutablePassportZkEvmRequestAccountsData::ToJsonString() const
4635
{

Source/Immutable/Private/Immutable/ImmutablePassport.cpp

Lines changed: 7 additions & 129 deletions
Original file line numberDiff line numberDiff line change
@@ -86,24 +86,6 @@ void UImmutablePassport::Initialize(const FImtblPassportResponseDelegate& Respon
8686
CallJS(ImmutablePassportAction::INIT, InitData.ToJsonString(), ResponseDelegate, FImtblJSResponseDelegate::CreateUObject(this, &UImmutablePassport::OnInitializeResponse), false);
8787
}
8888

89-
void UImmutablePassport::Connect(bool IsConnectImx, bool TryToRelogin, const FImtblPassportResponseDelegate& ResponseDelegate)
90-
{
91-
SetStateFlags(IPS_CONNECTING);
92-
if (IsConnectImx)
93-
{
94-
SetStateFlags(IPS_IMX);
95-
}
96-
if (TryToRelogin)
97-
{
98-
CallJS(IsConnectImx ? ImmutablePassportAction::RECONNECT : ImmutablePassportAction::RELOGIN, TEXT(""), ResponseDelegate, FImtblJSResponseDelegate::CreateUObject(this, &UImmutablePassport::ReinstateConnection));
99-
}
100-
else
101-
{
102-
Analytics->Track(IsConnectImx ? UImmutableAnalytics::EEventName::START_CONNECT_IMX : UImmutableAnalytics::EEventName::START_LOGIN);
103-
CallJS(ImmutablePassportAction::INIT_DEVICE_FLOW, TEXT(""), ResponseDelegate, FImtblJSResponseDelegate::CreateUObject(this, &UImmutablePassport::OnInitDeviceFlowResponse));
104-
}
105-
}
106-
10789
#if PLATFORM_ANDROID | PLATFORM_IOS | PLATFORM_MAC | PLATFORM_WINDOWS
10890
void UImmutablePassport::ConnectPKCE(bool IsConnectImx, const FImtblPassportResponseDelegate& ResponseDelegate)
10991
{
@@ -198,13 +180,7 @@ void UImmutablePassport::ZkEvmSignTypedDataV4(const FString& RequestJsonString,
198180
CallJS(ImmutablePassportAction::ZkEvmSignTypedDataV4, RequestJsonString, ResponseDelegate, FImtblJSResponseDelegate::CreateUObject(this, &UImmutablePassport::OnBridgeCallbackResponse));
199181
}
200182

201-
void UImmutablePassport::ConfirmCode(const FString& DeviceCode, const float Interval, const FImtblPassportResponseDelegate& ResponseDelegate)
202-
{
203-
FImmutablePassportCodeConfirmRequestData Data{DeviceCode, Interval};
204-
FString Action = IsStateFlagsSet(IPS_IMX) ? ImmutablePassportAction::CONNECT_CONFIRM_CODE : ImmutablePassportAction::LOGIN_CONFIRM_CODE;
205183

206-
CallJS(Action, UStructToJsonString(Data), ResponseDelegate, FImtblJSResponseDelegate::CreateUObject(this, &UImmutablePassport::OnConfirmCodeResponse));
207-
}
208184

209185
void UImmutablePassport::GetIdToken(const FImtblPassportResponseDelegate& ResponseDelegate)
210186
{
@@ -347,40 +323,7 @@ void UImmutablePassport::Setup(const TWeakObjectPtr<UImtblJSConnector> Connector
347323
Analytics->Setup(Connector);
348324
}
349325

350-
void UImmutablePassport::ReinstateConnection(FImtblJSResponse Response)
351-
{
352-
ResetStateFlags(IPS_CONNECTING);
353-
354-
if (auto ResponseDelegate = GetResponseDelegate(Response))
355-
{
356-
// currently, this response has to be called only for RELOGIN AND RECONNECT bridge routines
357-
bool IsRelogin = Response.responseFor.Compare(ImmutablePassportAction::RELOGIN, ESearchCase::IgnoreCase) == 0;
358-
const FString CallbackName = IsRelogin ? "Relogin" : "Reconnect";
359-
UImmutableAnalytics::EEventName EventName = IsRelogin ? UImmutableAnalytics::EEventName::COMPLETE_RELOGIN : UImmutableAnalytics::EEventName::COMPLETE_RECONNECT;
360326

361-
if (Response.success)
362-
{
363-
SetStateFlags(IPS_CONNECTED);
364-
ResponseDelegate->ExecuteIfBound(FImmutablePassportResult{true, "", Response});
365-
Analytics->Track(EventName, true);
366-
}
367-
else
368-
{
369-
Analytics->Track(EventName, false);
370-
#if PLATFORM_ANDROID | PLATFORM_IOS | PLATFORM_MAC
371-
if (IsStateFlagsSet(IPS_PKCE))
372-
{
373-
PKCEResponseDelegate = ResponseDelegate.GetValue();
374-
CallJS(ImmutablePassportAction::GetPKCEAuthUrl, TEXT(""), PKCEResponseDelegate, FImtblJSResponseDelegate::CreateUObject(this, &UImmutablePassport::OnGetPKCEAuthUrlResponse));
375-
}
376-
else
377-
#endif
378-
{
379-
CallJS(ImmutablePassportAction::INIT_DEVICE_FLOW, TEXT(""), ResponseDelegate.GetValue(), FImtblJSResponseDelegate::CreateUObject(this, &UImmutablePassport::OnInitDeviceFlowResponse));
380-
}
381-
}
382-
}
383-
}
384327

385328
bool UImmutablePassport::CheckIsInitialized(const FString& Action, const FImtblPassportResponseDelegate& ResponseDelegate) const
386329
{
@@ -436,36 +379,7 @@ void UImmutablePassport::OnInitializeResponse(FImtblJSResponse Response)
436379
}
437380
}
438381

439-
void UImmutablePassport::OnInitDeviceFlowResponse(FImtblJSResponse Response)
440-
{
441-
if (auto ResponseDelegate = GetResponseDelegate(Response))
442-
{
443-
const auto InitDeviceFlowData = JsonObjectToUStruct<FImmutablePassportInitDeviceFlowData>(Response.JsonObject);
444382

445-
if (!Response.success || !InitDeviceFlowData || !InitDeviceFlowData->code.Len())
446-
{
447-
FString Msg;
448-
449-
IMTBL_WARN("Login device flow initialization attempt failed.");
450-
Response.Error.IsSet() ? Msg = Response.Error->ToString() : Msg = Response.JsonObject->GetStringField(TEXT("error"));
451-
ResponseDelegate->ExecuteIfBound(FImmutablePassportResult{false, Msg, Response});
452-
453-
return;
454-
}
455-
FString Err;
456-
457-
FPlatformProcess::LaunchURL(*InitDeviceFlowData->url, nullptr, &Err);
458-
if (Err.Len())
459-
{
460-
FString Msg = "Failed to connect to Browser: " + Err;
461-
462-
IMTBL_ERR("%s", *Msg);
463-
ResponseDelegate->ExecuteIfBound(FImmutablePassportResult{false, Msg, Response});
464-
return;
465-
}
466-
ConfirmCode(InitDeviceFlowData->deviceCode, InitDeviceFlowData->interval, ResponseDelegate.GetValue());
467-
}
468-
}
469383

470384
void UImmutablePassport::OnLogoutResponse(FImtblJSResponse Response)
471385
{
@@ -521,30 +435,15 @@ void UImmutablePassport::OnLogoutResponse(FImtblJSResponse Response)
521435

522436
if (!Url.IsEmpty())
523437
{
524-
#if PLATFORM_ANDROID | PLATFORM_IOS | PLATFORM_MAC | PLATFORM_WINDOWS
525-
if (IsStateFlagsSet(IPS_PKCE))
526-
{
527-
OnHandleDeepLink.AddUObject(this, &UImmutablePassport::OnDeepLinkActivated);
438+
OnHandleDeepLink.AddUObject(this, &UImmutablePassport::OnDeepLinkActivated);
528439
#if PLATFORM_ANDROID
529-
LaunchAndroidUrl(Url);
440+
LaunchAndroidUrl(Url);
530441
#elif PLATFORM_IOS
531-
[[ImmutableIOS instance] launchUrl:TCHAR_TO_ANSI(*Url)];
442+
[[ImmutableIOS instance] launchUrl:TCHAR_TO_ANSI(*Url)];
532443
#elif PLATFORM_MAC
533-
[[ImmutableMac instance] launchUrl:TCHAR_TO_ANSI(*Url) forRedirectUri:TCHAR_TO_ANSI(*InitData.logoutRedirectUri)];
534-
#endif
535-
#if PLATFORM_WINDOWS
536-
Logout(Response);
537-
#endif
538-
}
539-
else
540-
{
541-
#endif
542-
Logout(Response);
543-
Analytics->Track(UImmutableAnalytics::EEventName::COMPLETE_LOGOUT);
544-
IMTBL_LOG("Logged out")
545-
ResponseDelegate->ExecuteIfBound(FImmutablePassportResult{ Response.success });
546-
#if PLATFORM_ANDROID | PLATFORM_IOS | PLATFORM_MAC | PLATFORM_WINDOWS
547-
}
444+
[[ImmutableMac instance] launchUrl:TCHAR_TO_ANSI(*Url) forRedirectUri:TCHAR_TO_ANSI(*InitData.logoutRedirectUri)];
445+
#elif PLATFORM_WINDOWS
446+
Logout(Response);
548447
#endif
549448
}
550449
else
@@ -632,29 +531,7 @@ void UImmutablePassport::OnConnectPKCEResponse(FImtblJSResponse Response)
632531
ResetStateFlags(IPS_COMPLETING_PKCE);
633532
}
634533

635-
void UImmutablePassport::OnConfirmCodeResponse(FImtblJSResponse Response)
636-
{
637-
if (auto ResponseDelegate = GetResponseDelegate(Response))
638-
{
639-
FString Msg;
640-
FString TypeOfConnection = IsStateFlagsSet(IPS_IMX) ? TEXT("connect") : TEXT("login");
641-
UImmutableAnalytics::EEventName EventName = IsStateFlagsSet(IPS_IMX) ? UImmutableAnalytics::EEventName::COMPLETE_CONNECT_IMX : UImmutableAnalytics::EEventName::COMPLETE_LOGIN;
642534

643-
ResetStateFlags(IPS_CONNECTING);
644-
if (Response.success)
645-
{
646-
IMTBL_LOG("Code confirmed for %s operation.", *TypeOfConnection)
647-
SetStateFlags(IPS_CONNECTED);
648-
}
649-
else
650-
{
651-
IMTBL_LOG("%s code not confirmed.", *TypeOfConnection)
652-
Response.Error.IsSet() ? Msg = Response.Error->ToString() : Msg = Response.JsonObject->GetStringField(TEXT("error"));
653-
}
654-
Analytics->Track(EventName, Response.success);
655-
ResponseDelegate->ExecuteIfBound(FImmutablePassportResult{Response.success, Msg, Response});
656-
}
657-
}
658535

659536
void UImmutablePassport::OnBridgeCallbackResponse(FImtblJSResponse Response)
660537
{
@@ -724,6 +601,7 @@ void UImmutablePassport::OnDeepLinkActivated(const FString& DeepLink)
724601
FGraphEventRef GameThreadTask = FFunctionGraphTask::CreateAndDispatchWhenReady([this]()
725602
{
726603
Analytics->Track(UImmutableAnalytics::EEventName::COMPLETE_LOGOUT_PKCE);
604+
IMTBL_LOG("Complete Logout PKCE")
727605
PKCELogoutResponseDelegate.ExecuteIfBound(FImmutablePassportResult{true, "Logged out"});
728606
PKCELogoutResponseDelegate = nullptr;
729607
ResetStateFlags(IPS_CONNECTED | IPS_PKCE | IPS_IMX);

Source/Immutable/Public/Immutable/Actions/ImtblConnectImxAsyncAction.h

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -18,28 +18,6 @@ class IMMUTABLE_API UImtblConnectionAsyncActions : public UImtblBlueprintAsyncAc
1818
DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FPassportConnectOutputPin, FString, ErrorMessage);
1919

2020
public:
21-
/**
22-
* Log into Passport using Device Code Authorisation.
23-
*
24-
* @param WorldContextObject World context
25-
* @param UseCachedSession Whether to use stored credentials for relogin
26-
*
27-
* @return A reference to the object represented by this node
28-
*/
29-
UFUNCTION(BlueprintCallable, meta = (WorldContext = "WorldContextObject", BlueprintInternalUseOnly = "true"), Category = "Immutable")
30-
static UImtblConnectionAsyncActions* Login(UObject* WorldContextObject, bool UseCachedSession = false);
31-
32-
/**
33-
* Log into Passport using Device Code Authorisation, initialise the gamer's wallet and instantiate the IMX provider.
34-
*
35-
* @param WorldContextObject World context
36-
* @param UseCachedSession Whether to use stored credentials for relogin
37-
*
38-
* @return A reference to the object represented by this node
39-
*/
40-
UFUNCTION(BlueprintCallable, meta = (WorldContext = "WorldContextObject", BlueprintInternalUseOnly = "true"), Category = "Immutable")
41-
static UImtblConnectionAsyncActions* ConnectImx(UObject* WorldContextObject, bool UseCachedSession = false);
42-
4321
/**
4422
* Log into Passport using PKCE
4523
*
@@ -64,7 +42,6 @@ class IMMUTABLE_API UImtblConnectionAsyncActions : public UImtblBlueprintAsyncAc
6442
virtual void Activate() override;
6543

6644
private:
67-
FImmutablePassportInitDeviceFlowData InitDeviceFlowData;
6845

6946
void DoConnect(TWeakObjectPtr<class UImtblJSConnector> JSConnector);
7047
void OnConnect(FImmutablePassportResult Result);

Source/Immutable/Public/Immutable/ImmutableDataTypes.h

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -91,26 +91,6 @@ struct IMMUTABLE_API FImmutablePassportInitData
9191
FString ToJsonString() const;
9292
};
9393

94-
USTRUCT()
95-
struct FImmutablePassportInitDeviceFlowData
96-
{
97-
GENERATED_BODY()
98-
99-
UPROPERTY()
100-
FString code;
101-
102-
UPROPERTY()
103-
FString deviceCode;
104-
105-
UPROPERTY()
106-
FString url;
107-
108-
UPROPERTY()
109-
float interval = 0;
110-
111-
static TOptional<FImmutablePassportInitDeviceFlowData> FromJsonString(const FString& JsonObjectString);
112-
};
113-
11494
USTRUCT()
11595
struct FImtblUserProfile
11696
{
@@ -153,20 +133,7 @@ struct IMMUTABLE_API FImmutablePassportZkEvmGetBalanceData
153133
FString ToJsonString() const;
154134
};
155135

156-
USTRUCT()
157-
struct FImmutablePassportCodeConfirmRequestData
158-
{
159-
GENERATED_BODY()
160136

161-
UPROPERTY()
162-
FString deviceCode;
163-
164-
UPROPERTY()
165-
float interval = 5;
166-
167-
UPROPERTY()
168-
float timeoutMs = 15 * 60 * 1000;
169-
};
170137

171138
USTRUCT()
172139
struct FImmutablePassportConnectPKCEData

Source/Immutable/Public/Immutable/ImmutableNames.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,6 @@
33
namespace ImmutablePassportAction
44
{
55
const FString INIT = TEXT("init");
6-
const FString INIT_DEVICE_FLOW = TEXT("initDeviceFlow");
7-
const FString RELOGIN = TEXT("relogin");
8-
const FString LOGIN_CONFIRM_CODE = TEXT("loginConfirmCode");
9-
const FString CONNECT_CONFIRM_CODE = TEXT("connectConfirmCode");
10-
const FString RECONNECT = TEXT("reconnect");
116
const FString Logout = TEXT("logout");
127
const FString Connect = TEXT("connect");
138
const FString ConnectEvm = TEXT("connectEvm");

0 commit comments

Comments
 (0)