This repository was archived by the owner on May 15, 2024. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +22
-6
lines changed
Xamarin.Essentials/WebAuthenticator Expand file tree Collapse file tree 2 files changed +22
-6
lines changed Original file line number Diff line number Diff line change @@ -14,6 +14,8 @@ public partial class WebAuthenticator
1414 static TaskCompletionSource < WebAuthenticatorResult > tcsResponse = null ;
1515 static Uri currentRedirectUri = null ;
1616
17+ internal static bool AuthenticatingWithCustomTabs { get ; private set ; } = false ;
18+
1719 internal static bool OnResume ( Intent intent )
1820 {
1921 // If we aren't waiting on a task, don't handle the url
@@ -71,7 +73,11 @@ static async Task<WebAuthenticatorResult> PlatformAuthenticateAsync(WebAuthentic
7173 tcsResponse = new TaskCompletionSource < WebAuthenticatorResult > ( ) ;
7274 currentRedirectUri = callbackUrl ;
7375
74- if ( ! ( await StartCustomTabsActivity ( url ) ) )
76+ // Try to start with custom tabs if the system supports it and we resolve it
77+ AuthenticatingWithCustomTabs = await StartCustomTabsActivity ( url ) ;
78+
79+ // Fall back to using the system browser if necessary
80+ if ( ! AuthenticatingWithCustomTabs )
7581 {
7682 // Fall back to opening the system-registered browser if necessary
7783 var urlOriginalString = url . OriginalString ;
Original file line number Diff line number Diff line change @@ -10,11 +10,21 @@ protected override void OnCreate(Bundle savedInstanceState)
1010 {
1111 base . OnCreate ( savedInstanceState ) ;
1212
13- // start the intermediate activity again with flags to close the custom tabs
14- var intent = new Intent ( this , typeof ( WebAuthenticatorIntermediateActivity ) ) ;
15- intent . SetData ( Intent . Data ) ;
16- intent . AddFlags ( ActivityFlags . ClearTop | ActivityFlags . SingleTop ) ;
17- StartActivity ( intent ) ;
13+ // Check how we launched the flow initially
14+ if ( WebAuthenticator . AuthenticatingWithCustomTabs )
15+ {
16+ // start the intermediate activity again with flags to close the custom tabs
17+ var intent = new Intent ( this , typeof ( WebAuthenticatorIntermediateActivity ) ) ;
18+ intent . SetData ( Intent . Data ) ;
19+ intent . AddFlags ( ActivityFlags . ClearTop | ActivityFlags . SingleTop ) ;
20+ StartActivity ( intent ) ;
21+ }
22+ else
23+ {
24+ // No intermediate activity if we returned from a system browser
25+ // intent since there's no custom tab instance to clean up
26+ WebAuthenticator . OnResume ( Intent ) ;
27+ }
1828
1929 // finish this activity
2030 Finish ( ) ;
You can’t perform that action at this time.
0 commit comments