【问题标题】:Consume Azure Authenticated .net core API with PowerShell通过 PowerShell 使用 Azure Authenticated .net core API
【发布时间】:2020-11-12 00:33:34
【问题描述】:

我正在尝试使用 powershell 脚本调用经过身份验证的 azure ad .net core api。有人可以帮我处理 powershell 脚本吗?我已经在 Azure Active Directory 中为 api 创建了一个应用注册。

【问题讨论】:

  • 嗨@Dev,您是使用 .net 还是 PowerShell 进行身份验证?两者之间的交互是什么?

标签: azure powershell azure-active-directory webapi


【解决方案1】:

我暴露了Azure保护的api,为api创建了应用注册,然后使用client credential flow获取token:

脚本:

$clientID = 'a13b414b-93b3-4aae-bb68-6a40ffxxxxxx'
$secretKey = '4.Yi4qwn_rqe7BK3F6Nfz.c0A7pTxxxxxx'
$tenantID = 'e4c9ab4e-bd27-40d5-8459-230ba2xxxxxx'

$password = ConvertTo-SecureString -String $secretKey -AsPlainText -Force
$credential = New-Object System.Management.Automation.PSCredential($ClientID,$password)
Connect-AzureRmAccount -ServicePrincipal -Credential $credential -Tenant $tenantID

$authUrl = "https://login.microsoftonline.com/" + $tenantID + "/oauth2/v2.0/token/"
$body = @{
   "scope" = "api://a13b414b-93b3-4aae-bb68-6a40ffxxxxxx/.default";
   "grant_type" = "client_credentials";
   "client_id" = $ClientID
   "client_secret" = $secretKey
}

Write-Output "Getting Authentication-Token" 
$adlsToken = Invoke-RestMethod -Uri $authUrl –Method POST -Body $body
Write-Output $adlsToken

【讨论】:

  • 这个脚本有帮助。谢谢!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-07-22
  • 2020-06-14
  • 1970-01-01
  • 1970-01-01
  • 2019-05-30
  • 1970-01-01
相关资源
最近更新 更多