Share via


Clearing Stored Credentials in Windows 8.1 using PasswordVault

If you ever have to test Windows Store applications with multiple OAuth providers interactively, you will run into a little bit of annoyance caused by the credential storage within the vault. Apparently the application has no control on this as even if did not check “Keep me signed in” during log in, the credentials were still stored into the vault managed by Credential Manager. This could be a combination of the preview of ADAL (“Install-Package Microsoft.Preview.WindowsAzure.ActiveDirectory.Authentication” and WebAuthenticationBroker.

In any case, since I needed the log in challenge screen to show up every time click sign in during testing, I wrote the following simple function to clear the credentials issued by Windows Azure Active Directory. Thought this might be useful for anyone integrating multiple OAuth providers including Azure Active Directory.

//clear stored credentials

ClearPasswordVault("Microsoft.WindowsAzure.ActiveDirectory.Authentication");

private void ClearPasswordVault(string resourceName)

{

    var passwordVault = new PasswordVault();

    try

   {        

       var storedCreds = passwordVault.FindAllByResource(resourceName);

 

       foreach (PasswordCredential pc in storedCreds)

       {

           passwordVault.Remove(pc);

       }

       WriteLog(string.Format("Removed {0} passwords for {1}", storedCreds.Count, resourceName));

    }

    catch

    {

        WriteLog("No passwords found in the vault");

    }

}

Technorati Tags: WebAuthenticationBroker,Windows Azure Active Directory,PasswordVault,OAuth Testing