【发布时间】:2016-12-13 23:11:26
【问题描述】:
我正在尝试让不记名令牌通过这样的 powershell 脚本调用 API:
function GetAuthToken
{
param
(
[Parameter(Mandatory=$true)]
$ApiEndpointUri,
[Parameter(Mandatory=$true)]
$AADTenant
)
$adal = "C:\Program Files (x86)\Reference Assemblies\Microsoft\WindowsPowerShell\3.0\" + `
"Microsoft.IdentityModel.Clients.ActiveDirectory.dll"
$adalforms = "C:\Program Files (x86)\Reference Assemblies\Microsoft\WindowsPowerShell\3.0\" + `
"Microsoft.IdentityModel.Clients.ActiveDirectory.WindowsForms.dll"
[System.Reflection.Assembly]::LoadFrom($adal) | Out-Null
[System.Reflection.Assembly]::LoadFrom($adalforms) | Out-Null
$clientId = "1950a258-227b-4e31-a9cf-717495945fc2"
$redirectUri = "urn:ietf:wg:oauth:2.0:oob"
$authorityUri = “https://login.windows.net/$aadTenant”
$authContext = New-Object "Microsoft.IdentityModel.Clients.ActiveDirectory.AuthenticationContext" -ArgumentList $authorityUri
$authResult = $authContext.AcquireTokenAsync($ApiEndpointUri, $clientId,$redirectUri, "Auto")
$authResult.Wait();
return $authResult
$ApiEndpointUri = "https://management.azure.com/" #change this to graph api uri
$AADTenant = 'GUID' #AAD tenant guid
$token = GetAuthToken -ApiEndPointUri $ApiEndpointUri -AADTenant $AADTenant
$header = @{
'Content-Type'='application\json'
'Authorization'=$token.CreateAuthorizationHeader()
}
$request = ``
(Invoke-RestMethod -Uri $request -Headers $header -Method Get).value
但是,acquiretokenasync 失败并出现此错误:
Cannot find an overload for "AcquireTokenAsync" and the argument count: "4".
任何想法为什么我会遇到这个问题? AcquireTokenAsync 采用我所知道的 4 个参数。
【问题讨论】:
标签: c# powershell authentication oauth token