gpt4 book ai didi

javascript - 对 Graph API 的 POST 请求因错误请求而失败

转载 作者:行者123 更新时间:2023-11-30 06:14:06 25 4
gpt4 key购买 nike

我正在开发一个脚本来访问图形 API 以读取我们 AD 中的所有用户。我正在通过 AXIOS 执行请求:

    let response;
try {
response = await axios.post(`https://login.microsoftonline.com/${config.get('azure.tenant')}/oauth2/v2.0/token`, {
client_id: config.get('azure.appId'),
scope: config.get('azure.scope'),
client_secret: config.get('azure.secret'),
grant_type: config.get('azure.grantType')
});
} catch (e) {
res.send(e);
}

但是,这失败了:

{
"message": "Request failed with status code 400",
"name": "Error",
"stack": "Error: Request failed with status code 400\n at createError (C:\\_Apps\\repos\\timesAPI\\node_modules\\axios\\lib\\core\\createError.js:16:15)\n at settle (C:\\_Apps\\repos\\timesAPI\\node_modules\\axios\\lib\\core\\settle.js:17:12)\n at IncomingMessage.handleStreamEnd (C:\\_Apps\\repos\\timesAPI\\node_modules\\axios\\lib\\adapters\\http.js:237:11)\n at IncomingMessage.emit (events.js:194:15)\n at endReadableNT (_stream_readable.js:1103:12)\n at process._tickCallback (internal/process/next_tick.js:63:19)",
"config": {
"url": "https://login.microsoftonline.com/86xxxxxxxxx8df7b/oauth2/v2.0/token",
"method": "post",
"data": "{\"client_id\":\"18xxxxxxxxf5x\",\"scope\":\"https://graph.microsoft.com/.default\",\"client_secret\":\"/xxxxxxxS:6xxxxxsxxQ\",\"grant_type\":\"client_credentials\"}",
"headers": {
"Accept": "application/json, text/plain, */*",
"Content-Type": "application/json;charset=utf-8",
"User-Agent": "axios/0.19.0",
"Content-Length": 184
},
"transformRequest": [
null
],
"transformResponse": [
null
],
"timeout": 0,
"xsrfCookieName": "XSRF-TOKEN",
"xsrfHeaderName": "X-XSRF-TOKEN",
"m

axContentLength": -1
}
}

为此,我遵循以下教程:https://learn.microsoft.com/en-us/graph/auth-v2-service ,其中表示,通过以下方式访问 api:

// Line breaks are for legibility only.

POST https://login.microsoftonline.com/{tenant}/oauth2/v2.0/token HTTP/1.1 Host: login.microsoftonline.com Content-Type: application/x-www-form-urlencoded

client_id=535fb089-9ff3-47b6-9bfb-4f1264799865 &scope=https%3A%2F%2Fgraph.microsoft.com%2F.default &client_secret=qWgdYAmab0YSkuL1qKv5bPX &grant_type=client_credentials

我只是发送了错误的 header 吗?

最佳答案

解决了。我使用字符串作为第二个参数发送了凭证:client_id=${config.get('azure.appId')}&scope=${config.get('azure.scope')}&client_secret=${config .get('azure.secret')}&grant_type=${config.get('azure.grantType')}

关于javascript - 对 Graph API 的 POST 请求因错误请求而失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57266377/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com