23
23
#include " GenericPlatform/GenericPlatformProcess.h"
24
24
#include " Mac/ImmutableMac.h"
25
25
#endif
26
+ #if PLATFORM_WINDOWS
27
+ #include " Immutable/Windows/ImmutablePKCEWindows.h"
28
+ #endif
26
29
27
30
#define PASSPORT_SAVE_GAME_SLOT_NAME TEXT (" Immutable" )
28
31
@@ -101,10 +104,22 @@ void UImmutablePassport::Connect(bool IsConnectImx, bool TryToRelogin, const FIm
101
104
}
102
105
}
103
106
104
- #if PLATFORM_ANDROID | PLATFORM_IOS | PLATFORM_MAC
107
+ #if PLATFORM_ANDROID | PLATFORM_IOS | PLATFORM_MAC | PLATFORM_WINDOWS
105
108
void UImmutablePassport::ConnectPKCE (bool IsConnectImx, const FImtblPassportResponseDelegate& ResponseDelegate)
106
109
{
107
110
SetStateFlags (IPS_CONNECTING | IPS_PKCE);
111
+
112
+ #if PLATFORM_WINDOWS
113
+ // Verify PKCEData is null before initializing to ensure we're not overriding an active PKCE operation.
114
+ // A non-null value indicates another PKCE operation is already in progress.
115
+ ensureAlways (!PKCEData);
116
+ PKCEData = UImmutablePKCEWindows::Initialise (InitData);
117
+ if (PKCEData)
118
+ {
119
+ PKCEData->DynamicMulticastDelegate_DeepLinkCallback .AddDynamic (this , &ThisClass::OnDeepLinkActivated);
120
+ }
121
+ #endif
122
+
108
123
if (IsConnectImx)
109
124
{
110
125
SetStateFlags (IPS_IMX);
@@ -117,7 +132,16 @@ void UImmutablePassport::ConnectPKCE(bool IsConnectImx, const FImtblPassportResp
117
132
118
133
void UImmutablePassport::Logout (bool DoHardLogout, const FImtblPassportResponseDelegate& ResponseDelegate)
119
134
{
120
- #if PLATFORM_ANDROID | PLATFORM_IOS | PLATFORM_MAC
135
+ #if PLATFORM_ANDROID | PLATFORM_IOS | PLATFORM_MAC | PLATFORM_WINDOWS
136
+ // Verify PKCEData is null before initializing to ensure we're not overriding an active PKCE operation.
137
+ // A non-null value indicates another PKCE operation is already in progress.
138
+ ensureAlways (!PKCEData);
139
+ PKCEData = UImmutablePKCEWindows::Initialise (InitData);
140
+ if (PKCEData)
141
+ {
142
+ PKCEData->DynamicMulticastDelegate_DeepLinkCallback .AddDynamic (this , &ThisClass::OnDeepLinkActivated);
143
+ }
144
+
121
145
if (IsStateFlagsSet (IPS_PKCE))
122
146
{
123
147
PKCELogoutResponseDelegate = ResponseDelegate;
@@ -392,7 +416,7 @@ TOptional<UImmutablePassport::FImtblPassportResponseDelegate> UImmutablePassport
392
416
393
417
void UImmutablePassport::OnInitializeResponse (FImtblJSResponse Response)
394
418
{
395
- if (auto ResponseDelegate = GetResponseDelegate (Response))
419
+ if (TOptional<FImtblPassportResponseDelegate> ResponseDelegate = GetResponseDelegate (Response))
396
420
{
397
421
FString Error;
398
422
@@ -470,43 +494,55 @@ void UImmutablePassport::OnLogoutResponse(FImtblJSResponse Response)
470
494
471
495
return ;
472
496
}
473
-
474
- FString Url;
475
- FString ErrorMessage;
497
+
498
+ auto Logout = [this ](const FImtblJSResponse& Response)
499
+ {
500
+ TOptional<FImtblPassportResponseDelegate> ResponseDelegate = GetResponseDelegate (Response);
501
+
502
+ FString Url;
503
+ Response.JsonObject ->TryGetStringField (TEXT (" result" ), Url);
504
+
505
+ FString ErrorMessage;
506
+ FPlatformProcess::LaunchURL (*Url, nullptr , &ErrorMessage);
507
+
508
+ if (ErrorMessage.Len ())
509
+ {
510
+ ErrorMessage = " Failed to launch browser: " + ErrorMessage;
511
+ IMTBL_ERR (" %s" , *ErrorMessage);
512
+ ResponseDelegate->ExecuteIfBound (FImmutablePassportResult{false , ErrorMessage, Response});
513
+ }
514
+ };
476
515
477
516
ResetStateFlags (IPS_HARDLOGOUT);
517
+
518
+ FString Url;
478
519
Response.JsonObject ->TryGetStringField (TEXT (" result" ), Url);
520
+
479
521
if (!Url.IsEmpty ())
480
522
{
481
- #if PLATFORM_ANDROID | PLATFORM_IOS | PLATFORM_MAC
523
+ #if PLATFORM_ANDROID | PLATFORM_IOS | PLATFORM_MAC | PLATFORM_WINDOWS
482
524
if (IsStateFlagsSet (IPS_PKCE))
483
525
{
484
- OnHandleDeepLink = FImtblPassportHandleDeepLinkDelegate::CreateUObject (this , &UImmutablePassport::OnDeepLinkActivated);
526
+ OnHandleDeepLink. AddUObject (this , &UImmutablePassport::OnDeepLinkActivated);
485
527
#if PLATFORM_ANDROID
486
528
LaunchAndroidUrl (Url);
487
529
#elif PLATFORM_IOS
488
530
[[ImmutableIOS instance] launchUrl:TCHAR_TO_ANSI (*Url)];
489
531
#elif PLATFORM_MAC
490
532
[[ImmutableMac instance] launchUrl:TCHAR_TO_ANSI (*Url) forRedirectUri:TCHAR_TO_ANSI (*InitData.logoutRedirectUri )];
533
+ #endif
534
+ #if PLATFORM_WINDOWS
535
+ Logout (Response);
491
536
#endif
492
537
}
493
538
else
494
539
{
495
540
#endif
496
- FPlatformProcess::LaunchURL (*Url, nullptr , &ErrorMessage);
497
- if (ErrorMessage.Len ())
498
- {
499
- Message = " Failed to connect to Browser: " + ErrorMessage;
500
-
501
- IMTBL_ERR (" %s" , *Message);
502
- ResponseDelegate->ExecuteIfBound (FImmutablePassportResult{ false , Message, Response });
503
-
504
- return ;
505
- }
541
+ Logout (Response);
506
542
Analytics->Track (UImmutableAnalytics::EEventName::COMPLETE_LOGOUT);
507
543
IMTBL_LOG (" Logged out" )
508
544
ResponseDelegate->ExecuteIfBound (FImmutablePassportResult{ Response.success });
509
- #if PLATFORM_ANDROID | PLATFORM_IOS | PLATFORM_MAC
545
+ #if PLATFORM_ANDROID | PLATFORM_IOS | PLATFORM_MAC | PLATFORM_WINDOWS
510
546
}
511
547
#endif
512
548
}
@@ -517,7 +553,7 @@ void UImmutablePassport::OnLogoutResponse(FImtblJSResponse Response)
517
553
ResetStateFlags (IPS_CONNECTED);
518
554
}
519
555
520
- #if PLATFORM_ANDROID | PLATFORM_IOS | PLATFORM_MAC
556
+ #if PLATFORM_ANDROID | PLATFORM_IOS | PLATFORM_MAC | PLATFORM_WINDOWS
521
557
void UImmutablePassport::OnGetPKCEAuthUrlResponse (FImtblJSResponse Response)
522
558
{
523
559
if (PKCEResponseDelegate.IsBound ())
@@ -532,7 +568,7 @@ void UImmutablePassport::OnGetPKCEAuthUrlResponse(FImtblJSResponse Response)
532
568
else
533
569
{
534
570
// Handle deeplink calls
535
- OnHandleDeepLink = FImtblPassportHandleDeepLinkDelegate::CreateUObject (this , &UImmutablePassport::OnDeepLinkActivated);
571
+ OnHandleDeepLink. AddUObject (this , &UImmutablePassport::OnDeepLinkActivated);
536
572
537
573
Msg = Response.JsonObject ->GetStringField (TEXT (" result" )).Replace (TEXT (" " ), TEXT (" +" ));
538
574
#if PLATFORM_ANDROID
@@ -542,6 +578,17 @@ void UImmutablePassport::OnGetPKCEAuthUrlResponse(FImtblJSResponse Response)
542
578
[[ImmutableIOS instance] launchUrl:TCHAR_TO_ANSI (*Msg)];
543
579
#elif PLATFORM_MAC
544
580
[[ImmutableMac instance] launchUrl:TCHAR_TO_ANSI (*Msg) forRedirectUri:TCHAR_TO_ANSI (*InitData.redirectUri )];
581
+ #elif PLATFORM_WINDOWS
582
+ FString ErrorMessage;
583
+ FPlatformProcess::LaunchURL (*Msg, nullptr , &ErrorMessage);
584
+ if (!ErrorMessage.IsEmpty ())
585
+ {
586
+ ErrorMessage = " Failed to launch browser: " + ErrorMessage;
587
+ IMTBL_ERR (" %s" , *ErrorMessage);
588
+ PKCEResponseDelegate.ExecuteIfBound (FImmutablePassportResult{false , ErrorMessage});
589
+ PKCEResponseDelegate.Unbind ();
590
+ ResetStateFlags (IPS_PKCE | IPS_CONNECTING);
591
+ }
545
592
#endif
546
593
}
547
594
}
@@ -583,7 +630,6 @@ void UImmutablePassport::OnConnectPKCEResponse(FImtblJSResponse Response)
583
630
}
584
631
ResetStateFlags (IPS_COMPLETING_PKCE);
585
632
}
586
- #endif
587
633
588
634
void UImmutablePassport::OnConfirmCodeResponse (FImtblJSResponse Response)
589
635
{
@@ -666,11 +712,9 @@ void UImmutablePassport::LoadPassportSettings()
666
712
}
667
713
}
668
714
669
- #if PLATFORM_ANDROID | PLATFORM_IOS | PLATFORM_MAC
670
- void UImmutablePassport::OnDeepLinkActivated (FString DeepLink)
715
+ void UImmutablePassport::OnDeepLinkActivated (const FString& DeepLink)
671
716
{
672
- IMTBL_LOG_FUNC (" URL : %s" , *DeepLink);
673
- OnHandleDeepLink = nullptr ;
717
+ OnHandleDeepLink.Clear ();
674
718
if (DeepLink.StartsWith (InitData.logoutRedirectUri ))
675
719
{
676
720
// execute on game thread to prevent call to Passport instance from another thread
@@ -690,6 +734,8 @@ void UImmutablePassport::OnDeepLinkActivated(FString DeepLink)
690
734
{
691
735
CompleteLoginPKCEFlow (DeepLink);
692
736
}
737
+
738
+ PKCEData = nullptr ;
693
739
}
694
740
695
741
void UImmutablePassport::CompleteLoginPKCEFlow (FString Url)
@@ -739,30 +785,34 @@ void UImmutablePassport::CompleteLoginPKCEFlow(FString Url)
739
785
FImtblJSResponseDelegate::CreateUObject (this , &UImmutablePassport::OnConnectPKCEResponse));
740
786
}
741
787
}
742
-
743
788
#endif
744
789
745
- #if PLATFORM_ANDROID | PLATFORM_IOS | PLATFORM_MAC
746
790
#if PLATFORM_ANDROID
747
791
// Called from Android JNI
748
792
void UImmutablePassport::HandleDeepLink (FString DeepLink) const
749
- {
750
- #elif PLATFORM_IOS | PLATFORM_MAC
751
-
793
+ #endif
794
+ #if PLATFORM_IOS | PLATFORM_MAC
752
795
// Called from iOS Objective C
753
796
void UImmutablePassport::HandleDeepLink (NSString* sDeepLink ) const
797
+ #endif
798
+ #if PLATFORM_WINDOWS
799
+ void UImmutablePassport::HandleDeepLink (FString DeepLink) const
800
+ #endif
754
801
{
802
+ #if PLATFORM_IOS | PLATFORM_MAC
755
803
FString DeepLink = FString (UTF8_TO_TCHAR ([sDeepLink UTF8String]));
756
804
IMTBL_LOG (" Handle Deep Link: %s" , *DeepLink);
757
805
#endif
758
-
759
- if (!OnHandleDeepLink. ExecuteIfBound (DeepLink) )
806
+ # if PLATFORM_WINDOWS
807
+ if (PKCEData )
760
808
{
761
- IMTBL_WARN ( " OnHandleDeepLink delegate was not called " );
809
+ UImmutablePKCEWindows::HandleDeepLink (PKCEData, DeepLink );
762
810
}
763
- }
764
811
#endif
765
812
813
+ OnHandleDeepLink.Broadcast (DeepLink);
814
+ }
815
+
766
816
#if PLATFORM_ANDROID
767
817
void UImmutablePassport::HandleOnLoginPKCEDismissed ()
768
818
{
0 commit comments