Skip to content

Commit 1dec37c

Browse files
chore: update direct login support to use direct login options (#3896)
1 parent cbe319c commit 1dec37c

File tree

8 files changed

+74
-43
lines changed

8 files changed

+74
-43
lines changed
Binary file not shown.
Binary file not shown.

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

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

99

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

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

1919
return PassportInitBlueprintNode;
2020
}
2121

22-
UImtblConnectionAsyncActions* UImtblConnectionAsyncActions::ConnectImx(UObject* WorldContextObject, EImmutableDirectLoginMethod DirectLoginMethod)
22+
UImtblConnectionAsyncActions* UImtblConnectionAsyncActions::ConnectImx(UObject* WorldContextObject, const FImmutableDirectLoginOptions& DirectLoginOptions)
2323
{
2424
UImtblConnectionAsyncActions* PassportInitBlueprintNode = NewObject<UImtblConnectionAsyncActions>();
2525

2626
PassportInitBlueprintNode->WorldContextObject = WorldContextObject;
2727
PassportInitBlueprintNode->bIsConnectImx = true;
2828
PassportInitBlueprintNode->bIsPKCE = true;
29-
PassportInitBlueprintNode->DirectLoginMethod = DirectLoginMethod;
29+
PassportInitBlueprintNode->DirectLoginOptions = DirectLoginOptions;
3030

3131
return PassportInitBlueprintNode;
3232
}
@@ -54,7 +54,7 @@ void UImtblConnectionAsyncActions::DoConnect(TWeakObjectPtr<UImtblJSConnector> J
5454
if (bIsPKCE)
5555
{
5656
#if PLATFORM_ANDROID | PLATFORM_IOS | PLATFORM_MAC | PLATFORM_WINDOWS
57-
Passport->Connect(bIsConnectImx, UImmutablePassport::FImtblPassportResponseDelegate::CreateUObject(this, &UImtblConnectionAsyncActions::OnConnect), DirectLoginMethod);
57+
Passport->Connect(bIsConnectImx, UImmutablePassport::FImtblPassportResponseDelegate::CreateUObject(this, &UImtblConnectionAsyncActions::OnConnect), DirectLoginOptions);
5858
#endif
5959
}
6060
}

Source/Immutable/Private/Immutable/ImmutableDataTypes.cpp

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

32-
33-
3432
FString FImmutablePassportZkEvmRequestAccountsData::ToJsonString() const
3533
{
3634
FString OutString;
@@ -97,4 +95,22 @@ void UImmutablePKCEData::Reset()
9795
#if PLATFORM_WINDOWS
9896
UImmutablePKCEWindows::Reset(this);
9997
#endif
98+
}
99+
100+
bool FImmutableDirectLoginOptions::IsEmailValid() const
101+
{
102+
return DirectLoginMethod == EImmutableDirectLoginMethod::Email && !Email.IsEmpty();
103+
}
104+
105+
TSharedPtr<FJsonObject> FImmutableDirectLoginOptions::ToJsonObject() const
106+
{
107+
TSharedPtr<FJsonObject> JsonObject = MakeShareable(new FJsonObject);
108+
JsonObject->SetStringField(TEXT("directLoginMethod"), StaticEnum<EImmutableDirectLoginMethod>()->GetNameStringByValue(static_cast<int64>(DirectLoginMethod)).ToLower());
109+
110+
if (IsEmailValid())
111+
{
112+
JsonObject->SetStringField(TEXT("email"), Email);
113+
}
114+
115+
return JsonObject;
100116
}

Source/Immutable/Private/Immutable/ImmutablePassport.cpp

Lines changed: 18 additions & 22 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, EImmutableDirectLoginMethod DirectLoginMethod)
90+
void UImmutablePassport::Connect(bool IsConnectImx, const FImtblPassportResponseDelegate& ResponseDelegate, const FImmutableDirectLoginOptions& DirectLoginOptions)
9191
{
9292
SetStateFlags(IPS_CONNECTING | IPS_PKCE);
9393

@@ -109,31 +109,27 @@ void UImmutablePassport::Connect(bool IsConnectImx, const FImtblPassportResponse
109109
PKCEResponseDelegate = ResponseDelegate;
110110
Analytics->Track(IsConnectImx ? UImmutableAnalytics::EEventName::START_CONNECT_IMX_PKCE : UImmutableAnalytics::EEventName::START_LOGIN_PKCE);
111111

112-
FImmutableGetPKCEAuthUrlRequest PKCERequest;
113-
PKCERequest.isConnectImx = IsConnectImx;
114-
PKCERequest.directLoginMethod = DirectLoginMethod;
112+
TSharedPtr<FJsonObject> RequestObject = MakeShareable(new FJsonObject);
113+
RequestObject->SetBoolField(TEXT("isConnectImx"), IsConnectImx);
115114

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>
115+
TSharedPtr<FJsonObject> DirectLoginOptionsObject = DirectLoginOptions.ToJsonObject();
116+
if (DirectLoginOptionsObject.IsValid())
119117
{
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-
});
118+
RequestObject->SetObjectField(TEXT("directLoginOptions"), DirectLoginOptionsObject);
119+
}
134120

121+
// Convert to JSON string
135122
FString PKCERequestJson;
136-
FJsonObjectConverter::UStructToJsonObjectString(PKCERequest, PKCERequestJson, 0, 0, 0, &CustomCallback);
123+
TSharedRef<TJsonWriter<>> Writer = TJsonWriterFactory<>::Create(&PKCERequestJson);
124+
if (!FJsonSerializer::Serialize(RequestObject.ToSharedRef(), Writer))
125+
{
126+
IMTBL_ERR("Failed to serialize PKCE request to JSON");
127+
FImmutablePassportResult Result;
128+
Result.Success = false;
129+
Result.Error = TEXT("Failed to serialize authentication request");
130+
ResponseDelegate.ExecuteIfBound(Result);
131+
return;
132+
}
137133

138134
CallJS(ImmutablePassportAction::GetPKCEAuthUrl, PKCERequestJson, PKCEResponseDelegate, FImtblJSResponseDelegate::CreateUObject(this, &UImmutablePassport::OnGetAuthUrlResponse));
139135
}

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

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,24 +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)
25+
* @param DirectLoginOptions Direct login options for authentication (email, google, apple, facebook)
2626
*
2727
* @return A reference to the object represented by this node
2828
*/
2929
UFUNCTION(BlueprintCallable, meta = (WorldContext = "WorldContextObject", BlueprintInternalUseOnly = "true"), Category = "Immutable")
30-
static UImtblConnectionAsyncActions* Login(UObject* WorldContextObject, EImmutableDirectLoginMethod DirectLoginMethod = EImmutableDirectLoginMethod::None);
30+
static UImtblConnectionAsyncActions* Login(UObject* WorldContextObject, const FImmutableDirectLoginOptions& DirectLoginOptions);
3131

3232
/**
3333
* Log into Passport, initialise the gamer's wallet and instantiate the IMX provider.
3434
*
3535
* @param WorldContextObject World context
36-
* @param DirectLoginMethod Direct login method to use for authentication (defaults to None for standard login page)
36+
* @param DirectLoginOptions Direct login options for authentication (email, google, apple, facebook)
3737
*
3838
* @return A reference to the object represented by this node
3939
*/
4040
UFUNCTION(BlueprintCallable, meta = (WorldContext = "WorldContextObject", BlueprintInternalUseOnly = "true"), Category = "Immutable")
41-
static UImtblConnectionAsyncActions* ConnectImx(UObject* WorldContextObject, EImmutableDirectLoginMethod DirectLoginMethod = EImmutableDirectLoginMethod::None);
42-
41+
static UImtblConnectionAsyncActions* ConnectImx(UObject* WorldContextObject, const FImmutableDirectLoginOptions& DirectLoginOptions);
4342

4443
virtual void Activate() override;
4544

@@ -56,5 +55,5 @@ class IMMUTABLE_API UImtblConnectionAsyncActions : public UImtblBlueprintAsyncAc
5655
bool bUseCachedSession = false;
5756
bool bIsConnectImx = false;
5857
bool bIsPKCE = false;
59-
EImmutableDirectLoginMethod DirectLoginMethod = EImmutableDirectLoginMethod::None;
58+
FImmutableDirectLoginOptions DirectLoginOptions;
6059
};

Source/Immutable/Public/Immutable/ImmutableDataTypes.h

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,34 @@ DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FImmutableDeepLinkDynamicMulticastDe
2020
UENUM(BlueprintType)
2121
enum class EImmutableDirectLoginMethod : uint8
2222
{
23-
None,
23+
Email,
2424
Google,
2525
Apple,
2626
Facebook
2727
};
2828

29+
/**
30+
* Structure representing direct login options for authentication
31+
* Can be used for social login (google, apple, facebook) or email login
32+
*/
33+
USTRUCT(BlueprintType)
34+
struct IMMUTABLE_API FImmutableDirectLoginOptions
35+
{
36+
GENERATED_BODY()
37+
38+
bool IsEmailValid() const;
39+
40+
TSharedPtr<FJsonObject> ToJsonObject() const;
41+
42+
/** Direct login method for authentication */
43+
UPROPERTY(EditAnywhere, BlueprintReadWrite)
44+
EImmutableDirectLoginMethod DirectLoginMethod = EImmutableDirectLoginMethod::Email;
45+
46+
/** Email address for email-based authentication (only used when DirectLoginMethod is Email) */
47+
UPROPERTY(EditAnywhere, BlueprintReadWrite)
48+
FString Email;
49+
};
50+
2951
USTRUCT()
3052
struct FImmutableEngineVersionData
3153
{
@@ -145,8 +167,6 @@ struct IMMUTABLE_API FImmutablePassportZkEvmGetBalanceData
145167
FString ToJsonString() const;
146168
};
147169

148-
149-
150170
USTRUCT()
151171
struct FImmutablePassportConnectData
152172
{
@@ -171,9 +191,9 @@ struct IMMUTABLE_API FImmutableGetPKCEAuthUrlRequest
171191
UPROPERTY()
172192
bool isConnectImx = false;
173193

174-
/** Direct login method to use for authentication */
194+
/** Direct login options for authentication */
175195
UPROPERTY()
176-
EImmutableDirectLoginMethod directLoginMethod = EImmutableDirectLoginMethod::None;
196+
FImmutableDirectLoginOptions directLoginOptions;
177197
};
178198

179199
USTRUCT()
@@ -350,4 +370,4 @@ class IMMUTABLE_API UImmutablePKCEData : public UObject
350370
* Handle for the ticker delegate that periodically checks for incoming deep links
351371
*/
352372
FTSTicker::FDelegateHandle TickDelegateHandle;
353-
};
373+
};

Source/Immutable/Public/Immutable/ImmutablePassport.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,9 +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).
106+
* @param DirectLoginOptions Direct login options for authentication (email, google, apple, facebook).
107107
*/
108-
void Connect(bool IsConnectImx, const FImtblPassportResponseDelegate& ResponseDelegate, EImmutableDirectLoginMethod DirectLoginMethod = EImmutableDirectLoginMethod::None);
108+
void Connect(bool IsConnectImx, const FImtblPassportResponseDelegate& ResponseDelegate, const FImmutableDirectLoginOptions& DirectLoginOptions);
109109
#endif
110110

111111
/**

0 commit comments

Comments
 (0)