| | 1 | | // Copyright (c) Microsoft Corporation. All rights reserved. |
| | 2 | | // Licensed under the MIT License. |
| | 3 | |
|
| | 4 | | using System; |
| | 5 | | using System.Globalization; |
| | 6 | | using System.IO; |
| | 7 | | using System.Runtime.InteropServices; |
| | 8 | | using System.Text; |
| | 9 | | using Azure.Core; |
| | 10 | |
|
| | 11 | | namespace Azure.Identity |
| | 12 | | { |
| | 13 | | internal sealed class MacosVisualStudioCodeAdapter : IVisualStudioCodeAdapter |
| | 14 | | { |
| 0 | 15 | | private static readonly string s_userSettingsJsonPath = Path.Combine(Environment.GetFolderPath(Environment.Speci |
| | 16 | |
|
| 0 | 17 | | public string GetUserSettingsPath() => s_userSettingsJsonPath; |
| | 18 | |
|
| | 19 | | public string GetCredentials(string serviceName, string accountName) |
| | 20 | | { |
| 0 | 21 | | Argument.AssertNotNullOrEmpty(serviceName, nameof(serviceName)); |
| 0 | 22 | | Argument.AssertNotNullOrEmpty(accountName, nameof(accountName)); |
| | 23 | |
|
| 0 | 24 | | IntPtr credentialsPtr = IntPtr.Zero; |
| 0 | 25 | | IntPtr itemRef = IntPtr.Zero; |
| | 26 | |
|
| | 27 | | try |
| | 28 | | { |
| 0 | 29 | | MacosNativeMethods.SecKeychainFindGenericPassword(IntPtr.Zero, serviceName, accountName, out int passwor |
| 0 | 30 | | return passwordLength > 0 ? Marshal.PtrToStringAnsi(credentialsPtr, passwordLength) : throw new InvalidO |
| | 31 | | } |
| | 32 | | finally |
| | 33 | | { |
| | 34 | | try |
| | 35 | | { |
| 0 | 36 | | MacosNativeMethods.SecKeychainItemFreeContent(IntPtr.Zero, credentialsPtr); |
| 0 | 37 | | } |
| | 38 | | finally |
| | 39 | | { |
| 0 | 40 | | MacosNativeMethods.CFRelease(itemRef); |
| 0 | 41 | | } |
| 0 | 42 | | } |
| 0 | 43 | | } |
| | 44 | | } |
| | 45 | | } |