Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 21 additions & 20 deletions Plugins/Web3AuthSDK/Source/Web3AuthSDK/Private/Web3Auth.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ void UWeb3Auth::setOptions(FWeb3AuthOptions options) {
authorizeSession();
}

void UWeb3Auth::request(FString path, FLoginParams* loginParams = NULL, TSharedPtr<FJsonObject> extraParams = NULL) {
void UWeb3Auth::request(FString path, FLoginParams* loginParams = nullptr, TSharedPtr<FJsonObject> extraParams = nullptr) {
TSharedPtr<FJsonObject> paramMap = MakeShareable(new FJsonObject);


Expand Down Expand Up @@ -81,7 +81,7 @@ void UWeb3Auth::request(FString path, FLoginParams* loginParams = NULL, TSharedP

FMfaSettings defaultMFA;

if (!(web3AuthOptions.mfaSettings == defaultMFA))
if (web3AuthOptions.mfaSettings != defaultMFA)
{
FString mfaSettingsJson;
FJsonObjectConverter::UStructToJsonObjectString(web3AuthOptions.mfaSettings, mfaSettingsJson);
Expand Down Expand Up @@ -157,11 +157,11 @@ void UWeb3Auth::request(FString path, FLoginParams* loginParams = NULL, TSharedP
params->SetStringField("curve", "ed25519");
}

if (extraParams != NULL) {
if (extraParams != nullptr) {
params = extraParams;
}

if (loginParams != NULL) {
if (loginParams != nullptr) {
for (auto o : loginParams->getJsonObject().Values) {
params->SetField(o.Key, o.Value);
}
Expand Down Expand Up @@ -247,7 +247,7 @@ void UWeb3Auth::launchWalletServices(FLoginParams loginParams, FChainConfig chai

FMfaSettings defaultMFA;

if (!(web3AuthOptions.mfaSettings == defaultMFA)) {
if (web3AuthOptions.mfaSettings != defaultMFA) {
FString mfaSettingsJson;
FJsonObjectConverter::UStructToJsonObjectString(web3AuthOptions.mfaSettings,
mfaSettingsJson);
Expand Down Expand Up @@ -403,12 +403,12 @@ void UWeb3Auth::setResultUrl(FString hash) {
int32 braceIndex = decodedString.Find(TEXT("}"));
FString substringBeforeBrace = decodedString.Left(braceIndex + 1);
//UE_LOG(LogTemp, Warning, TEXT("substringBeforeBrace: %s"), *substringBeforeBrace);

FSessionResponse response;

TSharedPtr<FJsonObject> jsonObject;
TSharedRef<TJsonReader<>> reader = TJsonReaderFactory<>::Create(substringBeforeBrace);
if (FJsonSerializer::Deserialize(reader, jsonObject) && jsonObject.IsValid())
{
FSessionResponse response;
jsonObject->TryGetStringField(TEXT("sessionId"), response.sessionId);
//UE_LOG(LogTemp, Warning, TEXT("Session-ID: %s"), *response.sessionId);
keyStoreUtils->Assign(*response.sessionId);
Expand Down Expand Up @@ -439,11 +439,12 @@ FString UWeb3Auth::startLocalWebServer() {
}

if (httpRouter.IsValid()) {

auto x = httpRouter->BindRoute(FHttpPath(TEXT("/auth")), EHttpServerRequestVerbs::VERB_GET,
[this](const FHttpServerRequest& Request, const FHttpResultCallback& OnComplete) { return requestAuthCallback(Request, OnComplete); });
FHttpRequestHandler::CreateLambda([this](const FHttpServerRequest& Request, const FHttpResultCallback& OnComplete) { return requestAuthCallback(Request, OnComplete); }));

auto y = httpRouter->BindRoute(FHttpPath(TEXT("/complete")), EHttpServerRequestVerbs::VERB_GET,
[this](const FHttpServerRequest& Request, const FHttpResultCallback& OnComplete) { return requestCompleteCallback(Request, OnComplete); });
FHttpRequestHandler::CreateLambda([this](const FHttpServerRequest& Request, const FHttpResultCallback& OnComplete) { return requestCompleteCallback(Request, OnComplete); }));

httpRoutes.Add(TPairInitializer<TSharedPtr<IHttpRouter>, FHttpRouteHandle>(httpRouter, x));
httpRoutes.Add(TPairInitializer<TSharedPtr<IHttpRouter>, FHttpRouteHandle>(httpRouter, y));
Expand Down Expand Up @@ -502,7 +503,7 @@ bool UWeb3Auth::requestCompleteCallback(const FHttpServerRequest& Request, const
if (window.location.hash.trim() == "") {
document.querySelector("#error").style.display="flex";
} else {
fetch(`http://${window.location.host}/auth/?code=${window.location.hash.slice(1,window.location.hash.length)}`).then(function(response) {
fetch(`https://${window.location.host}/auth/?code=${window.location.hash.slice(1,window.location.hash.length)}`).then(function(response) {
console.log(response);
document.querySelector("#success").style.display="flex";
}).catch(function(error) {
Expand Down Expand Up @@ -572,7 +573,7 @@ void UWeb3Auth::authorizeSession() {
if (!this->sessionId.IsEmpty()) {
FString pubKey = crypto->generatePublicKey(this->sessionId);
FString session = this->sessionId;
web3AuthApi->AuthorizeSession(pubKey, [session, this](FStoreApiResponse response)
web3AuthApi->AuthorizeSession(pubKey, [session, this](const FStoreApiResponse& response)
{
//UE_LOG(LogTemp, Log, TEXT("Response: %s"), *response.message);

Expand Down Expand Up @@ -602,9 +603,9 @@ void UWeb3Auth::authorizeSession() {
if (web3AuthResponse.error != "") {
return;
}

this->loginEvent.ExecuteIfBound(web3AuthResponse);
this->mfaEvent.ExecuteIfBound(true);
(void) this->loginEvent.ExecuteIfBound(web3AuthResponse);
(void) this->mfaEvent.ExecuteIfBound(true);
}

});
Expand All @@ -618,7 +619,7 @@ void UWeb3Auth::sessionTimeout() {
if (!this->sessionId.IsEmpty()) {
FString pubKey = crypto->generatePublicKey(this->sessionId);

web3AuthApi->AuthorizeSession(pubKey, [pubKey, this](FStoreApiResponse response)
web3AuthApi->AuthorizeSession(pubKey, [pubKey, this](const FStoreApiResponse& response)
{
FShareMetaData shareMetaData;

Expand All @@ -645,10 +646,10 @@ void UWeb3Auth::sessionTimeout() {
request.signature = sig;
request.timeout = 1;

web3AuthApi->Logout(request, [this](FString response)
web3AuthApi->Logout(request, [this](const FString& response)
{
UE_LOG(LogTemp, Log, TEXT("Response: %s"), *response);
this->logoutEvent.ExecuteIfBound();
(void) this->logoutEvent.ExecuteIfBound();
this->sessionId = FString();
keyStoreUtils->Clear();
});
Expand Down Expand Up @@ -694,7 +695,7 @@ void UWeb3Auth::createSession(const FString& jsonData, int32 sessionTime, bool i
request.signature = sig;
request.timeout = FMath::Min(sessionTime, 7 * 86400);

web3AuthApi->CreateSession(request, [this, newSessionKey, isWalletService](FString response)
web3AuthApi->CreateSession(request, [this, newSessionKey, isWalletService](const FString& response)
{
UE_LOG(LogTemp, Log, TEXT("Response: %s"), *response);
if(isWalletService) {
Expand All @@ -705,7 +706,7 @@ void UWeb3Auth::createSession(const FString& jsonData, int32 sessionTime, bool i
});
}

void UWeb3Auth::handleCreateSessionResponse(FString path, FString newSessionKey, bool isWalletService) {
void UWeb3Auth::handleCreateSessionResponse(const FString& path, const FString& newSessionKey, bool isWalletService) {
TSharedPtr<FJsonObject> loginIdObject = MakeShareable(new FJsonObject);
loginIdObject->SetStringField(TEXT("loginId"), newSessionKey);

Expand Down Expand Up @@ -742,7 +743,7 @@ void UWeb3Auth::handleCreateSessionResponse(FString path, FString newSessionKey,
thiz_instance = this;
[[WebAuthenticate Singleton] launchUrl:TCHAR_TO_ANSI(*url)];
#else
FPlatformProcess::LaunchURL(*url, NULL, NULL);
FPlatformProcess::LaunchURL(*url, nullptr, nullptr);
#endif
}

Expand Down
4 changes: 2 additions & 2 deletions Plugins/Web3AuthSDK/Source/Web3AuthSDK/Public/Web3Auth.h
Original file line number Diff line number Diff line change
Expand Up @@ -849,10 +849,10 @@ class WEB3AUTHSDK_API UWeb3Auth : public UGameInstanceSubsystem
FString startLocalWebServer();

bool requestAuthCallback(const FHttpServerRequest& Request, const FHttpResultCallback& OnComplete);
bool requestCompleteCallback(const FHttpServerRequest& Request, const FHttpResultCallback& OnComplete);
static bool requestCompleteCallback(const FHttpServerRequest& Request, const FHttpResultCallback& OnComplete);

void authorizeSession();
void sessionTimeout();
void createSession(const FString& jsonData, int32 sessionTime, bool isWalletService);
void handleCreateSessionResponse(FString path, FString newSessionKey, bool isWalletService);
void handleCreateSessionResponse(const FString& path, const FString& newSessionKey, bool isWalletService);
};
4 changes: 3 additions & 1 deletion Source/Web3AuthUnrealSDK.Target.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ public class Web3AuthUnrealSDKTarget : TargetRules
public Web3AuthUnrealSDKTarget( TargetInfo Target) : base(Target)
{
Type = TargetType.Game;
DefaultBuildSettings = BuildSettingsVersion.V2;
DefaultBuildSettings = BuildSettingsVersion.Latest;
IncludeOrderVersion = EngineIncludeOrderVersion.Latest;
bOverrideBuildEnvironment = true;
ExtraModuleNames.AddRange( new string[] { "Web3AuthUnrealSDK" } );
}
}
4 changes: 3 additions & 1 deletion Source/Web3AuthUnrealSDKEditor.Target.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ public class Web3AuthUnrealSDKEditorTarget : TargetRules
public Web3AuthUnrealSDKEditorTarget( TargetInfo Target) : base(Target)
{
Type = TargetType.Editor;
DefaultBuildSettings = BuildSettingsVersion.V2;
DefaultBuildSettings = BuildSettingsVersion.Latest;
IncludeOrderVersion = EngineIncludeOrderVersion.Latest;
bOverrideBuildEnvironment = true;
ExtraModuleNames.AddRange( new string[] { "Web3AuthUnrealSDK" } );
}
}