我可以使用 Powershell 連接到 MS Graph 以獲取 Bearer 令牌,但不能使用 ADFv2 中的 Web Acvtivity 使用相同的憑據。
我從 Azure 中的現有應用程式獲取 TenantId、ApplicationId 和 ClientSecret。

這就是我在 Powershell 中所做的 - 作品
# Authenticate to Microsoft Graph
Write-Host "Authenticating to Microsoft Graph via REST method"
$url = "https://login.microsoftonline.com/$tenantId/oauth2/token"
$resource = "https://graph.microsoft.com/"
$restbody = @{
grant_type = 'client_credentials'
client_id = $applicationID
client_secret = $clientSecret
resource = $resource
}
# Get the return Auth Token
$token = Invoke-RestMethod -Method POST -Uri $url -Body $restbody
Write-Host "Authenticated - token retrieved of type " $($token.token_type)
結果

這是網路活動 - 失敗
Input
{
"url": "https://login.microsoftonline.com/<tenantId>/oauth2/token",
"method": "POST",
"headers": {
"Content-Type": "application/x-www-form-urlencoded"
},
"body": "grant_type=client_credentials&client_id=\"<applId>\"&client_secret=\"<client_secret>\"&resource=\"https://graph.microsoft.com/\"",
"authentication": {
"type": "MSI",
"resource": "https://graph.microsoft.com/"
}
}
錯誤
在目錄“{tenantName}”中找不到識別符號為“{appIdentifier}”的應用程式。如果租戶管理員未安裝應用程式或租戶中的任何用戶未同意此應用程式,則可能會發生這種情況。您可能已將身份驗證請求發送給錯誤的租戶。
該錯誤沒有意義,因為它在 powershell 中有效。
這里的區別是我使用自己的帳戶和 ADF 中的系統分配的 MI 執行 powershell。我缺少什么權限?我該如何解決這個問題?
uj5u.com熱心網友回復:
我試圖在我的環境中重現相同的東西得到以下結果:
帶有不記名令牌的 PowerShell:

要解決錯誤。請按照以下步驟操作:
Step1:創建AD應用添加權限如下:

步驟 2:創建一個 Web 活動以從 ADF 獲取訪問令牌
- 網址:
https://login.microsoftonline.com/<Tenant ID>/oauth2/token

方法: POST
身體:
grant_type=client_credentials&client_id=<client_id>&client_secret=<client_secret>&resource=https://graph.microsoft.com/標題:
Content-Type:application/x-www-form-urlencoded

Step3:創建設定變數:
- 添加動態內容 ->
@activity('Web1').output.access_token

回復

轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/518223.html
上一篇:禁用用戶AD中的E3許可證清理
