【问题标题】:Authentication on BoT in MS BoT frameworkMS BoT 框架中的 BoT 认证
【发布时间】:2017-01-04 07:10:14
【问题描述】:

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

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

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

【问题讨论】:

    标签: botframework


    【解决方案1】:

    有几种方法可以解决您的问题。

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

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

    方法一:

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

    但是,为了使其工作,您需要用户的 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.......
    });
    

    然后,您将执行正常逻辑,在机器人对话端点创建和处理支持票证。如果在以后的对话路由中需要,您甚至可以将 authToken 存储在 session 对象中。 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,它允许您创建“反向通道”。

    使用 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.

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

    我希望这会有所帮助!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-02-13
      • 1970-01-01
      • 2018-10-24
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多