mirror of
https://github.com/ckaczor/sqltoolsservice.git
synced 2026-01-14 01:25:40 -05:00
Fix DacFx wizard not supporting AAD auth (#836)
* pass Azure authentication token if using AAD auth * add check for null
This commit is contained in:
@@ -5,6 +5,7 @@
|
||||
using Microsoft.SqlServer.Dac;
|
||||
using Microsoft.SqlTools.ServiceLayer.Connection;
|
||||
using Microsoft.SqlTools.ServiceLayer.TaskServices;
|
||||
using Microsoft.SqlTools.ServiceLayer.Utility;
|
||||
using Microsoft.SqlTools.Utility;
|
||||
using System;
|
||||
using System.Data.SqlClient;
|
||||
@@ -32,9 +33,13 @@ namespace Microsoft.SqlTools.ServiceLayer.DacFx
|
||||
|
||||
protected DacServices DacServices { get; private set; }
|
||||
|
||||
protected ConnectionInfo ConnInfo { get; private set; }
|
||||
|
||||
protected DacFxOperation(ConnectionInfo connInfo)
|
||||
{
|
||||
Validate.IsNotNull("connectionInfo", connInfo);
|
||||
Validate.IsNotNull("connectionDetails", connInfo.ConnectionDetails);
|
||||
this.ConnInfo = connInfo;
|
||||
this.ConnectionString = ConnectionService.BuildConnectionString(connInfo.ConnectionDetails);
|
||||
this.OperationId = Guid.NewGuid().ToString();
|
||||
}
|
||||
@@ -79,7 +84,8 @@ namespace Microsoft.SqlTools.ServiceLayer.DacFx
|
||||
|
||||
try
|
||||
{
|
||||
this.DacServices = new DacServices(this.ConnectionString);
|
||||
// Pass in Azure authentication token if needed
|
||||
this.DacServices = this.ConnInfo.ConnectionDetails.AzureAccountToken != null ? new DacServices(this.ConnectionString, new AccessTokenProvider(this.ConnInfo.ConnectionDetails.AzureAccountToken)) : new DacServices(this.ConnectionString);
|
||||
Execute();
|
||||
}
|
||||
catch (Exception e)
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
using Microsoft.SqlServer.Dac;
|
||||
using System;
|
||||
|
||||
namespace Microsoft.SqlTools.ServiceLayer.Utility
|
||||
{
|
||||
class AccessTokenProvider : IUniversalAuthProvider
|
||||
{
|
||||
private string _accessToken;
|
||||
|
||||
public AccessTokenProvider(string accessToken)
|
||||
{
|
||||
if (string.IsNullOrEmpty(accessToken))
|
||||
{
|
||||
throw new ArgumentNullException("accessToken");
|
||||
}
|
||||
|
||||
_accessToken = accessToken;
|
||||
}
|
||||
|
||||
public bool IsTokenExpired() { return false; }
|
||||
|
||||
public string GetValidAccessToken() { return _accessToken; }
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user