请求正文必须包含以下参数:'grant_type'...但是我将其放在正文中

时间:2018-12-08 00:36:52

标签: node.js oauth-2.0 httprequest microsoft-graph npm-request

我将grant_type参数放在文档正文中的请求正文中,但是Microsoft Graph仍然抱怨它不存在;

const tokenRequestBody = [
    "grant_type=client_credentials",
    "scope=https%3A%2F%2Fgraph.microsoft.com%2F.default",
    `client_secret=${config.appClient.password}`
].join("&");

request.post(
    {
        url: tokenRequestUrl,
        json: true,
        headers: {
            "content-type": "application/application/x-www-form-urlencoded"
        },
        body: tokenRequestBody
    },
    (err, req, body) => {
        console.log(body.error_description); 
        // Logs: The request body must contain the following parameter: 'grant_type'.

    }
);

1 个答案:

答案 0 :(得分:1)

我知道了。对于请求节点模块,我必须使用form而不是body