diff --git a/AzureSQLConnectivityChecker.ps1 b/AzureSQLConnectivityChecker.ps1 index ada1f97..a8cd46b 100644 --- a/AzureSQLConnectivityChecker.ps1 +++ b/AzureSQLConnectivityChecker.ps1 @@ -84,6 +84,9 @@ if ($null -ne $parameters) { if ($null -ne $parameters['DelayBetweenConnections']) { $DelayBetweenConnections = $parameters['DelayBetweenConnections'] } + if ($null -ne $parameters['UserAssignedIdentityClientId']) { + $UserAssignedIdentityClientId = $parameters['UserAssignedIdentityClientId'] + } if ($null -ne $parameters['TrustServerCertificate']) { $TrustServerCertificate = $parameters['TrustServerCertificate'] } @@ -1482,6 +1485,10 @@ try { TrackWarningAnonymously ('Authentication library:' + $AuthenticationLibrary) } + if ($null -ne $UserAssignedIdentityClientId -and $UserAssignedIdentityClientId -ne '') { + Write-Host ' UserAssignedIdentityClientId:' $UserAssignedIdentityClientId -ForegroundColor Yellow + } + Write-Host ' Server:' $Server -ForegroundColor Yellow if ($null -ne $Database) { diff --git a/TDSClient/TDSClient/AuthenticationProvider/AuthenticationProvider.cs b/TDSClient/TDSClient/AuthenticationProvider/AuthenticationProvider.cs index dabbe5e..be1f49d 100644 --- a/TDSClient/TDSClient/AuthenticationProvider/AuthenticationProvider.cs +++ b/TDSClient/TDSClient/AuthenticationProvider/AuthenticationProvider.cs @@ -151,9 +151,9 @@ private async Task GetAccessTokenForInteractiveAuth() /// private async Task GetAccessTokenForMSIAuth() { - return IdentityClientId != null ? - await MSALHelper.GetSQLAccessTokenFromMSALUsingUserAssignedManagedIdentity(Authority, IdentityClientId) : - await MSALHelper.GetSQLAccessTokenFromMSALUsingSystemAssignedManagedIdentity(Authority); + return string.IsNullOrEmpty(IdentityClientId) ? + await MSALHelper.GetSQLAccessTokenFromMSALUsingSystemAssignedManagedIdentity(Resource) : + await MSALHelper.GetSQLAccessTokenFromMSALUsingUserAssignedManagedIdentity(Resource, IdentityClientId); } } }