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:
Kim Santiago
2019-07-24 17:23:55 -07:00
committed by GitHub
parent e1b9890f5c
commit f7a7a3d466
2 changed files with 31 additions and 1 deletions

View File

@@ -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)

View File

@@ -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; }
}
}