Skip to content
This repository was archived by the owner on May 15, 2024. It is now read-only.

Commit f264e71

Browse files
authored
Merge pull request #2090 from xamarin/port-maui-15412
Fix failing auth redirect on Android
2 parents 25ceeea + b3acca3 commit f264e71

File tree

3 files changed

+23
-7
lines changed

3 files changed

+23
-7
lines changed

Xamarin.Essentials/WebAuthenticator/WebAuthenticator.android.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff 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;

Xamarin.Essentials/WebAuthenticator/WebAuthenticatorCallbackActivity.android.cs

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff 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();

azure-pipelines.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ pr:
88
- develop
99

1010
variables:
11-
BASE_VERSION: 1.7.1
11+
BASE_VERSION: 1.8.0
1212
PREVIEW_LABEL: 'ci'
1313
BUILD_NUMBER: $[counter(format('{0}_{1}_{2}', variables['BASE_VERSION'], variables['PREVIEW_LABEL'], variables['Build.SourceBranch']), 1)]
1414
NUGET_VERSION: $[format('{0}-{1}.{2}', variables['BASE_VERSION'], variables['PREVIEW_LABEL'], variables['BUILD_NUMBER'])]

0 commit comments

Comments
 (0)