You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Azure刷新令牌获取AccessToken报错900144的解决方法

解决Azure访问令牌生成错误(Error Code: 900144)

错误原因:请求格式不匹配。你设置了Content-Type为application/x-www-form-urlencoded,但却将请求体转换成JSON格式传递,而Azure AD的令牌端点要求该类型请求使用表单键值对格式,而非JSON,这就导致了请求体必须包含以下参数: '{name}'的错误。

修正方案

直接移除ConvertTo-Json的转换操作,Invoke-RestMethod会自动将哈希表格式的$body转换为符合要求的表单格式。

修正后的完整代码:

param (
    $RefreshToken,
    $tenantId,
    $clientId,
    $clientSecret
)

[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.SecurityProtocolType]::Tls12

# Azure token endpoint
$tokenUrl = "https://login.microsoftonline.com/$tenantId/oauth2/v2.0/token"

# Prepare the body of the request
$body = @{
    grant_type    = "refresh_token"
    client_id     = $clientId
    client_secret = $clientSecret
    refresh_token = $RefreshToken
    scope         = "499b84ac-1321-427f-aa17-267ca6975798/.default"
}

# Make the POST request
$response = Invoke-RestMethod -Uri $tokenUrl -Method Post -Body $body

# Output the response
$response

补充说明

如果需要显式指定Content-Type,也可以添加-ContentType参数,效果一致:

$response = Invoke-RestMethod -Uri $tokenUrl -Method Post -ContentType "application/x-www-form-urlencoded" -Body $body

内容的提问来源于stack exchange,提问作者user10434309

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.05 05:20:11