powershell 使用PowerShell对AAD进行身份验证然后调用Web API
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了powershell 使用PowerShell对AAD进行身份验证然后调用Web API相关的知识,希望对你有一定的参考价值。
### Load ADAL
Add-Type -Path "${env:ProgramFiles(x86)}\Microsoft SDKs\Azure\PowerShell\ServiceManagement\Azure\Services\Microsoft.IdentityModel.Clients.ActiveDirectory.dll"
# Set AAD client ID for the client app
$clientId = "aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa"
$resourceAppIdURI = "https://TestWebApi01.azurewebsites.net"
$authority = "https://login.windows.net/MyAadDirectory.onmicrosoft.com"
# Create Authentication Context tied to Azure AD Tenant
$authContext = New-Object "Microsoft.IdentityModel.Clients.ActiveDirectory.AuthenticationContext" -ArgumentList $authority
# Acquire token http://www.cloudidentity.com/blog/2014/07/10/adal-v2-and-windows-integrated-authentication/
$authResult = $authContext.AcquireToken($resourceAppIdURI, $clientId, (New-Object Microsoft.IdentityModel.Clients.ActiveDirectory.UserCredential me@MyAadDirectory.com))
### Use the token to call the API
Invoke-RestMethod -Method Get -Uri https://TestWebApi01.azurewebsites.net/api/values -Headers @{"Authorization" = "Bearer $($authResult.AccessToken)"}
以上是关于powershell 使用PowerShell对AAD进行身份验证然后调用Web API的主要内容,如果未能解决你的问题,请参考以下文章
Windows PowerShell ISE 是什么和 PowerShell 有什么区别
Windows 使用 PowerShell 来管理另外一台 Windows 机器
window powershell
powershell 使用PowerShell对AAD进行身份验证然后调用Web API
PowerShell脚本传递参数
Powershell RESTAPI 访问Office365