我正在尝试使用OAuth Implicit Flow对Azure Active Directory进行身份验证。
我可以从https://login.microsoftonline.com/organizations/oauth2/v2.0/authorize
获取代码。
我的问题是,当我执行POST
到https://login.microsoftonline.com/organizations/oauth2/v2.0/token
时,我会收到以下信息:
error: 'invalid_request',
error_description:
AADSTS90014: The request body must contain the following parameter: 'grant_type'.
Trace ID: 1ac8aa85-a56c-481d-9100-baaf6d1c2200
Correlation ID: ecaa1339-e176-49d3-90e0-080cc0cb4b8f
Timestamp: 2018-02-26 19:27:07Z,
error_codes: [ 90014 ],
timestamp: '2018-02-26 19:27:07Z',
trace_id: '1ac8aa85-a56c-481d-9100-baaf6d1c2200',
correlation_id: 'ecaa1339-e176-49d3-90e0-080cc0cb4b8f'
作为参考,这是我发布到URI
的内容// Snippet
// I should be sending queryParams to the POST request, but I keep
// getting the error from above and then I only posted the
// "grant_type" as a hard value into Axios
const queryParams = {
client_id: app_id,
client_secret: app_pass,
scope: 'user.read',
redirect_uri: redirect_uri,
grant_type: 'authorization_code'
}
await axios.post(baseUrl, {
grant_type: 'authorization_code'
}).then(res => {
console.log(res.data)
}).catch(err => {
if (err.response) {
console.error(err.response.data)
console.error(err.response.status)
console.error(err.response.headers)
} else if (err.request) {
console.error(err.request)
} else {
console.error('ERROR', err.message);
}
console.log(err.config)
})
然后,为了扩展日志,这是axios在错误响应中向我报告的内容
{
adapter: [Function: httpAdapter],
transformRequest: { '0': [Function: transformRequest] },
transformResponse: { '0': [Function: transformResponse] },
timeout: 0,
xsrfCookieName: 'XSRF-TOKEN',
xsrfHeaderName: 'X-XSRF-TOKEN',
maxContentLength: -1,
validateStatus: [Function: validateStatus],
headers: {
Accept: 'application/json, text/plain, */*',
'Content-Type': 'application/json;charset=utf-8',
'Access-Control-Allow-Origin': 'http://localhost:4200',
'User-Agent': 'axios/0.18.0',
'Content-Length': 35 },
method: 'post',
url: 'https://login.microsoftonline.com/organizations/oauth2/v2.0/token',
data: '{"grant_type":"authorization_code"}'
}
}
有人能够给我一些关于我出错或不发布价值的见解吗?真的在这个问题上摸不着头脑。