我正在尝试获取 token 以便能够检索 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: 请求正文必须包含以下参数:'grant_type'。\r\n跟踪 ID:
最佳答案
你的 body 畸形了,就这样做:
$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
关于azure - 无法从 Azure API 检索 token ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/74074606/