oauth-2.0 Microsoft get access tocken一直要求我输入“grant_type”

krcsximq  于 2022-10-31  发布在  其他
关注(0)|答案(1)|浏览(177)

我试图获得访问令牌与微软图形API。我一直得到错误-

error_description": "AADSTS900144: The request body must contain the following parameter: 'grant_type'

在我的发布请求中,我添加了“grant_type”参数,我做错了什么?
请求:(我把我的租户和编辑所有其他参数)

POST https://login.microsoftonline.com/{tenant}/oauth2/v2.0/token HTTP/1.1
Host: login.microsoftonline.com
Content-Type: application/x-www-form-urlencoded

client_id=535fb089-9ff3-47b6-9bfb-4f1264799865
&scope=https%3A%2F%2Fgraph.microsoft.com%2F.default
&client_secret=qWgdYAmab0YSkuL1qKv5bPX
&grant_type=client_credentials

回应:

{
    "error": "invalid_request",
    "error_description": "AADSTS900144: The request body must contain the following parameter: 'grant_type'.\r\nTrace ID: 4c3017cc-8624-4921-8cea-794861ca5a00\r\nCorrelation ID: cf5e682c-7522-4be3-a9f3-16bb33f40946\r\nTimestamp: 2022-08-02 10:20:07Z",
    "error_codes": [
        900144
    ],
    "timestamp": "2022-08-02 10:20:07Z",
    "trace_id": "4c3017cc-8624-4921-8cea-794861ca5a00",
    "correlation_id": "cf5e682c-7522-4be3-a9f3-16bb33f40946",
    "error_uri": "https://login.microsoftonline.com/error?code=900144"
}

参考:https://learn.microsoft.com/en-us/graph/auth-v2-service
这4天前还管用...我不知道是什么
谢谢!

yws3nbqq

yws3nbqq1#

你不应该在参数和头中发送grant_type。这些应该在主体参数中发送,这样只有它才能工作。
URL:https://login.microsoftonline.com/common/oauth2/v2.0/token client_id,scope和redirect_uri参数可以作为查询参数发送。其中,作为grant_type,code和client_secret应在主体参数中发送。

grant_type:authorization_code, 
code: {code you got from the authorization step}, 
client_secret:****

相关问题