@@ -114,10 +114,14 @@ void UWeb3Auth::processRequest(FString path, FLoginParams* loginParams = nullptr
114
114
115
115
#if !PLATFORM_ANDROID && !PLATFORM_IOS
116
116
FString redirectUrl = startLocalWebServer ();
117
+ this ->redirecturl = redirectUrl.Replace (TEXT (" /complete" ), TEXT (" " ));;
117
118
initParams->SetStringField (" redirectUrl" , redirectUrl);
118
119
#else
119
120
if (web3AuthOptions.redirectUrl != " " )
121
+ {
120
122
initParams->SetStringField (" redirectUrl" , web3AuthOptions.redirectUrl );
123
+ this ->redirecturl = web3AuthOptions.redirectUrl ;
124
+ }
121
125
#endif
122
126
123
127
switch (web3AuthOptions.buildEnv ) {
@@ -249,11 +253,11 @@ void UWeb3Auth::processRequest(FString path, FLoginParams* loginParams = nullptr
249
253
web3AuthOptions.walletSdkUrl = " https://wallet.web3auth.io/v3" ;
250
254
}
251
255
252
- createSession (json, 600 , false );
256
+ createSession (json, 600 , false , " * " );
253
257
}
254
258
255
259
void UWeb3Auth::launchWalletServices (FChainConfig chainConfig) {
256
- this ->sessionId = keyStoreUtils->Get ();
260
+ this ->sessionId = keyStoreUtils->GetSessionId ();
257
261
if (!this ->sessionId .IsEmpty ()) {
258
262
TSharedPtr <FJsonObject> paramMap = MakeShareable (new FJsonObject);
259
263
@@ -296,10 +300,14 @@ void UWeb3Auth::launchWalletServices(FChainConfig chainConfig) {
296
300
297
301
#if !PLATFORM_ANDROID && !PLATFORM_IOS
298
302
FString redirectUrl = startLocalWebServer ();
303
+ this ->redirecturl = redirectUrl.Replace (TEXT (" /complete" ), TEXT (" " ));;
299
304
initParams->SetStringField (" redirectUrl" , redirectUrl);
300
305
#else
301
306
if (web3AuthOptions.redirectUrl != " " )
307
+ {
302
308
initParams->SetStringField (" redirectUrl" , web3AuthOptions.redirectUrl );
309
+ this ->redirecturl = web3AuthOptions.redirectUrl ;
310
+ }
303
311
#endif
304
312
305
313
switch (web3AuthOptions.buildEnv ) {
@@ -378,7 +386,7 @@ void UWeb3Auth::launchWalletServices(FChainConfig chainConfig) {
378
386
web3AuthOptions.walletSdkUrl = " https://wallet.web3auth.io/v2" ;
379
387
}
380
388
381
- createSession (json, 86400 , true );
389
+ createSession (json, 86400 , true , " * " );
382
390
} else {
383
391
UE_LOG (LogTemp, Error, TEXT (" SessionId not found. Please login first." ));
384
392
}
@@ -395,7 +403,7 @@ void UWeb3Auth::processLogout() {
395
403
396
404
void UWeb3Auth::enableMFA (FLoginParams loginParams) {
397
405
UE_LOG (LogTemp, Warning, TEXT (" enableMFA called" ));
398
- this ->sessionId = keyStoreUtils->Get ();
406
+ this ->sessionId = keyStoreUtils->GetSessionId ();
399
407
if (!this ->sessionId .IsEmpty ()) {
400
408
this ->processRequest (" enable_mfa" , &loginParams);
401
409
} else {
@@ -405,7 +413,7 @@ void UWeb3Auth::enableMFA(FLoginParams loginParams) {
405
413
406
414
void UWeb3Auth::request (FChainConfig chainConfig, FString method, TArray<FString> requestParams, FString path)
407
415
{
408
- this ->sessionId = keyStoreUtils->Get ();
416
+ this ->sessionId = keyStoreUtils->GetSessionId ();
409
417
if (!this ->sessionId .IsEmpty ())
410
418
{
411
419
TSharedPtr <FJsonObject> paramMap = MakeShareable (new FJsonObject);
@@ -449,10 +457,14 @@ void UWeb3Auth::request(FChainConfig chainConfig, FString method, TArray<FString
449
457
450
458
#if !PLATFORM_ANDROID && !PLATFORM_IOS
451
459
FString redirectUrl = startLocalWebServer ();
460
+ this ->redirecturl = redirectUrl.Replace (TEXT (" /complete" ), TEXT (" " ));;
452
461
initParams->SetStringField (" redirectUrl" , redirectUrl);
453
462
#else
454
463
if (web3AuthOptions.redirectUrl != " " )
464
+ {
455
465
initParams->SetStringField (" redirectUrl" , web3AuthOptions.redirectUrl );
466
+ this ->redirecturl = web3AuthOptions.redirectUrl ;
467
+ }
456
468
#endif
457
469
458
470
switch (web3AuthOptions.buildEnv ) {
@@ -639,23 +651,21 @@ void UWeb3Auth::setResultUrl(FString hash) {
639
651
// UE_LOG(LogTemp, Warning, TEXT("substringBeforeBrace: %s"), *substringBeforeBrace);
640
652
641
653
if (bIsRequestResponse) {
642
- try
643
- {
644
- TSharedPtr<FJsonObject> jsonObject;
645
- TSharedRef<TJsonReader<>> reader = TJsonReaderFactory<>::Create (substringBeforeBrace);
646
- if (FJsonSerializer::Deserialize (reader, jsonObject) && jsonObject.IsValid ())
647
- {
648
- signResponse.success = jsonObject->GetBoolField (TEXT (" success" ));
649
- signResponse.result = jsonObject->GetStringField (TEXT (" result" ));
650
- signResponse.error = jsonObject->GetStringField (TEXT (" error" ));
651
- // UE_LOG(LogTemp, Warning, TEXT("signResponse - success: %d, result: %s, error: %s"), signResponse.success, *signResponse.result, *signResponse.error);
652
- setSignResponse (signResponse);
653
- }
654
- }
655
- catch (const std::exception & ex)
656
- {
657
- UE_LOG (LogTemp, Warning, TEXT (" Failed to parse SignResponse JSON" ));
658
- }
654
+
655
+ TSharedPtr<FJsonObject> jsonObject;
656
+ TSharedRef<TJsonReader<>> reader = TJsonReaderFactory<>::Create (substringBeforeBrace);
657
+ if (FJsonSerializer::Deserialize (reader, jsonObject) && jsonObject.IsValid ())
658
+ {
659
+ signResponse.success = jsonObject->GetBoolField (TEXT (" success" ));
660
+ signResponse.result = jsonObject->GetStringField (TEXT (" result" ));
661
+ signResponse.error = jsonObject->GetStringField (TEXT (" error" ));
662
+ UE_LOG (LogTemp, Warning, TEXT (" signResponse - success: %d, result: %s, error: %s" ), signResponse.success , *signResponse.result , *signResponse.error );
663
+ setSignResponse (signResponse);
664
+ }
665
+ else
666
+ {
667
+ UE_LOG (LogTemp, Warning, TEXT (" Failed to parse SignResponse JSON" ));
668
+ }
659
669
bIsRequestResponse = false ;
660
670
return ;
661
671
}
@@ -667,7 +677,7 @@ void UWeb3Auth::setResultUrl(FString hash) {
667
677
FSessionResponse response;
668
678
jsonObject->TryGetStringField (TEXT (" sessionId" ), response.sessionId );
669
679
// UE_LOG(LogTemp, Warning, TEXT("Session-ID: %s"), *response.sessionId);
670
- keyStoreUtils->Assign (*response.sessionId );
680
+ keyStoreUtils->Assign (*response.sessionId , * this -> redirecturl );
671
681
this ->sessionId = *response.sessionId ;
672
682
}
673
683
@@ -827,13 +837,17 @@ FUserInfo UWeb3Auth::getUserInfo() {
827
837
}
828
838
829
839
void UWeb3Auth::authorizeSession () {
830
- this ->sessionId = keyStoreUtils->Get ();
840
+ this ->sessionId = keyStoreUtils->GetSessionId ();
831
841
if (!this ->sessionId .IsEmpty ()) {
832
842
FString pubKey = crypto->generatePublicKey (this ->sessionId );
833
843
FString session = this ->sessionId ;
834
- web3AuthApi->AuthorizeSession (pubKey, [session, this ](const FStoreApiResponse& response)
844
+ FString origin = this ->redirecturl ;
845
+ if (origin.IsEmpty ()) {
846
+ origin = keyStoreUtils->GetRedirectUrl ();
847
+ }
848
+ web3AuthApi->AuthorizeSession (pubKey, origin, [session, this ](const FStoreApiResponse& response)
835
849
{
836
- // UE_LOG(LogTemp, Log, TEXT("Response: %s"), *response.message);
850
+ UE_LOG (LogTemp, Log, TEXT (" AuthorizeSession Response: %s" ), *response.message );
837
851
838
852
FShareMetaData shareMetaData;
839
853
@@ -873,11 +887,11 @@ void UWeb3Auth::authorizeSession() {
873
887
}
874
888
875
889
void UWeb3Auth::sessionTimeout () {
876
- this ->sessionId = keyStoreUtils->Get ();
890
+ this ->sessionId = keyStoreUtils->GetSessionId ();
877
891
if (!this ->sessionId .IsEmpty ()) {
878
892
FString pubKey = crypto->generatePublicKey (this ->sessionId );
879
-
880
- web3AuthApi->AuthorizeSession (pubKey, [pubKey, this ](const FStoreApiResponse& response)
893
+ FString origin = keyStoreUtils-> GetRedirectUrl ();
894
+ web3AuthApi->AuthorizeSession (pubKey, origin, [pubKey, this ](const FStoreApiResponse& response)
881
895
{
882
896
FShareMetaData shareMetaData;
883
897
@@ -915,7 +929,7 @@ void UWeb3Auth::sessionTimeout() {
915
929
}
916
930
}
917
931
918
- void UWeb3Auth::createSession (const FString& jsonData, int32 sessionTime, bool isWalletService) {
932
+ void UWeb3Auth::createSession (const FString& jsonData, int32 sessionTime, bool isWalletService, const FString& allowedOrigin ) {
919
933
// UE_LOG(LogTemp, Log, TEXT("CreateSessionJson: %s"), *jsonData);
920
934
FString newSessionKey = crypto->generateRandomSessionKey ();
921
935
FString ephemPublicKey = crypto->generatePublicKey (newSessionKey);
@@ -952,6 +966,7 @@ void UWeb3Auth::createSession(const FString& jsonData, int32 sessionTime, bool i
952
966
request.key = ephemPublicKey;
953
967
request.signature = sig;
954
968
request.timeout = FMath::Min (sessionTime, 7 * 86400 );
969
+ request.allowedOrigin = allowedOrigin;
955
970
956
971
web3AuthApi->CreateSession (request, [this , newSessionKey, isWalletService](const FString& response)
957
972
{
@@ -1047,7 +1062,7 @@ void UWeb3Auth::handleCreateSessionResponse(const FString& path, const FString&
1047
1062
loginIdObject->SetStringField (TEXT (" loginId" ), newSessionKey);
1048
1063
1049
1064
if (isWalletService) {
1050
- this ->sessionId = keyStoreUtils->Get ();
1065
+ this ->sessionId = keyStoreUtils->GetSessionId ();
1051
1066
loginIdObject->SetStringField (TEXT (" sessionId" ), this ->sessionId );
1052
1067
loginIdObject->SetStringField (TEXT (" platform" ), " unreal" );
1053
1068
}
0 commit comments