static async Task <bool> StartCustomTabsActivity(Uri url)
        {
            // Is only set to true if BindServiceAsync succeeds and no exceptions are thrown
            var success        = false;
            var parentActivity = Platform.GetCurrentActivity(true);

            var customTabsActivityManager = CustomTabsActivityManager.From(parentActivity);

            try
            {
                if (await BindServiceAsync(customTabsActivityManager))
                {
                    var customTabsIntent = new CustomTabsIntent.Builder(customTabsActivityManager.Session)
                                           .SetShowTitle(true)
                                           .Build();

                    customTabsIntent.Intent.SetData(global::Android.Net.Uri.Parse(url.OriginalString));

                    if (customTabsIntent.Intent.ResolveActivity(parentActivity.PackageManager) != null)
                    {
                        WebAuthenticatorIntermediateActivity.StartActivity(parentActivity, customTabsIntent.Intent);
                        success = true;
                    }
                }
            }
            finally
            {
                try
                {
                    customTabsActivityManager.Client?.Dispose();
                }
                finally
                {
                }
            }

            return(success);
        }
        static async Task <WebAuthenticatorResult> PlatformAuthenticateAsync(WebAuthenticatorOptions webAuthenticatorOptions)
        {
            var url         = webAuthenticatorOptions?.Url;
            var callbackUrl = webAuthenticatorOptions?.CallbackUrl;
            var packageName = Platform.AppContext.PackageName;

            // Create an intent to see if the app developer wired up the callback activity correctly
            var intent = new Intent(Intent.ActionView);

            intent.AddCategory(Intent.CategoryBrowsable);
            intent.AddCategory(Intent.CategoryDefault);
            intent.SetPackage(packageName);
            intent.SetData(global::Android.Net.Uri.Parse(callbackUrl.OriginalString));

            // Try to find the activity for the callback intent
            if (!Platform.IsIntentSupported(intent, packageName))
            {
                throw new InvalidOperationException($"You must subclass the `{nameof(WebAuthenticatorCallbackActivity)}` and create an IntentFilter for it which matches your `{nameof(callbackUrl)}`.");
            }

            // Cancel any previous task that's still pending
            if (tcsResponse?.Task != null && !tcsResponse.Task.IsCompleted)
            {
                tcsResponse.TrySetCanceled();
            }

            tcsResponse        = new TaskCompletionSource <WebAuthenticatorResult>();
            currentRedirectUri = callbackUrl;

            var parentActivity = Platform.GetCurrentActivity(true);

            var customTabsActivityManager = CustomTabsActivityManager.From(parentActivity);

            try
            {
                if (await BindServiceAsync(customTabsActivityManager))
                {
                    var customTabsIntent = new CustomTabsIntent.Builder(customTabsActivityManager.Session)
                                           .SetShowTitle(true)
                                           .Build();

                    customTabsIntent.Intent.SetData(global::Android.Net.Uri.Parse(url.OriginalString));

                    WebAuthenticatorIntermediateActivity.StartActivity(parentActivity, customTabsIntent.Intent);
                }
                else
                {
                    // Fall back to opening the system browser if necessary
                    var browserIntent = new Intent(Intent.ActionView, global::Android.Net.Uri.Parse(url.OriginalString));
                    Platform.CurrentActivity.StartActivity(browserIntent);
                }

                return(await tcsResponse.Task);
            }
            finally
            {
                try
                {
                    customTabsActivityManager.Client?.Dispose();
                }
                finally
                {
                }
            }
        }