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
14
14
static TaskCompletionSource < WebAuthenticatorResult > tcsResponse = null ;
15
15
static Uri currentRedirectUri = null ;
16
16
17
+ internal static bool AuthenticatingWithCustomTabs { get ; private set ; } = false ;
18
+
17
19
internal static bool OnResume ( Intent intent )
18
20
{
19
21
// If we aren't waiting on a task, don't handle the url
@@ -71,7 +73,11 @@ static async Task<WebAuthenticatorResult> PlatformAuthenticateAsync(WebAuthentic
71
73
tcsResponse = new TaskCompletionSource < WebAuthenticatorResult > ( ) ;
72
74
currentRedirectUri = callbackUrl ;
73
75
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 )
75
81
{
76
82
// Fall back to opening the system-registered browser if necessary
77
83
var urlOriginalString = url . OriginalString ;
Original file line number Diff line number Diff line change @@ -10,11 +10,21 @@ protected override void OnCreate(Bundle savedInstanceState)
10
10
{
11
11
base . OnCreate ( savedInstanceState ) ;
12
12
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
+ }
18
28
19
29
// finish this activity
20
30
Finish ( ) ;
You can’t perform that action at this time.
0 commit comments