azure - 无法从 Azure API 检索 token

标签 azure powershell azure-active-directory

我正在尝试获取 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/

相关文章:

azure - 在 Azure 管道上使用 `originalSwaggerUrl` 进行自定义 API 连接器部署期间,API 定义不会更新

powershell - 如何解决 PowerShell V5 中的模块嵌套限制已超出错误?

csv - 从Powershell foreach循环将输出安排为CSV

asp.net - 生成个人访问 token 以调用 Azure Web Api (OAuth)

azure-active-directory - Azure AD 添加,而不是邀请,外部用户作为成员,而不是 guest

azure - 从 Web 应用程序访问 Azure 文件存储,无需后端

适用于媒体的 Azure 视频分析器 - ARM_ACCOUNT_MUST_BE_MANAGED_BY_ARM

azure - Terraform - 如何动态创建资源

powershell - 在Powershell中获取Azure函数的函数和主机 key

winforms - 如何配置适用于 Azure 的 CSLA WCF 数据门户?