1
votes

I am using Bot Framework SDK V4 (.Net) for building my Bot Service. I would like to enable authentication using Azure AD.

I found these steps - https://docs.microsoft.com/en-us/azure/bot-service/bot-builder-tutorial-authentication?view=azure-bot-service-3.0

But this is for SDK V3, which is not working for V4

Can someone help on how to enable Azure AD Authentication for bots built using V4 framework?

2
We currently have a sample for v4 in progress. I would expect it in the not too distant future, for sure by Ignite. - D4RKCIDE
I should add that all the steps to set up your bot in Azure and your AAD app would be the same as the doc you linked. Just the bot's code would be different. - D4RKCIDE
Yes @JasonSowers. You are right. I understand that the steps are same. But I am unable to find the var token = await context.GetUserTokenAsync(ConnectionName).ConfigureAwait(false); in V4 framework - Ram
take a look at this repo Its not a final or official sample, but it should help you get started. - D4RKCIDE

2 Answers

0
votes

I know this is a bit late answer but it might help someone. You need to create your bot service in Azure and get Microsoft App Id and App Password. Then you can prompt the user to sign in.

private static OAuthPrompt Prompt(string connectionName)
{
    return new OAuthPrompt(
        LoginPromptName,
        new OAuthPromptSettings
        {
            ConnectionName = connectionName,
            Text = "Please Sign In",
            Title = "Sign In",
            Timeout = 300000, // User has 5 minutes to login (1000 * 60 * 5)
        });
}

Create a WaterfallStep to login Prompt.

private static async Task<DialogTurnResult> PromptStepAsync(WaterfallStepContext step, CancellationToken cancellationToken)
    {
        return await step.BeginDialogAsync(LoginPromptName, cancellationToken: cancellationToken);
    }

Next you can can continue to do what ever you want with the token.

private static async Task<DialogTurnResult> LoginStepAsync(WaterfallStepContext step, CancellationToken cancellationToken)
        {
            // Get the token from the previous step. Note that we could also have gotten the
            // token directly from the prompt itself. There is an example of this in the next method.
            var tokenResponse = (TokenResponse)step.Result;
                    if (tokenResponse != null)
                    {
                        // use the token to do exciting things!
                    }
                    else
                    {
                        // If Bot Service does not have a token, send an OAuth card to sign in
                    }

            await step.Context.SendActivityAsync("Login was not successful please try again.", cancellationToken: cancellationToken);
            return Dialog.EndOfTurn;
        }

Follow this guide for more information.

You can even set other OAuth providers for Azure like Github, Facebook. To do this go to Settings of your Bot Channels Registration and find add new connection option.

enter image description here

0
votes

I'm using the botframework community's AzureAdAuthMiddleware to inject the Azure AD authentication functionality into my v4 chatbot.

You can check it out here: https://github.com/BotBuilderCommunity/botbuilder-community-dotnet