Reputation: 187
Details:
I have two sample Uwp apps. Both has use fallowing method:
private string GetPasswordCredential()
{
PasswordVault passwordVault = new PasswordVault();
PasswordCredential passwordCredential = null;
try
{
var passwordCredentials = new List<PasswordCredential>(passwordVault.RetrieveAll());
if (passwordCredentials.Any(c => c.Resource.Equals("testResource") && c.UserName.Equals("testUserName")))
{
passwordCredential = passwordVault.Retrieve(resource: "testResource", userName: "testUserName");
}
}
catch (Exception exception)
{
var message = exception.Message;
}
if (passwordCredential == null)
{
// create credential deteils
passwordCredential = new PasswordCredential(resource: "testResource", userName: "testUserName", password: "testPassword");
// add credential details to password vault
passwordVault.Add(passwordCredential);
}
return passwordCredential.Password;
}
The problem is that, the method creates unique Credentials for every app:
My aim is to create one Credential detail if not exists, and use it by second App as well once second App gets run. The above method logic does a check but also create brand new Credential for each App. Only difference I can see 'Saved By' section. How can I force second App to grab/use already existed Credential?
Upvotes: 2
Views: 248
Reputation: 169160
How can I force second App to grab/use already existed Credential?
You can't. The offical documentation is pretty clear on the fact that "the contents of the locker [represented by the PasswordVault
class] are specific to the app or service. Apps and services don't have access to credentials associated with other apps or services.".
So App2
cannot access a credential created by App1
and vice versa. This is by design.
Upvotes: 2