/ token请求中的404响应

时间:2018-12-08 00:02:21

标签: node.js oauth-2.0 microsoft-graph

我正在尝试在this guide之后从Microsoft Graph API接收访问令牌。因此,我在Node中执行POST请求,但收到404错误状态:

const tokenRequestUrl = [
    `https://login.microsoftonline.com/${config.tenantId}/oauth2/v2.0/token HTTP/1.1?client_id=${config.appClient.id}`,
    `scope=https%3A%2F%2Fgraph.microsoft.com%2F.default`,
    `client_secret=${config.appClient.password}`,
    "grant_type=client_credentials"
].join("&");
request.post(
    tokenRequestUrl,
    {
        headers: {
            "content-type": "application/application/x-www-form-urlencoded"
        }
    },
    (err, req, body) => {
        console.log(req.statusCode, body); // 404, ""
    }
);

一些调试信息(隐藏):

  • 租户ID:XXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX
  • 应用程序客户端ID:XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX
  • APP客户端密码:XXXXXXXXXXXXXXXXXXXXXXX

1 个答案:

答案 0 :(得分:0)

您不小心在URL中有协议版本。您有oauth2/v2.0/token HTTP/1.1?client_id,需要在URL中删除HTTP/1.1。所以看起来像oauth2/v2.0/token?client_id