Kylie Bot Part 4 - Customising Our Authentication
This post will focus on providing us with some more flexibility in terms of our authentication options that we specified previously. As you know from the previous blog post, we installed a Nuget package from Mat Vellosso to handle our authentication mechanisms. Luckily, Mat has made a sample available to us with the source code available here.
This post will focus on including the elements from the AuthBot project into our own so that we can change text prompts, etc. with ease. Here goes.
First, we will need to remove the previous AuthBot Nuget package by right clicking on our KylieBot project and the selecting 'Manage Nuget Packages...'
You should be presented with the following screen:
Make sure you have the 'Installed' tab selected at the top of the screen. You should see the AuthBot package there. You can go ahead and remove this package by clicking uninstall on the top right hand side of the screen. You should get a confirmation of this in the results window at the bottom of your screen.
*You will also need to remove the using clauses that we automatically added previously. These will be in the RootDialog and MessagesController classes and will point to AuthBot.Dialogs and AuthBot.Models.
Next, we are going to explicitly add the required classes from the AuthBot project from Mat. To do this, we will create the classes in our project (so that namespaces, etc. are correct) and then copy the content of the classes across. The first class that we will need to add is to the Dialogs folder of our project as follows:
*The class is called AzureAuthDialog and we will need to copy the content from the same file in the AuthBot project. Remember when copying the content to just take the contents of the actual class and to leave the class name and namespace definition as we will have our own versions of these in our project.
Next, we will need to add a folder to our KylieBot project by right clicking on the KylieBot project and selecting 'Add->Folder':
To this newly added folder, we can specify a name of 'Helpers'. Next, lets add a class called 'AzureActiveDirectoryHelper' to the folder in a similar fashion to the previous step. We will also need to copy the content form the same file in the AuthBot project. Remember when copying the content to just take the contents of the actual class and to leave the class name and namespace definition as we will have our own versions of these in our project.
Next, we need to add the following classes to the main KylieBot project: ContextConstants, ContextExtensions. Again, copy the content from the Authbot project, remembering not to copy the namespace and class definitions from the AuthBot versions.
Repeat the class addition process for the following 5 classes that need to be added to the Models folder before copying content from the AuthBot versions to the local versions:
Next, we need to add a very specific RESX file to the main KylieBot project. To do this, right click on the KylieBot project and select add class and then select the 'General' tab under the 'Visual C#' tree structure on the left hand side of the screen as follows:
The file needs to be named AuthText and once it's created, we can double click on it to add some parameters to it. Double clicking on the file should present a screen like this:
*Add an item that reflects the above screen shot. This will be an item with a Name of 'CancellationWords' and Value of 'QUIT,CANCEL,STOP,GO,BACK,RESET,HELP'.
Next, we need to add the OAuthCallbackController class to the Controllers folder of the project and copy the content from the AuthBot project file, remembering not to copy the namespace and method signatures.
Finally, we will need to update the Global.asax file by removing the AuthBot prefix from the entries in there. Our project structure should now look like this:
Great work! Now we can finally go ahead and change some of the wording in the authentication challenge that we receive in our bot dialog. To do this, let's open the AzureAuthDialog class and modify the the prompt field in the two constructors. My updated versions look as follows:
Perfect! Let's go ahead and test our changes. Run the KylieBot project and the Emulator as discussed in previous posts and respond to the initial prompt from Kylie Bot. You should then be presented with the now updated authentication request as follows:
Awesome work. Seems like a large amount of work for very little outcome. This is not however true in fact. Using our own version of the authentication mechanism provides us with the opportunity to customise it as necessary and this will become quite relevant in later posts. Lookout for the next post on logging our conversations to our Dynamics 365 Customer Engagement instance!
*Don't forget to check-in your code!