@@ -43,6 +43,9 @@ public class PassportImpl
43
43
internal static string loginPKCEUrl ;
44
44
#endif
45
45
46
+ // Used to prevent calling login/connect functions multiple times
47
+ private bool isLoggedIn = false ;
48
+
46
49
public event OnAuthEventDelegate OnAuthEvent ;
47
50
48
51
public PassportImpl ( IBrowserCommunicationsManager communicationsManager )
@@ -119,6 +122,7 @@ await ConfirmCode(
119
122
PassportAuthEvent . LoginOpeningBrowser , PassportAuthEvent . PendingBrowserLogin , functionName ,
120
123
PassportFunction . LOGIN_CONFIRM_CODE , timeoutMs ) ;
121
124
SendAuthEvent ( PassportAuthEvent . LoginSuccess ) ;
125
+ isLoggedIn = true ;
122
126
return true ;
123
127
}
124
128
catch ( Exception ex )
@@ -137,6 +141,7 @@ private async UniTask<bool> Relogin()
137
141
string callResponse = await communicationsManager . Call ( PassportFunction . RELOGIN ) ;
138
142
bool success = callResponse . GetBoolResponse ( ) ?? false ;
139
143
SendAuthEvent ( success ? PassportAuthEvent . ReloginSuccess : PassportAuthEvent . ReloginFailed ) ;
144
+ isLoggedIn = success ;
140
145
return success ;
141
146
}
142
147
catch ( Exception ex )
@@ -177,6 +182,7 @@ await ConfirmCode(
177
182
PassportAuthEvent . ConnectImxOpeningBrowser , PassportAuthEvent . PendingBrowserLoginAndProviderSetup ,
178
183
functionName , PassportFunction . CONNECT_CONFIRM_CODE , timeoutMs ) ;
179
184
SendAuthEvent ( PassportAuthEvent . ConnectImxSuccess ) ;
185
+ isLoggedIn = true ;
180
186
return true ;
181
187
}
182
188
catch ( Exception ex )
@@ -195,6 +201,7 @@ private async UniTask<bool> Reconnect()
195
201
string callResponse = await communicationsManager . Call ( PassportFunction . RECONNECT ) ;
196
202
bool success = callResponse . GetBoolResponse ( ) ?? false ;
197
203
SendAuthEvent ( success ? PassportAuthEvent . ReconnectSuccess : PassportAuthEvent . ReconnectFailed ) ;
204
+ isLoggedIn = success ;
198
205
return success ;
199
206
}
200
207
catch ( Exception ex )
@@ -276,8 +283,12 @@ public async void OnDeepLinkActivated(string url)
276
283
if ( domain . Equals ( logoutRedirectUri ) )
277
284
{
278
285
await UniTask . SwitchToMainThread ( ) ;
286
+ if ( isLoggedIn )
287
+ {
288
+ TrySetPKCEResult ( true ) ;
289
+ }
279
290
SendAuthEvent ( PassportAuthEvent . LogoutPKCESuccess ) ;
280
- TrySetPKCEResult ( true ) ;
291
+ isLoggedIn = false ;
281
292
pkceCompletionSource = null ;
282
293
}
283
294
else if ( domain . Equals ( redirectUri ) )
@@ -415,8 +426,12 @@ public async UniTask CompleteLoginPKCEFlow(string uriString)
415
426
}
416
427
else
417
428
{
429
+ if ( ! isLoggedIn )
430
+ {
431
+ TrySetPKCEResult ( true ) ;
432
+ }
418
433
SendAuthEvent ( pkceLoginOnly ? PassportAuthEvent . LoginPKCESuccess : PassportAuthEvent . ConnectImxPKCESuccess ) ;
419
- TrySetPKCEResult ( true ) ;
434
+ isLoggedIn = true ;
420
435
}
421
436
}
422
437
}
@@ -437,7 +452,7 @@ public async UniTask CompleteLoginPKCEFlow(string uriString)
437
452
public void OnLoginPKCEDismissed ( bool completing )
438
453
{
439
454
Debug . Log ( $ "{ TAG } On Login PKCE Dismissed") ;
440
- if ( ! completing )
455
+ if ( ! completing && ! isLoggedIn )
441
456
{
442
457
// User hasn't entered all required details (e.g. email address) into Passport yet
443
458
Debug . Log ( $ "{ TAG } Login PKCE dismissed before completing the flow") ;
@@ -484,6 +499,7 @@ public async UniTask Logout()
484
499
string logoutUrl = await GetLogoutUrl ( ) ;
485
500
OpenUrl ( logoutUrl ) ;
486
501
SendAuthEvent ( PassportAuthEvent . LogoutSuccess ) ;
502
+ isLoggedIn = false ;
487
503
}
488
504
catch ( Exception ex )
489
505
{
@@ -671,6 +687,7 @@ private async UniTask CallFromAuthCallbackError(string id, string message)
671
687
672
688
private void TrySetPKCEResult ( bool result )
673
689
{
690
+ Debug . Log ( $ "{ TAG } Trying to set PKCE result to { result } ...") ;
674
691
if ( pkceCompletionSource != null )
675
692
{
676
693
pkceCompletionSource . TrySetResult ( result ) ;
@@ -683,6 +700,7 @@ private void TrySetPKCEResult(bool result)
683
700
684
701
private void TrySetPKCEException ( Exception exception )
685
702
{
703
+ Debug . Log ( $ "{ TAG } Trying to set PKCE exception...") ;
686
704
if ( pkceCompletionSource != null )
687
705
{
688
706
pkceCompletionSource . TrySetException ( exception ) ;
@@ -695,18 +713,20 @@ private void TrySetPKCEException(Exception exception)
695
713
696
714
private void TrySetPKCECanceled ( )
697
715
{
716
+ Debug . Log ( $ "{ TAG } Trying to set PKCE canceled...") ;
698
717
if ( pkceCompletionSource != null )
699
718
{
700
719
pkceCompletionSource . TrySetCanceled ( ) ;
701
720
}
702
721
else
703
722
{
704
- Debug . LogError ( $ "{ TAG } PKCE canceled") ;
723
+ Debug . LogWarning ( $ "{ TAG } PKCE canceled") ;
705
724
}
706
725
}
707
726
708
727
private void SendAuthEvent ( PassportAuthEvent authEvent )
709
728
{
729
+ Debug . Log ( $ "{ TAG } Send auth event: { authEvent } ") ;
710
730
if ( OnAuthEvent != null )
711
731
{
712
732
OnAuthEvent . Invoke ( authEvent ) ;
0 commit comments