[英]Get access token from Microsoft Graph for Azure
I have this code below to try to get an access token from Microsoft Graph.我在下面有这个代码来尝试从 Microsoft Graph 获取访问令牌。 Using the query in Postman works great.
在 Postman 中使用查询效果很好。 But whenever I tried in node I am having this error: The request body must contain the following parameter: 'grant_type'.
但是每当我在节点中尝试时,我都会遇到此错误:请求正文必须包含以下参数:'grant_type'。
What am I missing here please?请问我在这里缺少什么? Im really stuck.
我真的卡住了。 (the value for grant_type is 'password')
(grant_type 的值为“密码”)
// GET TOKEN
alterState(state => {
const { host, userName, password, scope, client_secret, client_id, tenant_id, grant_type } = state.configuration;
const data = {
grant_type: grant_type,
client_id: client_id,
client_secret: client_secret,
scope: scope,
userName: userName,
password: password,
};
return post(
`${host}${tenant_id}/oauth2/v2.0/token`,
{
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
},
body: data
},
state => {
console.log(state);
}
)(state);
});
I found the answer.我找到了答案。 Actually data for the post should not be sent as body but as form .
实际上帖子的数据不应该作为body发送,而是作为form发送。
So by doing this below you have the access token:因此,通过在下面执行此操作,您将获得访问令牌:
return post(
url,
{
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
},
form: data
})
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.