microsoft / vsts-authentication-library-for-java

Retrieve OAuth2 or Personal Accesss Tokens for Visual Studio Team Services (visualstudio.com) accounts. Also provides secure storage for those secrets on different platforms.
MIT License
18 stars 20 forks source link

Manual to read credential from Windows Credential manager #40

Open gzep opened 2 years ago

gzep commented 2 years ago

Hello,

can you please provide a short code snippet or description how to fetch credentials from CredManagerBackedCredentialStore? When I call get() with a name that is displayed in the credential manager it gives me com.sun.jna.LastErrorException: [1168] Element not found.

Thank you very much!

Colbix commented 2 years ago

The sample app doesn't provide the best example but here is what I've used. The main branch has a bug with not encoding properly. The pull request (PR), #37, fixes UTF-16LE instead of UTF-8 encoding. I applied the PR manually and it worked.

  final SecretStore<Credential> credStore = StorageProvider.getCredentialStorage(true, SecureOption.PREFER);
  //Add to MS Credential Manager
  String sName = "TestSubject01";
  String sPass = "thiswasatriumph";
  String sAddress = "GlaDOS";
  Credential cred = new Credential(sName, sPass);
  credStore.add(sAddress, cred);
  System.out.println(credStore.get(sAddress).Username + " : " + credStore.get(sAddress).Password);
gzep commented 1 year ago

Thanks for lettin' me know. I subscribed for the pull request and give feedback later.