I have an app where users are going to share devices. The app uses OAuth 2.0 to sign the user in.(from a provider with IdentityServer4, though the problem occurs on other providers too)
The browser used is:
//Android
public Task OpenBrowser(Uri uri)
{
var nativeUri = UUri.Parse(uri.AbsoluteUri);
var builder = new CustomTabsIntent.Builder();
var launchIntent = builder
.SetShowTitle(true)
.Build();
launchIntent.LaunchUrl(MainActivity, nativeUri);
return Task.CompletedTask;
}
//iOS
public Task OpenBrowser(Uri uri)
{
var nativeUrl = new NSUrl(uri.AbsoluteUri);
var sfViewController = new SFSafariViewController(nativeUrl, false);
var window = UIApplication.SharedApplication.KeyWindow;
var vc = window.RootViewController;
while (vc.PresentedViewController != null)
{
vc = vc.PresentedViewController;
}
vc.PresentViewControllerAsync(sfViewController, true);
return Task.CompletedTask;
}
I also tried to use the new WebAuthenticator from Xamarin.Forms.
Since I’m making an app where users share devices I have to let them sign out, to remove the token from internal storage. The problem arises when there is no Internet, as I can only remove the token in the app, and not the authentication/token or what is cached in the Browser. Meaning, the next user to try (when the internet is back) will get automatically signed in with the previous users' credentials..
I tried to remove cookies with NSHttpCookieStorage.SharedStorage and CookieManager.Instance, but they have empty cookie storages.
Any solution is welcome, either to remove the cookie from the browser or to create a browser which clears cookies instantly (as I don't need the cookies in the browser after auth is done anyway).