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

Commit

Permalink
Merge pull request #2090 from xamarin/port-maui-15412
Browse files Browse the repository at this point in the history
Fix failing auth redirect on Android
  • Loading branch information
jfversluis committed Jun 15, 2023
1 parent 5183266 commit 9b78e75
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ public partial class WebAuthenticator
static TaskCompletionSource<WebAuthenticatorResult> tcsResponse = null;
static Uri currentRedirectUri = null;

internal static bool AuthenticatingWithCustomTabs { get; private set; } = false;

internal static bool OnResume(Intent intent)
{
// If we aren't waiting on a task, don't handle the url
Expand Down Expand Up @@ -71,7 +73,11 @@ static async Task<WebAuthenticatorResult> PlatformAuthenticateAsync(WebAuthentic
tcsResponse = new TaskCompletionSource<WebAuthenticatorResult>();
currentRedirectUri = callbackUrl;

if (!(await StartCustomTabsActivity(url)))
// Try to start with custom tabs if the system supports it and we resolve it
AuthenticatingWithCustomTabs = await StartCustomTabsActivity(url);

// Fall back to using the system browser if necessary
if (!AuthenticatingWithCustomTabs)
{
// Fall back to opening the system-registered browser if necessary
var urlOriginalString = url.OriginalString;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,21 @@ protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);

// start the intermediate activity again with flags to close the custom tabs
var intent = new Intent(this, typeof(WebAuthenticatorIntermediateActivity));
intent.SetData(Intent.Data);
intent.AddFlags(ActivityFlags.ClearTop | ActivityFlags.SingleTop);
StartActivity(intent);
// Check how we launched the flow initially
if (WebAuthenticator.AuthenticatingWithCustomTabs)
{
// start the intermediate activity again with flags to close the custom tabs
var intent = new Intent(this, typeof(WebAuthenticatorIntermediateActivity));
intent.SetData(Intent.Data);
intent.AddFlags(ActivityFlags.ClearTop | ActivityFlags.SingleTop);
StartActivity(intent);
}
else
{
// No intermediate activity if we returned from a system browser
// intent since there's no custom tab instance to clean up
WebAuthenticator.OnResume(Intent);
}

// finish this activity
Finish();
Expand Down

0 comments on commit 9b78e75

Please sign in to comment.