gpt4 book ai didi

botframework - MS BoT 框架中的 BoT 认证

转载 作者:行者123 更新时间:2023-12-01 00:35:37 25 4
gpt4 key购买 nike

我们计划将 BoT 部署为一种帮助台,以根据用户的文本接受查询并提出支持请求。我们希望将我们的 BoT 与我们自己的 AD 集成以进行身份​​验证。如果 AD 身份验证不起作用,那么我们的计划 B 是说我们将 BoT 作为网络聊天 BoT 托管在我们的网页内,并且所有身份验证都在 Web 应用程序中完成。但是当我们想代表他提出一些支持票时,我们仍然需要捕获登录到 Web 应用程序的用户。知道如何将登录的用户详细信息从托管网页传递到 BoT。托管网页可以是 Azure 或本地实现。

AuthBoT 是唯一的出路,使用该方法将用户重定向到 Web 应用程序进行登录,并使用魔术代码进行身份验证并将 BoT 发回。我们是否有一种无缝的身份验证方式,无需重定向到另一个网页进行身份验证?

我的客户不想转到另一个网页并在此处输入他的凭据以进行身份​​验证。他想要更无缝的身份验证。从某种意义上说,他是对的,因为他已经对自己进行了身份验证并登录了网页,而 BoT 是他网页中的另一个片段。他的观点是为什么我们需要再次登录,为什么 BoT 不能从托管网页中获取身份验证/ token 。这里有什么建议吗?

最佳答案

有几种方法可以解决您的情况。

据我了解,当客户端到达带有聊天机器人小部件的网页时,用户已经通过网页对您的网站进行了身份验证。

编辑:我添加了第三种方法,它是在网页和嵌入式 WebChat 框之间进行通信的首选方式。

方法一:

将用户凭据(身份验证 token )传输到页面内的聊天机器人的一种方法是到 使用来自服务器身份验证端点的凭据开始与用户的新对话。

但是,为了使其正常工作,您需要用户的 IAddress .换句话说,用户之前必须与您的机器人进行过对话,而您必须将其存储在某个地方,可能是在数据库中。

例如,这里是您的服务器代码(这是在 NodeJS 中):

//where user is sent after authenticating through web page
server.post("/authenticated", function(req, res){

//get user iaddress from database using credentials
//(you will need the Iaddress of the user to begin a dialog)
var address = getAddressFromDB(req.body.credentials)

//then use beginDialog to start a new dialog with the user you just authenticated
//(this dialog route will only be accessible from here to guarantee authentication)
bot.beginDialog(address, "/authenticated", { userAuthToken: auth_token });

//success
res.status(200);
res.end();
});

//user is sent here from the above bot.beginDialog() call
bot.dialog("/authenticated", function(session, args){

//extract credentials (auth token) from args
var authToken = args.userAuthToken;

//use auth token here.......
});

然后,您将执行正常逻辑以在机器人对话端点创建和处理支持票证。您甚至可以存储 authTokensession对象,如果在以后的对话路由中需要它。 session.userData.authToken = authToken;
方法二:

另一种验证用户身份的方法是通过聊天窗口本身通过 瀑布对话 .但是,这并不能真正解决您让用户进行两次身份验证的问题,但它可以解决用户必须离开当前网页进行身份验证的问题。

机器人将引导用户完成输入凭据的过程:
//begin user authentication here
bot.dialog("/get_username", [

function(session){
//prompt user for username here
botbuilder.Prompts.text(session, "Hello, what is your username?");
},
function(session, results){
//store username
session.userData.username = results.response;
//begin new dialogue
session.beginDialog("/get_password");
}
]);

bot.dialog("/get_password", [

function(session){
//prompt user for password here
botbuilder.Prompts.text(session, "What is your password?");
},
function(session, results){
//store password
session.userData.password = results.response;
//check credentials
if(checkCredentials(session.userData.username, session.userData.password){
//good credentials, send to post-authentication dialog
session.beginDialog("/authenticated");
} else {
//bad credentials
//reset user data and retry
session.userData.username = "";
session.userData.password = "";
session.beginDialog("/get_username");
}
}
]);

You can actually check out a working example of the above Method 2 code here.

方法三:

让网页与嵌入式 WebChat 机器人通信的首选方式是通过 Direct Line REST API这允许您创建“反向 channel ”。

使用 WebChat 控件 (which you can download and learn about from the repo here) ,您可以设置您的嵌入式机器人和容纳它的网页,通过监听和广播您定义的事件来相互通信。

You can see a great example of this by checking out this example code that shows the client side.

While this code demonstrates what the bot & server-side code is doing behind the scenes.

然后,您可以使用此方法让您的机器人从您的网页中监听身份验证事件,并在用户进行身份验证时,使用附加的所需凭据广播该事件,以便您的机器人可以使用它们。

我希望这有帮助!

关于botframework - MS BoT 框架中的 BoT 认证,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41458114/

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