Search code examples
c#win-universal-appuwpwindows-10-universalwindows-10-mobile

Clear Credentials stored in Universal Windows App


I'm using Windows.Web.Http.HttpClient in Universal Windows platform (UWP). The URL needs domain credentials (NTLM) so windows opens a self defined popup for username and password. App needs a functionality to logout but I couldn;'t find a working code which can clear credentials stored by UWP.

I have tried to clear credentials from Windows.Security.Credentials.PasswordVault using following code but it didn't work:

        var cred = new Windows.Security.Credentials.PasswordVault(); 
        var pwds = cred.RetrieveAll();
        foreach(var pwd in pwds)
        {
            pwd.RetrievePassword();                 
            cred.Remove(pwd);
        }

I'm also clearing cookies as below:

        var filter = new HttpBaseProtocolFilter();            
        var cookieManager = filter.CookieManager;
        HttpCookieCollection cookies = cookieManager.GetCookies(uri);            
        foreach (HttpCookie u in cookies)
        {
            cookieManager.DeleteCookie(u);
        }

Any suggestions please?


Solution

  • This isn't available in Windows 10, but will be in the Anniversary Update:

    var filter = new HttpBaseProtocolFilter();
    filter.ClearAuthenticationCache();
    

    You can see more on the MSDN page and if you have an Insider Preview build / SDK later than 14295 you should be able to test it.