| | 1 | | // Copyright (c) Microsoft Corporation. All rights reserved. |
| | 2 | | // Licensed under the MIT License. |
| | 3 | |
|
| | 4 | | using System; |
| | 5 | | using System.ComponentModel; |
| | 6 | | using System.IO; |
| | 7 | | using System.Runtime.InteropServices; |
| | 8 | |
|
| | 9 | | namespace Azure.Identity |
| | 10 | | { |
| | 11 | | internal sealed class WindowsVisualStudioCodeAdapter : IVisualStudioCodeAdapter |
| | 12 | | { |
| 2 | 13 | | private static readonly string s_userSettingsJsonPath = Path.Combine(Environment.GetFolderPath(Environment.Speci |
| | 14 | |
|
| 48 | 15 | | public string GetUserSettingsPath() => s_userSettingsJsonPath; |
| | 16 | |
|
| | 17 | | public string GetCredentials(string serviceName, string accountName) |
| | 18 | | { |
| 48 | 19 | | IntPtr credentials = WindowsNativeMethods.CredRead($"{serviceName}/{accountName}", WindowsNativeMethods.CRED |
| | 20 | | try |
| | 21 | | { |
| 48 | 22 | | WindowsNativeMethods.CredentialData credData = Marshal.PtrToStructure<WindowsNativeMethods.CredentialDat |
| 48 | 23 | | return Marshal.PtrToStringAnsi(credData.CredentialBlob, (int) credData.CredentialBlobSize); |
| | 24 | | } |
| | 25 | | finally |
| | 26 | | { |
| 48 | 27 | | WindowsNativeMethods.CredFree(credentials); |
| 48 | 28 | | } |
| 48 | 29 | | } |
| | 30 | | } |
| | 31 | | } |