TL;DR: CustomTabs close when app is backgrounded, but we need it to stay active. How can we achieve this?
We have an app which uses CustomTabs to login the user. We have added two-factor authentication, but this introduces a problem. When you tap the login button the custom tabs intent is launched as this:
var tcs = new TaskCompletionSource<BrowserResult>();
try
{
var activity = (Activity)Forms.Context;
var builder = new CustomTabsIntent.Builder().EnableUrlBarHiding();
var customTabsIntent = builder.Build();
customTabsIntent.Intent.AddFlags(ActivityFlags.NoHistory);
Action<string> callback = null;
callback = url =>
{
MainActivity.Callbacks -= callback;
tcs.SetResult(new BrowserResult
{
ResultType = BrowserResultType.Success,
Response = url
});
};
MainActivity.Callbacks += callback;
customTabsIntent.LaunchUrl(activity, Android.Net.Uri.Parse(options.StartUrl));
}
catch (Exception ex)
{
throw new Exception($"error: {ex.Message}");
}
return tcs.Task;
This works as expected and you can login, of course now the code for two-factor authentication code is asked, which in most cases means you have to background the app, open your authenticator (authy, Google authenticator etc.) and then come back to the app with the code. The problem is that when we re-open the app the CustomTabs and it's session is completely gone. This means you have to click it again, login again and the same happens all over. I have searched for a solution for days now. Can anyone help us finding a way to keep the CustomTabs and it's session open, so you can just fill in your authenticator code and login happily ever after?