Fix failing auth redirect on Android

This commit is contained in:
Gerald Versluis 2023-06-06 11:37:42 +02:00
Родитель 25ceeea887
Коммит 5033519b00
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 81501CE0693195A3
2 изменённых файлов: 22 добавлений и 6 удалений

Просмотреть файл

@ -14,6 +14,8 @@ namespace Xamarin.Essentials
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
@ -71,7 +73,11 @@ namespace Xamarin.Essentials
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;

Просмотреть файл

@ -10,11 +10,21 @@ namespace Xamarin.Essentials
{
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();