【发布时间】:2018-09-05 21:02:10
【问题描述】:
在 Windev 的开发中,我使用 Oauth 2.0 进行授权,以从用户那里获得对 Outlook 邮件的访问权限。
应用程序在https://apps.dev.microsoft.com 注册,没有隐式工作流。 用户输入凭据后,将返回授权码。 使用新代码,承载令牌是通过 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 正常工作?
【问题讨论】:
-
感谢您的指导。 a) 它必须在正文中,而不是在标题中。 b) 它必须以纯文本形式进行编码。比它有效。
标签: http oauth-2.0 bearer-token windev