BotBuilder,直线 API returns "tokenParameters is missing User" 具有增强的身份验证选项
BotBuilder, Direct Line API returns "tokenParameters is missing User" with Enhanced authentication options
我在 Azure 帐户上发布了一个机器人,我正试图从中取出魔术代码,因此按照 Direct Line documentation 我改进了代码以隐藏令牌。但是一旦启用增强型身份验证选项,我总是得到相同的响应。
{
"error": {
"code": "BadArgument",
"message": "tokenParameters is missing User."
}
}
而且我无法弄清楚如何使用用户数据完成 HTTP 请求。
该机器人基于 BotFramework SDK v4,加上一些控制器,用于使用封装的密钥请求和刷新令牌。
我通过不同和错误的方式将 userId 数据添加到请求中,结果总是相同。
请求令牌代码
server.post('/dl/tokenRequest', async (_, res) => {
try {
const userId = "dl_testuser1";
const askToken = await fetch('https://directline.botframework.com/v3/directline/tokens/generate', {
headers: {
authorization: Bearer ${ process.env.DIRECT_LINE_SECRET }
},
//HERE THE userId INFORMATION,
method: 'POST'
});
const json = await askToken.json();
if ('error' in json) {
console.log('Requesting token - Error');
res.send(500);
} else {
console.log(`Requesting token ` + json.token);
res.send(json);
}
} catch (err) {
res.send(500);
}
});
在启用增强工具之前,我应该如何放置用户信息才能从 DL API 获得 OK?
您的页眉中似乎缺少 Content-Type
。看看下面的代码片段。
try {
const res = await fetch('https://directline.botframework.com/v3/directline/tokens/generate',
{
method: 'POST',
headers: {
'Authorization': `Bearer <SECRET>`,
'Content-Type': 'application/json'
},
body: {
user: {
id: "dl_123", // user id must start with 'dl_'
name: "user"
}
}
});
const json = await res.json();
} catch (error) {
console.log(error)
}
请注意,您不必检查 'error' 是否在 JSON 响应中 - try-catch 块应该会处理该问题。
希望对您有所帮助!
我在 Azure 帐户上发布了一个机器人,我正试图从中取出魔术代码,因此按照 Direct Line documentation 我改进了代码以隐藏令牌。但是一旦启用增强型身份验证选项,我总是得到相同的响应。
{
"error": {
"code": "BadArgument",
"message": "tokenParameters is missing User."
}
}
而且我无法弄清楚如何使用用户数据完成 HTTP 请求。
该机器人基于 BotFramework SDK v4,加上一些控制器,用于使用封装的密钥请求和刷新令牌。 我通过不同和错误的方式将 userId 数据添加到请求中,结果总是相同。
请求令牌代码
server.post('/dl/tokenRequest', async (_, res) => {
try {
const userId = "dl_testuser1";
const askToken = await fetch('https://directline.botframework.com/v3/directline/tokens/generate', {
headers: {
authorization: Bearer ${ process.env.DIRECT_LINE_SECRET }
},
//HERE THE userId INFORMATION,
method: 'POST'
});
const json = await askToken.json();
if ('error' in json) {
console.log('Requesting token - Error');
res.send(500);
} else {
console.log(`Requesting token ` + json.token);
res.send(json);
}
} catch (err) {
res.send(500);
}
});
在启用增强工具之前,我应该如何放置用户信息才能从 DL API 获得 OK?
您的页眉中似乎缺少 Content-Type
。看看下面的代码片段。
try {
const res = await fetch('https://directline.botframework.com/v3/directline/tokens/generate',
{
method: 'POST',
headers: {
'Authorization': `Bearer <SECRET>`,
'Content-Type': 'application/json'
},
body: {
user: {
id: "dl_123", // user id must start with 'dl_'
name: "user"
}
}
});
const json = await res.json();
} catch (error) {
console.log(error)
}
请注意,您不必检查 'error' 是否在 JSON 响应中 - try-catch 块应该会处理该问题。
希望对您有所帮助!