diff --git a/Content/Example.umap b/Content/Example.umap index 6187f74..b4c64ce 100644 Binary files a/Content/Example.umap and b/Content/Example.umap differ diff --git a/Plugins/Web3AuthSDK/Content/AuthInterface.uasset b/Plugins/Web3AuthSDK/Content/AuthInterface.uasset index d3a7d22..81af856 100644 Binary files a/Plugins/Web3AuthSDK/Content/AuthInterface.uasset and b/Plugins/Web3AuthSDK/Content/AuthInterface.uasset differ diff --git a/Plugins/Web3AuthSDK/Source/Web3AuthSDK/Private/KeyStoreUtils.cpp b/Plugins/Web3AuthSDK/Source/Web3AuthSDK/Private/KeyStoreUtils.cpp index d09dafa..27ac48e 100644 --- a/Plugins/Web3AuthSDK/Source/Web3AuthSDK/Private/KeyStoreUtils.cpp +++ b/Plugins/Web3AuthSDK/Source/Web3AuthSDK/Private/KeyStoreUtils.cpp @@ -6,17 +6,18 @@ UKeyStoreUtils::UKeyStoreUtils() { UKeyStoreUtils::~UKeyStoreUtils() {} -void UKeyStoreUtils::Assign(FString value) { +void UKeyStoreUtils::Assign(FString sessionId, FString redirectUrl) { UWeb3StorageAdapter* saveGameInstance = Cast(UGameplayStatics::CreateSaveGameObject(UWeb3StorageAdapter::StaticClass())); if (saveGameInstance) { - saveGameInstance->sessionId = value; + saveGameInstance->sessionId = sessionId; + saveGameInstance->redirectUrl = redirectUrl; UGameplayStatics::SaveGameToSlot(saveGameInstance, TEXT("Web3AuthDataSlot"), 0); } } -FString UKeyStoreUtils::Get() { +FString UKeyStoreUtils::GetSessionId() { UWeb3StorageAdapter* saveGameInstance = Cast(UGameplayStatics::LoadGameFromSlot(TEXT("Web3AuthDataSlot"), 0)); if (saveGameInstance) @@ -32,6 +33,17 @@ void UKeyStoreUtils::Clear() { if (saveGameInstance) { saveGameInstance->sessionId = ""; + saveGameInstance->redirectUrl = ""; UGameplayStatics::SaveGameToSlot(saveGameInstance, TEXT("Web3AuthDataSlot"), 0); } -} \ No newline at end of file +} + +FString UKeyStoreUtils::GetRedirectUrl() { + UWeb3StorageAdapter* saveGameInstance = Cast(UGameplayStatics::LoadGameFromSlot(TEXT("Web3AuthDataSlot"), 0)); + + if (saveGameInstance) + { + return saveGameInstance->redirectUrl; + } + return ""; +} diff --git a/Plugins/Web3AuthSDK/Source/Web3AuthSDK/Private/Web3Auth.cpp b/Plugins/Web3AuthSDK/Source/Web3AuthSDK/Private/Web3Auth.cpp index b0b7be8..d92c190 100644 --- a/Plugins/Web3AuthSDK/Source/Web3AuthSDK/Private/Web3Auth.cpp +++ b/Plugins/Web3AuthSDK/Source/Web3AuthSDK/Private/Web3Auth.cpp @@ -114,10 +114,14 @@ void UWeb3Auth::processRequest(FString path, FLoginParams* loginParams = nullptr #if !PLATFORM_ANDROID && !PLATFORM_IOS FString redirectUrl = startLocalWebServer(); + this->redirecturl = redirectUrl.Replace(TEXT("/complete"), TEXT(""));; initParams->SetStringField("redirectUrl", redirectUrl); #else if (web3AuthOptions.redirectUrl != "") + { initParams->SetStringField("redirectUrl", web3AuthOptions.redirectUrl); + this->redirecturl = web3AuthOptions.redirectUrl; + } #endif switch (web3AuthOptions.buildEnv) { @@ -233,27 +237,27 @@ void UWeb3Auth::processRequest(FString path, FLoginParams* loginParams = nullptr FJsonSerializer::Serialize(paramMap.ToSharedRef(), jsonWriter); if (web3AuthOptions.buildEnv == FBuildEnv::STAGING) { - web3AuthOptions.sdkUrl = "https://staging-auth.web3auth.io/v8"; + web3AuthOptions.sdkUrl = "https://staging-auth.web3auth.io/v9"; } else if(web3AuthOptions.buildEnv == FBuildEnv::TESTING) { web3AuthOptions.sdkUrl = "https://develop-auth.web3auth.io"; } else { - web3AuthOptions.sdkUrl = "https://auth.web3auth.io/v8"; + web3AuthOptions.sdkUrl = "https://auth.web3auth.io/v9"; } if (web3AuthOptions.buildEnv == FBuildEnv::STAGING) { - web3AuthOptions.walletSdkUrl = "https://staging-wallet.web3auth.io/v2"; + web3AuthOptions.walletSdkUrl = "https://staging-wallet.web3auth.io/v3"; } else if (web3AuthOptions.buildEnv == FBuildEnv::TESTING) { web3AuthOptions.walletSdkUrl = "https://develop-wallet.web3auth.io"; } else { - web3AuthOptions.walletSdkUrl = "https://wallet.web3auth.io/v2"; + web3AuthOptions.walletSdkUrl = "https://wallet.web3auth.io/v3"; } - createSession(json, 600, false); + createSession(json, 600, false, "*"); } void UWeb3Auth::launchWalletServices(FChainConfig chainConfig) { - this->sessionId = keyStoreUtils->Get(); + this->sessionId = keyStoreUtils->GetSessionId(); if (!this->sessionId.IsEmpty()) { TSharedPtr paramMap = MakeShareable(new FJsonObject); @@ -296,10 +300,14 @@ void UWeb3Auth::launchWalletServices(FChainConfig chainConfig) { #if !PLATFORM_ANDROID && !PLATFORM_IOS FString redirectUrl = startLocalWebServer(); + this->redirecturl = redirectUrl.Replace(TEXT("/complete"), TEXT(""));; initParams->SetStringField("redirectUrl", redirectUrl); #else if (web3AuthOptions.redirectUrl != "") + { initParams->SetStringField("redirectUrl", web3AuthOptions.redirectUrl); + this->redirecturl = web3AuthOptions.redirectUrl; + } #endif switch (web3AuthOptions.buildEnv) { @@ -371,14 +379,14 @@ void UWeb3Auth::launchWalletServices(FChainConfig chainConfig) { FJsonSerializer::Serialize(paramMap.ToSharedRef(), jsonWriter); if (web3AuthOptions.buildEnv == FBuildEnv::STAGING) { - web3AuthOptions.walletSdkUrl = "https://staging-wallet.web3auth.io/v2"; + web3AuthOptions.walletSdkUrl = "https://staging-wallet.web3auth.io/v3"; } else if (web3AuthOptions.buildEnv == FBuildEnv::TESTING) { web3AuthOptions.walletSdkUrl = "https://develop-wallet.web3auth.io"; } else { - web3AuthOptions.walletSdkUrl = "https://wallet.web3auth.io/v2"; + web3AuthOptions.walletSdkUrl = "https://wallet.web3auth.io/v3"; } - createSession(json, 86400, true); + createSession(json, 86400, true, "*"); } else { UE_LOG(LogTemp, Error, TEXT("SessionId not found. Please login first.")); } @@ -395,7 +403,7 @@ void UWeb3Auth::processLogout() { void UWeb3Auth::enableMFA(FLoginParams loginParams) { UE_LOG(LogTemp, Warning, TEXT("enableMFA called")); - this->sessionId = keyStoreUtils->Get(); + this->sessionId = keyStoreUtils->GetSessionId(); if (!this->sessionId.IsEmpty()) { this->processRequest("enable_mfa", &loginParams); } else { @@ -405,7 +413,7 @@ void UWeb3Auth::enableMFA(FLoginParams loginParams) { void UWeb3Auth::request(FChainConfig chainConfig, FString method, TArray requestParams, FString path) { - this->sessionId = keyStoreUtils->Get(); + this->sessionId = keyStoreUtils->GetSessionId(); if (!this->sessionId.IsEmpty()) { TSharedPtr paramMap = MakeShareable(new FJsonObject); @@ -449,10 +457,14 @@ void UWeb3Auth::request(FChainConfig chainConfig, FString method, TArrayredirecturl = redirectUrl.Replace(TEXT("/complete"), TEXT(""));; initParams->SetStringField("redirectUrl", redirectUrl); #else if (web3AuthOptions.redirectUrl != "") + { initParams->SetStringField("redirectUrl", web3AuthOptions.redirectUrl); + this->redirecturl = web3AuthOptions.redirectUrl; + } #endif switch (web3AuthOptions.buildEnv) { @@ -507,11 +519,11 @@ void UWeb3Auth::request(FChainConfig chainConfig, FString method, TArray jsonObject; - TSharedRef> reader = TJsonReaderFactory<>::Create(substringBeforeBrace); - if (FJsonSerializer::Deserialize(reader, jsonObject) && jsonObject.IsValid()) - { - signResponse.success = jsonObject->GetBoolField(TEXT("success")); - signResponse.result = jsonObject->GetStringField(TEXT("result")); - signResponse.error = jsonObject->GetStringField(TEXT("error")); - //UE_LOG(LogTemp, Warning, TEXT("signResponse - success: %d, result: %s, error: %s"), signResponse.success, *signResponse.result, *signResponse.error); - setSignResponse(signResponse); - } - } - catch (const std::exception& ex) - { - UE_LOG(LogTemp, Warning, TEXT("Failed to parse SignResponse JSON")); - } + + TSharedPtr jsonObject; + TSharedRef> reader = TJsonReaderFactory<>::Create(substringBeforeBrace); + if (FJsonSerializer::Deserialize(reader, jsonObject) && jsonObject.IsValid()) + { + signResponse.success = jsonObject->GetBoolField(TEXT("success")); + signResponse.result = jsonObject->GetStringField(TEXT("result")); + signResponse.error = jsonObject->GetStringField(TEXT("error")); + UE_LOG(LogTemp, Warning, TEXT("signResponse - success: %d, result: %s, error: %s"), signResponse.success, *signResponse.result, *signResponse.error); + setSignResponse(signResponse); + } + else + { + UE_LOG(LogTemp, Warning, TEXT("Failed to parse SignResponse JSON")); + } bIsRequestResponse = false; return; } @@ -667,10 +677,11 @@ void UWeb3Auth::setResultUrl(FString hash) { FSessionResponse response; jsonObject->TryGetStringField(TEXT("sessionId"), response.sessionId); //UE_LOG(LogTemp, Warning, TEXT("Session-ID: %s"), *response.sessionId); - keyStoreUtils->Assign(*response.sessionId); + keyStoreUtils->Assign(*response.sessionId, *this->redirecturl); this->sessionId = *response.sessionId; } + //UE_LOG(LogTemp, Warning, TEXT("authorizeSession called: Session-ID: %s"), "authorizeSession"); authorizeSession(); } @@ -827,13 +838,20 @@ FUserInfo UWeb3Auth::getUserInfo() { } void UWeb3Auth::authorizeSession() { - this->sessionId = keyStoreUtils->Get(); + this->sessionId = keyStoreUtils->GetSessionId(); if (!this->sessionId.IsEmpty()) { + //UE_LOG(LogTemp, Warning, TEXT("Inside authorizeSession Session-ID: %s"), *this->sessionId); FString pubKey = crypto->generatePublicKey(this->sessionId); FString session = this->sessionId; - web3AuthApi->AuthorizeSession(pubKey, [session, this](const FStoreApiResponse& response) + FString origin = this->redirecturl; + //UE_LOG(LogTemp, Warning, TEXT("In authorizeSession Session-ID: %s"), *session); + //UE_LOG(LogTemp, Warning, TEXT("In authorizeSession Origin: %s"), *origin); + if(origin.IsEmpty()) { + origin = keyStoreUtils->GetRedirectUrl(); + } + web3AuthApi->AuthorizeSession(pubKey, origin, [session, this](const FStoreApiResponse& response) { - //UE_LOG(LogTemp, Log, TEXT("Response: %s"), *response.message); + UE_LOG(LogTemp, Log, TEXT("AuthorizeSession Response: %s"), *response.message); FShareMetaData shareMetaData; @@ -873,11 +891,11 @@ void UWeb3Auth::authorizeSession() { } void UWeb3Auth::sessionTimeout() { - this->sessionId = keyStoreUtils->Get(); + this->sessionId = keyStoreUtils->GetSessionId(); if (!this->sessionId.IsEmpty()) { FString pubKey = crypto->generatePublicKey(this->sessionId); - - web3AuthApi->AuthorizeSession(pubKey, [pubKey, this](const FStoreApiResponse& response) + FString origin = keyStoreUtils->GetRedirectUrl(); + web3AuthApi->AuthorizeSession(pubKey, origin, [pubKey, this](const FStoreApiResponse& response) { FShareMetaData shareMetaData; @@ -915,7 +933,7 @@ void UWeb3Auth::sessionTimeout() { } } -void UWeb3Auth::createSession(const FString& jsonData, int32 sessionTime, bool isWalletService) { +void UWeb3Auth::createSession(const FString& jsonData, int32 sessionTime, bool isWalletService, const FString& allowedOrigin) { //UE_LOG(LogTemp, Log, TEXT("CreateSessionJson: %s"), *jsonData); FString newSessionKey = crypto->generateRandomSessionKey(); FString ephemPublicKey = crypto->generatePublicKey(newSessionKey); @@ -951,7 +969,8 @@ void UWeb3Auth::createSession(const FString& jsonData, int32 sessionTime, bool i request.data = jsonString; request.key = ephemPublicKey; request.signature = sig; - request.timeout = FMath::Min(sessionTime, 7 * 86400); + request.timeout = FMath::Min(sessionTime, 30 * 86400); + request.allowedOrigin = allowedOrigin; web3AuthApi->CreateSession(request, [this, newSessionKey, isWalletService](const FString& response) { @@ -1047,7 +1066,7 @@ void UWeb3Auth::handleCreateSessionResponse(const FString& path, const FString& loginIdObject->SetStringField(TEXT("loginId"), newSessionKey); if(isWalletService) { - this->sessionId = keyStoreUtils->Get(); + this->sessionId = keyStoreUtils->GetSessionId(); loginIdObject->SetStringField(TEXT("sessionId"), this->sessionId); loginIdObject->SetStringField(TEXT("platform"), "unreal"); } diff --git a/Plugins/Web3AuthSDK/Source/Web3AuthSDK/Private/Web3AuthApi.cpp b/Plugins/Web3AuthSDK/Source/Web3AuthSDK/Private/Web3AuthApi.cpp index 188cf00..d2f673f 100644 --- a/Plugins/Web3AuthSDK/Source/Web3AuthSDK/Private/Web3AuthApi.cpp +++ b/Plugins/Web3AuthSDK/Source/Web3AuthSDK/Private/Web3AuthApi.cpp @@ -23,15 +23,19 @@ UWeb3AuthApi* UWeb3AuthApi::GetInstance() } -void UWeb3AuthApi::AuthorizeSession(const FString& key, const TFunction callback) +void UWeb3AuthApi::AuthorizeSession(const FString& key, const FString& origin, const TFunction callback) { TSharedRef request = FHttpModule::Get().CreateRequest(); request->SetVerb(TEXT("POST")); - request->SetURL(TEXT("https://session.web3auth.io/store/get?key=" + key)); - + request->SetURL(TEXT("https://session.web3auth.io/v2/store/get?key=" + key)); + + //UELog(LogTemp, Log, TEXT("key: %s"), *key); + //UELog(LogTemp, Log, TEXT("origin: %s"), *origin); FString FormString = "key=" + key; + //UE_LOG(LogTemp, Log, TEXT("FormString: %s"), *FormString); request->SetHeader(TEXT("Content-Type"), TEXT("application/x-www-form-urlencoded")); + request->SetHeader(TEXT("origin"), origin); request->SetContentAsString(FormString); request->OnProcessRequestComplete().BindLambda([callback](FHttpRequestPtr request, FHttpResponsePtr response, bool success) { @@ -60,7 +64,7 @@ void UWeb3AuthApi::Logout(const FLogoutApiRequest logoutApiRequest, const TFunct { TSharedRef request = FHttpModule::Get().CreateRequest(); request->SetVerb(TEXT("POST")); - request->SetURL(TEXT("https://session.web3auth.io/store/set")); + request->SetURL(TEXT("https://session.web3auth.io/v2/store/set")); FString FormString = "key=" + logoutApiRequest.key + "&data=" + FGenericPlatformHttp::UrlEncode(logoutApiRequest.data) + "&signature=" + logoutApiRequest.signature + "&timeout=" + FString::FromInt(logoutApiRequest.timeout); @@ -87,7 +91,7 @@ void UWeb3AuthApi::CreateSession(const FLogoutApiRequest logoutApiRequest, const { TSharedRef request = FHttpModule::Get().CreateRequest(); request->SetVerb(TEXT("POST")); - request->SetURL(TEXT("https://session.web3auth.io/store/set")); + request->SetURL(TEXT("https://session.web3auth.io/v2/store/set")); FString FormString = "key=" + logoutApiRequest.key + "&data=" + FGenericPlatformHttp::UrlEncode(logoutApiRequest.data) + "&signature=" + logoutApiRequest.signature + "&timeout=" + FString::FromInt(logoutApiRequest.timeout); diff --git a/Plugins/Web3AuthSDK/Source/Web3AuthSDK/Public/KeyStoreUtils.h b/Plugins/Web3AuthSDK/Source/Web3AuthSDK/Public/KeyStoreUtils.h index afa2017..369306c 100644 --- a/Plugins/Web3AuthSDK/Source/Web3AuthSDK/Public/KeyStoreUtils.h +++ b/Plugins/Web3AuthSDK/Source/Web3AuthSDK/Public/KeyStoreUtils.h @@ -12,6 +12,9 @@ class UWeb3StorageAdapter : public USaveGame public: UPROPERTY(VisibleAnywhere, Category = Basic) FString sessionId; + + UPROPERTY(VisibleAnywhere, Category = Basic) + FString redirectUrl; }; UCLASS() @@ -24,8 +27,9 @@ class WEB3AUTHSDK_API UKeyStoreUtils : public UObject UKeyStoreUtils(); ~UKeyStoreUtils(); - void Assign(FString value); - FString Get(); + void Assign(FString sessionId, FString redirectUrl); + FString GetSessionId(); + FString GetRedirectUrl(); void Clear(); }; diff --git a/Plugins/Web3AuthSDK/Source/Web3AuthSDK/Public/Web3Auth.h b/Plugins/Web3AuthSDK/Source/Web3AuthSDK/Public/Web3Auth.h index 2431b3e..09848f5 100644 --- a/Plugins/Web3AuthSDK/Source/Web3AuthSDK/Public/Web3Auth.h +++ b/Plugins/Web3AuthSDK/Source/Web3AuthSDK/Public/Web3Auth.h @@ -609,10 +609,10 @@ struct FWeb3AuthOptions FString redirectUrl; UPROPERTY(EditAnywhere, BlueprintReadWrite) - FString sdkUrl = "https://sdk.openlogin.com/v8"; + FString sdkUrl = "https://sdk.openlogin.com/v9"; UPROPERTY(EditAnywhere, BlueprintReadWrite) - FString walletSdkUrl = "https://wallet.web3auth.io/v1"; + FString walletSdkUrl = "https://wallet.web3auth.io/v3"; UPROPERTY(EditAnywhere, BlueprintReadWrite) FNetwork network; @@ -747,6 +747,9 @@ class WEB3AUTHSDK_API UWeb3Auth : public UGameInstanceSubsystem UPROPERTY(VisibleAnywhere, BlueprintReadOnly) FString sessionId = FString(); + UPROPERTY(VisibleAnywhere, BlueprintReadOnly) + FString redirecturl = FString(); + UFUNCTION(BlueprintCallable) void setOptions(FWeb3AuthOptions web3authOptions); @@ -823,7 +826,7 @@ class WEB3AUTHSDK_API UWeb3Auth : public UGameInstanceSubsystem void authorizeSession(); void sessionTimeout(); - void createSession(const FString& jsonData, int32 sessionTime, bool isWalletService); + void createSession(const FString& jsonData, int32 sessionTime, bool isWalletService, const FString& allowedOrigin); void handleCreateSessionResponse(const FString& path, const FString& newSessionKey, bool isWalletService); void fetchProjectConfig(); FWhiteLabelData mergeWhiteLabelData(const FWhiteLabelData& other); diff --git a/Plugins/Web3AuthSDK/Source/Web3AuthSDK/Public/Web3AuthApi.h b/Plugins/Web3AuthSDK/Source/Web3AuthSDK/Public/Web3AuthApi.h index 99d11d6..ea1b985 100644 --- a/Plugins/Web3AuthSDK/Source/Web3AuthSDK/Public/Web3AuthApi.h +++ b/Plugins/Web3AuthSDK/Source/Web3AuthSDK/Public/Web3AuthApi.h @@ -131,6 +131,9 @@ struct FLogoutApiRequest UPROPERTY() int32 timeout; + + UPROPERTY() + FString allowedOrigin; }; USTRUCT() @@ -174,7 +177,7 @@ class WEB3AUTHSDK_API UWeb3AuthApi : public UObject static UWeb3AuthApi* GetInstance(); // Authorize the user session - void AuthorizeSession(const FString& key, const TFunction callback); + void AuthorizeSession(const FString& key, const FString& origin, const TFunction callback); // Logout the user session void Logout(const FLogoutApiRequest logoutApiRequest, const TFunction callback);