【发布时间】:2021-06-18 10:34:24
【问题描述】:
它没有读取 authcontext 中的值,不知道为什么,可以帮助我解决这个问题。使用最新版本的 ADAL v5.2.9
PowerShell
function Get-AccessToken
{
$tenantID = "<id>"
$AuthUri = "https://login.microsoftonline.com/$tenantID"
########
#SPN IDs.....
#spn
$AppId = ""
#######
# SPN cert thumbprints.......
#spn
$clientCertificate = Get-Item -Path Cert:\CurrentUser\My\<cert thumb>
$resource = "<RestApi>"
$adal = "<path to the dll>\Microsoft.IdentityModel.Clients.ActiveDirectory.dll"
[System.Reflection.Assembly]::LoadFrom($adal) | Out-Null
$authenticationContext = New-Object -TypeName Microsoft.IdentityModel.Clients.ActiveDirectory.AuthenticationContext -ArgumentList $AuthUri
$certificateCredential = New-Object -TypeName Microsoft.IdentityModel.Clients.ActiveDirectory.ClientAssertionCertificate -ArgumentList ($AppId, $clientCertificate)
$authToken = $authenticationContext.AcquireTokenAsync($resource, $certificateCredential)
$accessToken = $authToken.Result.AccessToken.Trim()
$authToken.Result.AccessToken.Trim() | Clip
Write-Host "Token length"
Write-Host $accessToken.Length
$accessToken
}
#endregion
# Get access token, headers and body
$token = Get-AccessToken
出现以下错误
InvalidOperation: C:\Users\Ipaws-api.ps1:17
Line |
17 | $authToken = $authContext.AcquireTokenAsync($resource, $certificat …
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
| Method invocation failed because [Microsoft.IdentityModel.Clients.ActiveDirectory.AuthenticationContext] does not
| contain a method named 'AcquireTokenAsync'.
【问题讨论】:
标签: azure-active-directory azure-powershell adal