Skip to content

Commit 19c41cd

Browse files
feat: add direct login support (#3857)
1 parent 16ab539 commit 19c41cd

File tree

6 files changed

+71
-9
lines changed

6 files changed

+71
-9
lines changed
68.6 KB
Binary file not shown.

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

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

99

10-
UImtblConnectionAsyncActions* UImtblConnectionAsyncActions::Login(UObject* WorldContextObject)
10+
UImtblConnectionAsyncActions* UImtblConnectionAsyncActions::Login(UObject* WorldContextObject, EImmutableDirectLoginMethod DirectLoginMethod)
1111
{
1212
UImtblConnectionAsyncActions* PassportInitBlueprintNode = NewObject<UImtblConnectionAsyncActions>();
1313

1414
PassportInitBlueprintNode->WorldContextObject = WorldContextObject;
1515
PassportInitBlueprintNode->bIsConnectImx = false;
1616
PassportInitBlueprintNode->bIsPKCE = true;
17+
PassportInitBlueprintNode->DirectLoginMethod = DirectLoginMethod;
1718

1819
return PassportInitBlueprintNode;
1920
}
2021

21-
UImtblConnectionAsyncActions* UImtblConnectionAsyncActions::ConnectImx(UObject* WorldContextObject)
22+
UImtblConnectionAsyncActions* UImtblConnectionAsyncActions::ConnectImx(UObject* WorldContextObject, EImmutableDirectLoginMethod DirectLoginMethod)
2223
{
2324
UImtblConnectionAsyncActions* PassportInitBlueprintNode = NewObject<UImtblConnectionAsyncActions>();
2425

2526
PassportInitBlueprintNode->WorldContextObject = WorldContextObject;
2627
PassportInitBlueprintNode->bIsConnectImx = true;
2728
PassportInitBlueprintNode->bIsPKCE = true;
29+
PassportInitBlueprintNode->DirectLoginMethod = DirectLoginMethod;
2830

2931
return PassportInitBlueprintNode;
3032
}
@@ -52,7 +54,7 @@ void UImtblConnectionAsyncActions::DoConnect(TWeakObjectPtr<UImtblJSConnector> J
5254
if (bIsPKCE)
5355
{
5456
#if PLATFORM_ANDROID | PLATFORM_IOS | PLATFORM_MAC | PLATFORM_WINDOWS
55-
Passport->Connect(bIsConnectImx, UImmutablePassport::FImtblPassportResponseDelegate::CreateUObject(this, &UImtblConnectionAsyncActions::OnConnect));
57+
Passport->Connect(bIsConnectImx, UImmutablePassport::FImtblPassportResponseDelegate::CreateUObject(this, &UImtblConnectionAsyncActions::OnConnect), DirectLoginMethod);
5658
#endif
5759
}
5860
}

Source/Immutable/Private/Immutable/ImmutablePassport.cpp

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ void UImmutablePassport::Initialize(const FImtblPassportResponseDelegate& Respon
8787
}
8888

8989
#if PLATFORM_ANDROID | PLATFORM_IOS | PLATFORM_MAC | PLATFORM_WINDOWS
90-
void UImmutablePassport::Connect(bool IsConnectImx, const FImtblPassportResponseDelegate& ResponseDelegate)
90+
void UImmutablePassport::Connect(bool IsConnectImx, const FImtblPassportResponseDelegate& ResponseDelegate, EImmutableDirectLoginMethod DirectLoginMethod)
9191
{
9292
SetStateFlags(IPS_CONNECTING | IPS_PKCE);
9393

@@ -108,7 +108,34 @@ void UImmutablePassport::Connect(bool IsConnectImx, const FImtblPassportResponse
108108
}
109109
PKCEResponseDelegate = ResponseDelegate;
110110
Analytics->Track(IsConnectImx ? UImmutableAnalytics::EEventName::START_CONNECT_IMX_PKCE : UImmutableAnalytics::EEventName::START_LOGIN_PKCE);
111-
CallJS(ImmutablePassportAction::GetPKCEAuthUrl, TEXT(""), PKCEResponseDelegate, FImtblJSResponseDelegate::CreateUObject(this, &UImmutablePassport::OnGetAuthUrlResponse));
111+
112+
FImmutableGetPKCEAuthUrlRequest PKCERequest;
113+
PKCERequest.isConnectImx = IsConnectImx;
114+
PKCERequest.directLoginMethod = DirectLoginMethod;
115+
116+
// Custom export callback to handle all enums to use lowercase
117+
FJsonObjectConverter::CustomExportCallback CustomCallback;
118+
CustomCallback.BindLambda([](FProperty* Property, const void* Value) -> TSharedPtr<FJsonValue>
119+
{
120+
if (FEnumProperty* EnumProperty = CastField<FEnumProperty>(Property))
121+
{
122+
int64 EnumValue = EnumProperty->GetUnderlyingProperty()->GetSignedIntPropertyValue(Value);
123+
124+
if (UEnum* Enum = EnumProperty->GetEnum())
125+
{
126+
FString EnumNameString = Enum->GetNameStringByValue(EnumValue);
127+
return MakeShareable(new FJsonValueString(EnumNameString.ToLower()));
128+
}
129+
}
130+
131+
// Return null to use default serialization for non-enum properties
132+
return TSharedPtr<FJsonValue>();
133+
});
134+
135+
FString PKCERequestJson;
136+
FJsonObjectConverter::UStructToJsonObjectString(PKCERequest, PKCERequestJson, 0, 0, 0, &CustomCallback);
137+
138+
CallJS(ImmutablePassportAction::GetPKCEAuthUrl, PKCERequestJson, PKCEResponseDelegate, FImtblJSResponseDelegate::CreateUObject(this, &UImmutablePassport::OnGetAuthUrlResponse));
112139
}
113140
#endif
114141

@@ -754,4 +781,4 @@ void UImmutablePassport::LaunchAndroidUrl(FString Url)
754781
CallJniStaticVoidMethod(Env, jimmutableAndroidClass, jlaunchUrl, FJavaWrapper::GameActivityThis, jurl);
755782
}
756783
}
757-
#endif
784+
#endif

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,21 +22,23 @@ class IMMUTABLE_API UImtblConnectionAsyncActions : public UImtblBlueprintAsyncAc
2222
* Log into Passport
2323
*
2424
* @param WorldContextObject World context
25+
* @param DirectLoginMethod Direct login method to use for authentication (defaults to None for standard login page)
2526
*
2627
* @return A reference to the object represented by this node
2728
*/
2829
UFUNCTION(BlueprintCallable, meta = (WorldContext = "WorldContextObject", BlueprintInternalUseOnly = "true"), Category = "Immutable")
29-
static UImtblConnectionAsyncActions* Login(UObject* WorldContextObject);
30+
static UImtblConnectionAsyncActions* Login(UObject* WorldContextObject, EImmutableDirectLoginMethod DirectLoginMethod = EImmutableDirectLoginMethod::None);
3031

3132
/**
3233
* Log into Passport, initialise the gamer's wallet and instantiate the IMX provider.
3334
*
3435
* @param WorldContextObject World context
36+
* @param DirectLoginMethod Direct login method to use for authentication (defaults to None for standard login page)
3537
*
3638
* @return A reference to the object represented by this node
3739
*/
3840
UFUNCTION(BlueprintCallable, meta = (WorldContext = "WorldContextObject", BlueprintInternalUseOnly = "true"), Category = "Immutable")
39-
static UImtblConnectionAsyncActions* ConnectImx(UObject* WorldContextObject);
41+
static UImtblConnectionAsyncActions* ConnectImx(UObject* WorldContextObject, EImmutableDirectLoginMethod DirectLoginMethod = EImmutableDirectLoginMethod::None);
4042

4143

4244
virtual void Activate() override;
@@ -54,4 +56,5 @@ class IMMUTABLE_API UImtblConnectionAsyncActions : public UImtblBlueprintAsyncAc
5456
bool bUseCachedSession = false;
5557
bool bIsConnectImx = false;
5658
bool bIsPKCE = false;
59+
EImmutableDirectLoginMethod DirectLoginMethod = EImmutableDirectLoginMethod::None;
5760
};

Source/Immutable/Public/Immutable/ImmutableDataTypes.h

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,18 @@ DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FImmutableDeepLinkDynamicMulticastDe
1414
// This hardcoded value will be updated by a workflow during the release process.
1515
#define ENGINE_SDK_VERSION TEXT("1.11.0")
1616

17+
/**
18+
* Enum representing direct login methods for authentication providers
19+
*/
20+
UENUM(BlueprintType)
21+
enum class EImmutableDirectLoginMethod : uint8
22+
{
23+
None,
24+
Google,
25+
Apple,
26+
Facebook
27+
};
28+
1729
USTRUCT()
1830
struct FImmutableEngineVersionData
1931
{
@@ -147,6 +159,23 @@ struct FImmutablePassportConnectData
147159
FString state;
148160
};
149161

162+
/**
163+
* Structure to hold PKCE authentication URL request data
164+
*/
165+
USTRUCT()
166+
struct IMMUTABLE_API FImmutableGetPKCEAuthUrlRequest
167+
{
168+
GENERATED_BODY()
169+
170+
/** Whether this is a ConnectImx operation (true) or just Login (false) */
171+
UPROPERTY()
172+
bool isConnectImx = false;
173+
174+
/** Direct login method to use for authentication */
175+
UPROPERTY()
176+
EImmutableDirectLoginMethod directLoginMethod = EImmutableDirectLoginMethod::None;
177+
};
178+
150179
USTRUCT()
151180
struct IMMUTABLE_API FImmutablePassportResult
152181
{

Source/Immutable/Public/Immutable/ImmutablePassport.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,9 @@ class IMMUTABLE_API UImmutablePassport : public UObject
103103
* @param IsConnectImx If true, player will connect to Immutable X after logging in.
104104
* Else, just perform the login without connecting to Immutable X.
105105
* @param ResponseDelegate Callback delegate.
106+
* @param DirectLoginMethod Direct login method to use for authentication (defaults to None for standard login page).
106107
*/
107-
void Connect(bool IsConnectImx, const FImtblPassportResponseDelegate& ResponseDelegate);
108+
void Connect(bool IsConnectImx, const FImtblPassportResponseDelegate& ResponseDelegate, EImmutableDirectLoginMethod DirectLoginMethod = EImmutableDirectLoginMethod::None);
108109
#endif
109110

110111
/**

0 commit comments

Comments
 (0)