我正在尝试在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, ""
}
);
一些调试信息(隐藏):
XXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX
XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXX
答案 0 :(得分:0)
您不小心在URL中有协议版本。您有oauth2/v2.0/token HTTP/1.1?client_id
,需要在URL中删除HTTP/1.1
。所以看起来像oauth2/v2.0/token?client_id