Skip to content

Commit 9b6276d

Browse files
authored
fix: android custom tabs dismiss callback (#63)
1 parent 2a71c8d commit 9b6276d

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

Source/Immutable/Private/Immutable/ImmutablePassport.cpp

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -615,6 +615,7 @@ void UImmutablePassport::OnConnectPKCEResponse(FImtblJSResponse Response)
615615
{
616616
IMTBL_ERR("Unable to return a response for Connect PKCE");
617617
}
618+
ResetStateFlags(IPS_COMPLETING_PKCE);
618619
}
619620
#endif
620621

@@ -958,7 +959,10 @@ void UImmutablePassport::OnDeepLinkActivated(FString DeepLink)
958959

959960
void UImmutablePassport::CompleteLoginPKCEFlow(FString Url)
960961
{
961-
SetStateFlags(IPS_CONNECTED);
962+
// Required mainly for Android to detect when Chrome Custom tabs is dismissed
963+
// See HandleOnLoginPKCEDismissed
964+
SetStateFlags(IPS_COMPLETING_PKCE);
965+
962966
// Get code and state from deeplink URL
963967
TOptional<FString> Code, State;
964968
FString Endpoint, Params;
@@ -989,7 +993,7 @@ void UImmutablePassport::CompleteLoginPKCEFlow(FString Url)
989993
IMTBL_ERR("%s", *ErrorMsg);
990994
PKCEResponseDelegate.ExecuteIfBound(FImmutablePassportResult{false, ErrorMsg});
991995
PKCEResponseDelegate = nullptr;
992-
ResetStateFlags(IPS_PKCE|IPS_CONNECTING);
996+
ResetStateFlags(IPS_PKCE|IPS_CONNECTING|IPS_COMPLETING_PKCE);
993997
}
994998
else
995999
{
@@ -1028,7 +1032,12 @@ void UImmutablePassport::HandleOnLoginPKCEDismissed()
10281032
IMTBL_LOG("Handle On Login PKCE Dismissed");
10291033
OnPKCEDismissed = nullptr;
10301034

1031-
if (IsStateFlagSet(IPS_CONNECTING))
1035+
// If the second part of PKCE (CompleteLoginPKCEFlow) has not started yet and custom tabs is dismissed,
1036+
// this means the user manually dismissed the custom tabs before entering all
1037+
// all required details (e.g. email address) into Passport
1038+
// Cannot use IPS_CONNECTING as that is set when PKCE flow is initiated. Here we are checking against the second
1039+
// half of the PKCE flow.
1040+
if (!IsStateFlagSet(IPS_COMPLETING_PKCE))
10321041
{
10331042
// User hasn't entered all required details (e.g. email address) into
10341043
// Passport yet

Source/Immutable/Public/Immutable/ImmutablePassport.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,8 @@ class IMMUTABLE_API UImmutablePassport : public UObject
239239
IPS_CONNECTED = 1 << 1,
240240
IPS_IMX = 1 << 2,
241241
IPS_PKCE = 1 << 3,
242-
IPS_INITIALIZED = 1 << 4
242+
IPS_COMPLETING_PKCE = 1 << 4,
243+
IPS_INITIALIZED = 1 << 5
243244
};
244245

245246
uint8 StateFlags = IPS_NONE;

0 commit comments

Comments
 (0)