mirror of
https://github.com/ckaczor/sqltoolsservice.git
synced 2026-01-13 17:23:02 -05:00
Get Application Path from command options (#1916)
This commit is contained in:
@@ -5,6 +5,7 @@
|
||||
|
||||
using Microsoft.Data.SqlClient;
|
||||
using Microsoft.SqlTools.Authentication.Utility;
|
||||
using Microsoft.SqlTools.Utility;
|
||||
|
||||
namespace Microsoft.SqlTools.Authentication.Sql
|
||||
{
|
||||
@@ -27,13 +28,23 @@ namespace Microsoft.SqlTools.Authentication.Sql
|
||||
/// Instantiates AuthenticationProvider to be used for AAD authentication with MSAL.NET and MSAL.js co-ordinated.
|
||||
/// </summary>
|
||||
/// <param name="applicationName">Application Name that identifies user folder path location for reading/writing to shared cache.</param>
|
||||
/// <param name="applicationPath">Application Path directory where application cache folder is present.</param>
|
||||
/// <param name="authCallback">Callback that handles AAD authentication when user interaction is needed.</param>
|
||||
public AuthenticationProvider(string applicationName)
|
||||
public AuthenticationProvider(string applicationName, string applicationPath)
|
||||
{
|
||||
if (string.IsNullOrEmpty(applicationName))
|
||||
{
|
||||
if(string.IsNullOrEmpty(applicationName)) {
|
||||
applicationName = nameof(SqlTools);
|
||||
Logger.Warning($"Application Name not received with command options, using default application name as: {applicationName}");
|
||||
}
|
||||
var cachePath = Path.Combine(Utils.BuildAppDirectoryPath(), applicationName, AzureTokenFolder);
|
||||
|
||||
if (string.IsNullOrEmpty(applicationPath))
|
||||
{
|
||||
applicationPath = Utils.BuildAppDirectoryPath();
|
||||
Logger.Warning($"Application Path not received with command options, using default application path as: {applicationPath}");
|
||||
}
|
||||
|
||||
var cachePath = Path.Combine(applicationPath, applicationName, AzureTokenFolder);
|
||||
this.authenticator = new Authenticator(ApplicationClientId, applicationName, cachePath, MsalCacheName);
|
||||
}
|
||||
|
||||
|
||||
@@ -37,7 +37,7 @@ namespace Microsoft.SqlTools.Authentication.Utility
|
||||
/// <exception cref="Exception">When called on unsupported platform.</exception>
|
||||
public static string BuildAppDirectoryPath()
|
||||
{
|
||||
var homedir = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile);
|
||||
var homedir = Environment.GetFolderPath(Environment.SpecialFolder.Personal);
|
||||
|
||||
// Windows
|
||||
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
|
||||
|
||||
@@ -46,6 +46,9 @@ namespace Microsoft.SqlTools.Utility
|
||||
case "-application-name":
|
||||
ApplicationName = args[++i];
|
||||
break;
|
||||
case "-data-path":
|
||||
ApplicationPath = args[++i];
|
||||
break;
|
||||
case "-autoflush-log":
|
||||
AutoFlushLog = true;
|
||||
break;
|
||||
@@ -110,6 +113,11 @@ namespace Microsoft.SqlTools.Utility
|
||||
/// </summary>
|
||||
public string ApplicationName { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Path of application home directory
|
||||
/// </summary>
|
||||
public string ApplicationPath { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Contains any error messages during execution
|
||||
/// </summary>
|
||||
|
||||
@@ -1076,7 +1076,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Connection
|
||||
if (commandOptions != null && commandOptions.EnableSqlAuthenticationProvider)
|
||||
{
|
||||
// Register SqlAuthenticationProvider with SqlConnection for AAD Interactive (MFA) authentication.
|
||||
var provider = new AuthenticationProvider(commandOptions.ApplicationName);
|
||||
var provider = new AuthenticationProvider(commandOptions.ApplicationName, commandOptions.ApplicationPath);
|
||||
SqlAuthenticationProvider.SetProvider(SqlAuthenticationMethod.ActiveDirectoryInteractive, provider);
|
||||
|
||||
this.EnableSqlAuthenticationProvider = true;
|
||||
|
||||
Reference in New Issue
Block a user