mirror of
https://github.com/ckaczor/sqltoolsservice.git
synced 2026-01-29 01:25:41 -05:00
MSAL encrypted file system cache (#1945)
This commit is contained in:
@@ -14,5 +14,11 @@ namespace Microsoft.SqlTools.Shared.Utility
|
||||
public const string dstsAuth = "dstsAuth";
|
||||
public const string ActiveDirectoryInteractive = "ActiveDirectoryInteractive";
|
||||
public const string ActiveDirectoryPassword = "ActiveDirectoryPassword";
|
||||
|
||||
// Azure authentication (MSAL) constants
|
||||
public const string ApplicationClientId = "a69788c6-1d43-44ed-9ca3-b83e194da255";
|
||||
public const string AzureTokenFolder = "Azure Accounts";
|
||||
public const string AzureAccountProviderCredentials = "azureAccountProviderCredentials";
|
||||
public const string MsalCacheName = "accessTokenCache";
|
||||
}
|
||||
}
|
||||
|
||||
65
src/Microsoft.SqlTools.Shared/Utility/Utils.cs
Normal file
65
src/Microsoft.SqlTools.Shared/Utility/Utils.cs
Normal file
@@ -0,0 +1,65 @@
|
||||
//
|
||||
// Copyright (c) Microsoft. All rights reserved.
|
||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
//
|
||||
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace Microsoft.SqlTools.Shared.Utility
|
||||
{
|
||||
public static class Utils
|
||||
{
|
||||
/// <summary>
|
||||
/// Builds directory path based on environment settings.
|
||||
/// </summary>
|
||||
/// <returns>Application directory path</returns>
|
||||
/// <exception cref="Exception">When called on unsupported platform.</exception>
|
||||
public static string BuildAppDirectoryPath()
|
||||
{
|
||||
var homedir = Environment.GetFolderPath(Environment.SpecialFolder.Personal);
|
||||
|
||||
// Windows
|
||||
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
|
||||
{
|
||||
var appData = Environment.GetEnvironmentVariable("APPDATA");
|
||||
var userProfile = Environment.GetEnvironmentVariable("USERPROFILE");
|
||||
if (appData != null)
|
||||
{
|
||||
return appData;
|
||||
}
|
||||
else if (userProfile != null)
|
||||
{
|
||||
return string.Join(Environment.GetEnvironmentVariable("USERPROFILE"), "AppData", "Roaming");
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new Exception("Not able to find APPDATA or USERPROFILE");
|
||||
}
|
||||
}
|
||||
|
||||
// Mac
|
||||
else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
|
||||
{
|
||||
return string.Join(homedir, "Library", "Application Support");
|
||||
}
|
||||
|
||||
// Linux
|
||||
else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
|
||||
{
|
||||
var xdgConfigHome = Environment.GetEnvironmentVariable("XDG_CONFIG_HOME");
|
||||
if (xdgConfigHome != null)
|
||||
{
|
||||
return xdgConfigHome;
|
||||
}
|
||||
else
|
||||
{
|
||||
return string.Join(homedir, ".config");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new Exception("Platform not supported");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user