无法从Azure API检索令牌



我正在尝试获取一个令牌,以便能够在Azure AD 中检索组信息

这是我针对API的powershell脚本:

Invoke-RestMethod -Method POST -Uri 'https://login.microsoftonline.com/<tenantID>/oauth2/v2.0/token?api-version=1.6'
-Header @{'Content-type' = 'application/x-www-form-urlencoded'} 
-Body '{grant_type=client_credentials&client_id=<clientID>&scope=https://graph.microsoft.com/.default&client_secret=<clientSecret> }'

我一直收到这个错误:{"error":"invalid_request","error_description":"AADSTS900144: The request body must contain the following parameter: 'grant_type'.rnTrace ID:

你的身体畸形,只需做:

$body = @{
Grant_Type    = 'client_credentials'
Scope         = 'https://graph.microsoft.com/.default'
Client_Id     = $ClientID
Client_Secret = $Secret
}
$con = Invoke-RestMethod -Uri "https://login.microsoftonline.com/$tenantid/oauth2/v2.0/token" -Method 'Post' -Body $body
$token = $con.access_token

最新更新