Integrating Azure Bot in Web Application

穿精又带淫゛_ 提交于 2019-12-20 07:29:53

问题


We have a scenario where a user would first login to web application before starting a conversation with Azure Bot.

My question is how do we ensure bot will only allow user to ask financial questions related to his own accounts considering the bot is capable of answer questions related to financial holding of the person logged in.

Basically is there a way to pass principal object to the bot before the conversation starts. If yes how do we pass those details.


回答1:


The BotFramework currently does not support single sign-on; however, the BotFramework Web Chat Development team has recommended different approaches to create a single sign-on experience and is currently working on developing a sample.

The main approach recommends piggybacking the authentication token on every outgoing message by adding it to the activity's channel data. To do this, you can create a custom middleware that appends the additional data. Take a look at the code snippet below.

const store = window.WebChat.createStore(
  {},
  ({ dispatch }) => next => action => {
    if (action.type === 'DIRECT_LINE/POST_ACTIVITY') {
      // The channelData submitted here is very similar to HTTP cookies and vulnerable to forgery attack.
      // Make sure you use signature to protect it and verify the signature on the bot side.

      // To minimize unexpected behaviors, we recommend to treat the "action" object as if it is immutable.
      // We use simple-update-in package to update "action" with partial deep cloning.
      action = window.simpleUpdateIn(action, ['payload', 'activity', 'channelData', 'token'], () => token);
    }

    return next(action);
  }
);

window.WebChat.renderWebChat({
  directLine: window.WebChat.createDirectLine({ token }),
  // We will use a custom version of Redux store, which we added middleware to handle backchannel messages.
  store
}, document.getElementById('webchat'));

On the bot side, you can retrieve the token from the channel data and use it to make various requests. For more details on adding data to outgoing activities, take a look at this sample.

For more details regarding recommended approaches, take a look at this issue on GitHub. The Web Chat Development team is also using it to track the progress of the sample.

Hope this helps.



来源:https://stackoverflow.com/questions/54765707/integrating-azure-bot-in-web-application

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!