oauth2错误AADSTS90014:请求正文必须包含以下参数:'grant_type'

问题描述 投票:1回答:2

从Windev的开发中,我使用Oauth 2.0授权来访问用户的Outlook邮件。

该应用程序在https://apps.dev.microsoft.com注册,没有Implicit工作流程。用户输入凭据后,将返回授权码。使用新代码,使用HTTP Post命令请求承载令牌。

到现在为止还挺好。

只有响应给出了对我没有意义的错误消息。

在代码中:

m_sHTTPUrl = "client_id=" + m_sClientID + "&client_secret=" ...
    + m_sClientSecret ...
    + "&redirect_uri=" + m_sRedirectURL + "&code=" + m_sAuthToken ...
    + "&grant_type=authorization_code"
m_sHTTPres = ""
LogLocalFile("GetAccessToken - " + m_sTokenURL + " // " + m_sHTTPUrl) 

cMyRequest is httpRequest
cMyRequest..Method = httpPost
cMyRequest..URL = m_sTokenURL
cMyRequest..ContentType = "application/x-www-form-urlencoded"
cMyRequest..Header["grant_type"] = "authorization_code"
cMyRequest..Header["code"] = m_sAuthToken
cMyRequest..Header["client_id"] = m_sClientID
cMyRequest..Header["client_secret"] = m_sClientSecret
cMyRequest..Header["scope"] = m_sScope
cMyRequest..Header["redirect_uri"] = m_sRedirectURL
//cMyRequest..Content = m_sHTTPUrl
cMyResponse is httpResponse = HTTPSend(cMyRequest)
m_sHTTPres = cMyResponse.Content

在日志文件中,我请求使用的参数和httpResponse的内容:

GetAccessToken - https://login.microsoftonline.com/common/oauth2/v2.0/token // grant_type=authorization_code
&code=xxxxxxx
&scope=openid+offline_access+User.Read+Email+Mail.Read+Contacts.Read
&redirect_uri=http://localhost/
&client_id=xxxxxxx
&client_secret=xxxxxxx

GetAccessToken - error = invalid_request
GetAccessToken - error_description = AADSTS90014: The request body must contain the following parameter: 'grant_type'.

grant_type是应该在标题中。

有没有人知道让OAUTH2工作需要什么?

http oauth-2.0 bearer-token windev
2个回答
0
投票

根据这个post,oauth-2.0参数必须在您的请求的内容中。你有没试过?这个post也警告身体的编码。


0
投票

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

grant_type:authorization_code,代码:{您从授权步骤获得的代码},client_secret:****

© www.soinside.com 2019 - 2024. All rights reserved.