如何在 BotFramwork Node.js 网络聊天中隐藏直线秘密和传递令牌
How to hide directline secret and pass token in BotFramwork Node.js webchat
我是 node.js 的新手。
我在我的服务器上托管了以下 Webchat 版本,并根据需要修改了直线键和语音 api 键。
https://github.com/Microsoft/BotFramework-WebChat/tree/master/samples/speech
这里的问题是,目前,我已经在下面的代码中硬编码了密钥,而不是我想生成直线令牌并传递它。
BotChat.App({
bot: bot,
locale: params['locale'],
resize: 'detect',
speechOptions: speechOptions,
user: user,
directLine: {
secret: 'my secret goes here',
webSocket: params['webSocket'] && params['webSocket'] === 'true' // defaults to true
}
}, document.getElementById('BotChatGoesHere'));
如何实现?
提前致谢。
您还可以使用 npm 中的 dotenv 模块。
这允许您 'hide' 您的密钥,并且看起来像这样:
BotChat.App({
bot: bot,
locale: params['locale'],
resize: 'detect',
speechOptions: speechOptions,
user: user,
directLine: {
secret: process.env.DIRECT_LINE_SECRET,
webSocket: params['webSocket'] && params['webSocket'] === 'true' // defaults to true
}
}, document.getElementById('BotChatGoesHere'));
希望对您有所帮助!
您需要实现令牌刷新机制
curl -X POST \
https://directline.botframework.com/v3/directline/tokens/generate \
-H 'authorization: Bearer direct_line_secret' \
-H 'cache-control: no-cache' \ -H 'postman-token: 596bb603-b6f6-4802-c868-bb2055e7cd44'
您应该会得到如下所示的响应
您可以将令牌反馈到您的直线应用程序
{
"conversationId": "5pCw0I1VZxD64AZmNR624I",
"token": "lqBRp7neCNM.dAA.NQBwAEMAd.DtSAr-V81AE.8WGDZ-O0H4E.CT4ZIuIqHR1AvN8Byb0ewzF4eE",
"expires_in": 1800 }
Refer Here 更多
我是 node.js 的新手。 我在我的服务器上托管了以下 Webchat 版本,并根据需要修改了直线键和语音 api 键。
https://github.com/Microsoft/BotFramework-WebChat/tree/master/samples/speech
这里的问题是,目前,我已经在下面的代码中硬编码了密钥,而不是我想生成直线令牌并传递它。
BotChat.App({
bot: bot,
locale: params['locale'],
resize: 'detect',
speechOptions: speechOptions,
user: user,
directLine: {
secret: 'my secret goes here',
webSocket: params['webSocket'] && params['webSocket'] === 'true' // defaults to true
}
}, document.getElementById('BotChatGoesHere'));
如何实现?
提前致谢。
您还可以使用 npm 中的 dotenv 模块。
这允许您 'hide' 您的密钥,并且看起来像这样:
BotChat.App({
bot: bot,
locale: params['locale'],
resize: 'detect',
speechOptions: speechOptions,
user: user,
directLine: {
secret: process.env.DIRECT_LINE_SECRET,
webSocket: params['webSocket'] && params['webSocket'] === 'true' // defaults to true
}
}, document.getElementById('BotChatGoesHere'));
希望对您有所帮助!
您需要实现令牌刷新机制
curl -X POST \
https://directline.botframework.com/v3/directline/tokens/generate \
-H 'authorization: Bearer direct_line_secret' \
-H 'cache-control: no-cache' \ -H 'postman-token: 596bb603-b6f6-4802-c868-bb2055e7cd44'
您应该会得到如下所示的响应
您可以将令牌反馈到您的直线应用程序
{ "conversationId": "5pCw0I1VZxD64AZmNR624I", "token": "lqBRp7neCNM.dAA.NQBwAEMAd.DtSAr-V81AE.8WGDZ-O0H4E.CT4ZIuIqHR1AvN8Byb0ewzF4eE", "expires_in": 1800 }
Refer Here 更多