Search code examples
javascriptdirect-line-botframework

Direct Line API Microsoft Bot Framework - Get token without exposing secret publicly in Javascript


I'm creating custom chat window on a wordpress site (hosted outside Azure) for my bot using Direct line connector and Javascript, and to start conversation I need to specify Direct line SECRET or a TOKEN for my bot app.

To get a token i have to make a REST call to https://directline.botframework.com/v3/directline/tokens/generate and add to header "Authorization : Bearer SECRET". I don't want to expose that SECRET publicly in my javascript file and I don't want to pass it as a URL parameter.

What are my other options? How to get token without exposing my bot Direct line SECRET to client?


Solution

  • There is no front end solution, unfortunately. After your web page is served, all of its contents including all script files are available to be scrutinized by anybody who requested the page. The only way to hide your key is to use your server as a middle man, and store the secret there. Sorry for the crude drawing:

    keep your secret secret.

    If your entire project is a static page, then this means substantial work is needed to set up a server. Thankfully, it's not as difficult to get a server up and running today as it was 10 years ago. If you're already familiar with JavaScript, then you'll be able to learn node.js quickly. Then, you can implement your server with a framework such as express which will do a majority of the heavy lifting for you.