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,17 @@ 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_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
+ #endif
145
+ #if PLATFORM_ANDROID | PLATFORM_IOS | PLATFORM_MAC | PLATFORM_WINDOWS
121
146
if (IsStateFlagsSet (IPS_PKCE))
122
147
{
123
148
PKCELogoutResponseDelegate = ResponseDelegate;
@@ -392,7 +417,7 @@ TOptional<UImmutablePassport::FImtblPassportResponseDelegate> UImmutablePassport
392
417
393
418
void UImmutablePassport::OnInitializeResponse (FImtblJSResponse Response)
394
419
{
395
- if (auto ResponseDelegate = GetResponseDelegate (Response))
420
+ if (TOptional<FImtblPassportResponseDelegate> ResponseDelegate = GetResponseDelegate (Response))
396
421
{
397
422
FString Error;
398
423
@@ -470,43 +495,55 @@ void UImmutablePassport::OnLogoutResponse(FImtblJSResponse Response)
470
495
471
496
return ;
472
497
}
473
-
474
- FString Url;
475
- FString ErrorMessage;
498
+
499
+ auto Logout = [this ](const FImtblJSResponse& Response)
500
+ {
501
+ TOptional<FImtblPassportResponseDelegate> ResponseDelegate = GetResponseDelegate (Response);
502
+
503
+ FString Url;
504
+ Response.JsonObject ->TryGetStringField (TEXT (" result" ), Url);
505
+
506
+ FString ErrorMessage;
507
+ FPlatformProcess::LaunchURL (*Url, nullptr , &ErrorMessage);
508
+
509
+ if (ErrorMessage.Len ())
510
+ {
511
+ ErrorMessage = " Failed to launch browser: " + ErrorMessage;
512
+ IMTBL_ERR (" %s" , *ErrorMessage);
513
+ ResponseDelegate->ExecuteIfBound (FImmutablePassportResult{false , ErrorMessage, Response});
514
+ }
515
+ };
476
516
477
517
ResetStateFlags (IPS_HARDLOGOUT);
518
+
519
+ FString Url;
478
520
Response.JsonObject ->TryGetStringField (TEXT (" result" ), Url);
521
+
479
522
if (!Url.IsEmpty ())
480
523
{
481
- #if PLATFORM_ANDROID | PLATFORM_IOS | PLATFORM_MAC
524
+ #if PLATFORM_ANDROID | PLATFORM_IOS | PLATFORM_MAC | PLATFORM_WINDOWS
482
525
if (IsStateFlagsSet (IPS_PKCE))
483
526
{
484
- OnHandleDeepLink = FImtblPassportHandleDeepLinkDelegate::CreateUObject (this , &UImmutablePassport::OnDeepLinkActivated);
527
+ OnHandleDeepLink. AddUObject (this , &UImmutablePassport::OnDeepLinkActivated);
485
528
#if PLATFORM_ANDROID
486
529
LaunchAndroidUrl (Url);
487
530
#elif PLATFORM_IOS
488
531
[[ImmutableIOS instance] launchUrl:TCHAR_TO_ANSI (*Url)];
489
532
#elif PLATFORM_MAC
490
533
[[ImmutableMac instance] launchUrl:TCHAR_TO_ANSI (*Url) forRedirectUri:TCHAR_TO_ANSI (*InitData.logoutRedirectUri )];
534
+ #endif
535
+ #if PLATFORM_WINDOWS
536
+ Logout (Response);
491
537
#endif
492
538
}
493
539
else
494
540
{
495
541
#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
- }
542
+ Logout (Response);
506
543
Analytics->Track (UImmutableAnalytics::EEventName::COMPLETE_LOGOUT);
507
544
IMTBL_LOG (" Logged out" )
508
545
ResponseDelegate->ExecuteIfBound (FImmutablePassportResult{ Response.success });
509
- #if PLATFORM_ANDROID | PLATFORM_IOS | PLATFORM_MAC
546
+ #if PLATFORM_ANDROID | PLATFORM_IOS | PLATFORM_MAC | PLATFORM_WINDOWS
510
547
}
511
548
#endif
512
549
}
@@ -517,7 +554,7 @@ void UImmutablePassport::OnLogoutResponse(FImtblJSResponse Response)
517
554
ResetStateFlags (IPS_CONNECTED);
518
555
}
519
556
520
- #if PLATFORM_ANDROID | PLATFORM_IOS | PLATFORM_MAC
557
+ #if PLATFORM_ANDROID | PLATFORM_IOS | PLATFORM_MAC | PLATFORM_WINDOWS
521
558
void UImmutablePassport::OnGetPKCEAuthUrlResponse (FImtblJSResponse Response)
522
559
{
523
560
if (PKCEResponseDelegate.IsBound ())
@@ -532,7 +569,7 @@ void UImmutablePassport::OnGetPKCEAuthUrlResponse(FImtblJSResponse Response)
532
569
else
533
570
{
534
571
// Handle deeplink calls
535
- OnHandleDeepLink = FImtblPassportHandleDeepLinkDelegate::CreateUObject (this , &UImmutablePassport::OnDeepLinkActivated);
572
+ OnHandleDeepLink. AddUObject (this , &UImmutablePassport::OnDeepLinkActivated);
536
573
537
574
Msg = Response.JsonObject ->GetStringField (TEXT (" result" )).Replace (TEXT (" " ), TEXT (" +" ));
538
575
#if PLATFORM_ANDROID
@@ -542,6 +579,17 @@ void UImmutablePassport::OnGetPKCEAuthUrlResponse(FImtblJSResponse Response)
542
579
[[ImmutableIOS instance] launchUrl:TCHAR_TO_ANSI (*Msg)];
543
580
#elif PLATFORM_MAC
544
581
[[ImmutableMac instance] launchUrl:TCHAR_TO_ANSI (*Msg) forRedirectUri:TCHAR_TO_ANSI (*InitData.redirectUri )];
582
+ #elif PLATFORM_WINDOWS
583
+ FString ErrorMessage;
584
+ FPlatformProcess::LaunchURL (*Msg, nullptr , &ErrorMessage);
585
+ if (!ErrorMessage.IsEmpty ())
586
+ {
587
+ ErrorMessage = " Failed to launch browser: " + ErrorMessage;
588
+ IMTBL_ERR (" %s" , *ErrorMessage);
589
+ PKCEResponseDelegate.ExecuteIfBound (FImmutablePassportResult{false , ErrorMessage});
590
+ PKCEResponseDelegate.Unbind ();
591
+ ResetStateFlags (IPS_PKCE | IPS_CONNECTING);
592
+ }
545
593
#endif
546
594
}
547
595
}
@@ -583,7 +631,6 @@ void UImmutablePassport::OnConnectPKCEResponse(FImtblJSResponse Response)
583
631
}
584
632
ResetStateFlags (IPS_COMPLETING_PKCE);
585
633
}
586
- #endif
587
634
588
635
void UImmutablePassport::OnConfirmCodeResponse (FImtblJSResponse Response)
589
636
{
@@ -666,11 +713,9 @@ void UImmutablePassport::LoadPassportSettings()
666
713
}
667
714
}
668
715
669
- #if PLATFORM_ANDROID | PLATFORM_IOS | PLATFORM_MAC
670
- void UImmutablePassport::OnDeepLinkActivated (FString DeepLink)
716
+ void UImmutablePassport::OnDeepLinkActivated (const FString& DeepLink)
671
717
{
672
- IMTBL_LOG_FUNC (" URL : %s" , *DeepLink);
673
- OnHandleDeepLink = nullptr ;
718
+ OnHandleDeepLink.Clear ();
674
719
if (DeepLink.StartsWith (InitData.logoutRedirectUri ))
675
720
{
676
721
// execute on game thread to prevent call to Passport instance from another thread
@@ -690,6 +735,8 @@ void UImmutablePassport::OnDeepLinkActivated(FString DeepLink)
690
735
{
691
736
CompleteLoginPKCEFlow (DeepLink);
692
737
}
738
+
739
+ PKCEData = nullptr ;
693
740
}
694
741
695
742
void UImmutablePassport::CompleteLoginPKCEFlow (FString Url)
@@ -739,30 +786,31 @@ void UImmutablePassport::CompleteLoginPKCEFlow(FString Url)
739
786
FImtblJSResponseDelegate::CreateUObject (this , &UImmutablePassport::OnConnectPKCEResponse));
740
787
}
741
788
}
742
-
743
789
#endif
744
790
745
- #if PLATFORM_ANDROID | PLATFORM_IOS | PLATFORM_MAC
746
- #if PLATFORM_ANDROID
791
+ #if PLATFORM_ANDROID | PLATFORM_WINDOWS
747
792
// Called from Android JNI
748
793
void UImmutablePassport::HandleDeepLink (FString DeepLink) const
749
- {
750
- #elif PLATFORM_IOS | PLATFORM_MAC
751
-
794
+ #endif
795
+ #if PLATFORM_IOS | PLATFORM_MAC
752
796
// Called from iOS Objective C
753
797
void UImmutablePassport::HandleDeepLink (NSString* sDeepLink ) const
798
+ #endif
754
799
{
800
+ #if PLATFORM_IOS | PLATFORM_MAC
755
801
FString DeepLink = FString (UTF8_TO_TCHAR ([sDeepLink UTF8String]));
756
802
IMTBL_LOG (" Handle Deep Link: %s" , *DeepLink);
757
803
#endif
758
-
759
- if (!OnHandleDeepLink. ExecuteIfBound (DeepLink) )
804
+ # if PLATFORM_WINDOWS
805
+ if (PKCEData )
760
806
{
761
- IMTBL_WARN ( " OnHandleDeepLink delegate was not called " );
807
+ UImmutablePKCEWindows::HandleDeepLink (PKCEData, DeepLink );
762
808
}
763
- }
764
809
#endif
765
810
811
+ OnHandleDeepLink.Broadcast (DeepLink);
812
+ }
813
+
766
814
#if PLATFORM_ANDROID
767
815
void UImmutablePassport::HandleOnLoginPKCEDismissed ()
768
816
{
0 commit comments