0

Xamarin Android CookieManager.hasCookies() returns false, indicating there are no cookies.

public static async Task<string> SignOut(){

    IEnumerable<IAccount> accounts = await App.IdentityClientApp.GetAccountsAsync();

    foreach (IAccount account in accounts)
    {
        await App.IdentityClientApp.RemoveAsync(account);
    }

    DependencyService.Get<ILogoutHelper>().LogoutSSO();

    graphClient = null;
    TokenForUser = null;

    return "";
}

public class LogoutHelper : ILogoutHelper
{
    public void LogoutSSO()
    {
        CookieManager.Instance.RemoveAllCookies(null);
        CookieManager.Instance.RemoveAllCookie();
        CookieManager.Instance.RemoveSessionCookie();
        CookieManager.Instance.Flush();
        Device.BeginInvokeOnMainThread(() => new Android.Webkit.WebView(null).ClearCache(true));

    }
}

I want to clear cookies on the browser of the OS so that MSAL login credentials are not cached.

trojanhorse
  • 1
  • 1
  • 4

1 Answers1

0

Fixed.

Switching from Chrome Custom Tabs to Embedded (WebView?) allows you to manage cookies through CookieManager.

App.UiParent = new UIParent(Xamarin.Forms.Forms.Context as Activity, true);

https://github.com/AzureAD/microsoft-authentication-library-for-dotnet/wiki/MSAL.NET-uses-web-browser#choosing-between-embedded-web-browser-or-system-browser-on-xamarinandroid

trojanhorse
  • 1
  • 1
  • 4