[英]Call azure ad-protected API from powershell with username/password
[英]Getting 401 while trying perform API call with bearer token which is deployed and protected with Azure Ad Authentication
我嘗試使用 powershell 創建運行手冊,同時使用調用 webrequest 調用 api(部署在 azure 中),我在標頭中傳遞訪問令牌並且我沒有獲得身份驗證。
$TenantId="xyxyxyx"
$MapUrl="https://graph.microsoft.com"
$Authority="https://login.microsoftonline.com/$TenantId"
$ClientSecret="secret"
$AuthContext=New-Object "Micorsoft.IdentityModel.Clients.ActiveDirectory.AuthenticationContext -argumentlist $Authority
$ClientCredential=New-Object "Micorsoft.IdentityModel.Clients.ActiveDirectory.ClientCredential -argumentlsit $ClientId,$ClientSecret
$ResultToken=$AuthContext.AcquireTokenAsync($MapUrl,$ClientCredential).Result
By Using the above steps i got the access token then im using the token in the request like this
Invoke-WebRequest -uri 'https://sssss/api/Get' -Headers @{"Authorization"="(Bearer $ResultToken.AccessToken)"}
I dont know what im missing can someone help me with this. Thanks in Advance
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.