Recently I experienced some issue with Azure DevOps PowerShell when attempting to create a ClientCredential and or ClientAssertion. I have the following code which was working on the past for creating a ClientCredential based on the following variables:
TenantId
ClientID (SPN)
Password (SPN Password)
$ResourceUrl = "https://database.windows.net/"
$AuthorityUrl = "https://login.microsoftonline.com/$($TenantId)"
$objClientCredential = [Microsoft.IdentityModel.Clients.ActiveDirectory.ClientCredential]::new($ClientId, $Password) $objAuthenticationContext = [Microsoft.IdentityModel.Clients.ActiveDirectory.AuthenticationContext]::new($AuthorityUrl) $objAuthenticationResult = $objAuthenticationContext.AcquireTokenAsync($ResourceUrl, $objClientCredential)
but recently this code stop working. It seems that the AzureAD module is not loading correctly. This only happens on Azure DevOps Powershell, on my machine it works fine (I am using PowerShell 7.1) So far so now I attempted the following:
- Run the code as shown above **Breaks on: **$objClientCredential = [Microsoft.IdentityModel.Clients.ActiveDirectory.ClientCredential]::new($ClientId, $Password) Error: Unable to find type [Microsoft.IdentityModel.Clients.ActiveDirectory.ClientCredential]
- Install AzureAD before running the code Install-Module -Name AzureAD -Force Import-Module -Name AzureAD **Breaks on: **$objClientCredential = [Microsoft.IdentityModel.Clients.ActiveDirectory.ClientCredential]::new($ClientId, $Password) Error: Unable to find type [Microsoft.IdentityModel.Clients.ActiveDirectory.ClientCredential]
- Import the dll Microsoft.IdentityModel.Clients.ActiveDirectory.dll from my machine Add-Type -Path ".\libraries\Microsoft.IdentityModel.Clients.ActiveDirectory.dll Doesn't break, however ClientCredential is not created it is returned as null
Have anyone experienced a similar issue? Do you know how should I drive this?