I'm developing a chat bot using MS bot framework v4 SDK in C#.
I've chosen Dispatch bot sample as my base, Since I'm using QnA maker and Luis. Now i want to add an authentication to access my bot. As per the sample Authentication Bot I've added all the dependency including the nuget packages, methods and classes in my bot project code, but still the authentication is not working for me, it throws an exception error and gives sorry something went wrong error. There could be some issue with the way of integration and calling the correct methods.
if anyone has solution or sample of a bot with both authentication and QnA Maker used, please do share me


Sandhiya PriyaRank #26 · 43.2K reputationPosted Oct 27, 2025, 5:10 AM EDT
you’re trying to integrate Azure AD authentication (like OAuthPrompt or Bot authentication) into a Bot Framework v4 C# Dispatch Bot that already uses LUIS + QnA Maker. You’ve added the dependencies from the Authentication Bot sample, but it’s still failing with the “Sorry, something went wrong” message — usually meaning a misconfiguration in your OAuth connection, app settings, or adapter setup.
Let’s break this down carefully
Common Integration Steps (Authentication + LUIS + QnA)
Here’s the correct and stable integration pattern for your scenario.
1. Ensure all required NuGet packages are installed
Make sure your
.csprojincludes:For authentication:
2. Create an OAuth connection in Azure Bot Channels Registration
Go to your bot in Azure Portal ? Settings ? OAuth connections.
Add a connection (e.g.,
MyBotOAuthConnection) with:Service Provider: Azure Active Directory v2
Client ID / Secret / Tenant ID: from your Azure AD App Registration
Scopes:
User.ReadNote the Connection Name — it must match exactly what you configure in your bot.
3. Update
appsettings.json{ "MicrosoftAppId": "your-app-id", "MicrosoftAppPassword": "your-app-password", "ConnectionName": "MyBotOAuthConnection", "LuisAppId": "your-luis-id", "LuisAPIKey": "your-luis-key", "LuisAPIHostName": "your-luis-endpoint", "QnAKnowledgebaseId": "your-qna-id", "QnAEndpointKey": "your-qna-key", "QnAEndpointHostName": "your-qna-endpoint" }4. Update your
Startup.csMake sure your adapter and BotFrameworkHttpAdapter handle authentication errors properly.
public class AdapterWithErrorHandler : BotFrameworkHttpAdapter { public AdapterWithErrorHandler(IConfiguration configuration, ILogger logger) : base(configuration, logger) { OnTurnError = async (turnContext, exception) => { logger.LogError(exception, $"[OnTurnError] unhandled error: {exception.Message}"); await turnContext.SendActivityAsync("Sorry, something went wrong."); }; } }Then in
Startup.cs:5. Add Authentication Dialog to your Bot
Create
LoginDialog.cs:public class LoginDialog : ComponentDialog { private readonly string _connectionName; public LoginDialog(IConfiguration configuration) : base(nameof(LoginDialog)) { _connectionName = configuration["ConnectionName"]; AddDialog(new OAuthPrompt( nameof(OAuthPrompt), new OAuthPromptSettings { ConnectionName = _connectionName, Text = "Please sign in", Title = "Sign In", Timeout = 300000 })); AddDialog(new WaterfallDialog(nameof(WaterfallDialog), new WaterfallStep[] { PromptLoginStepAsync, DisplayTokenStepAsync, })); InitialDialogId = nameof(WaterfallDialog); } private async Task PromptLoginStepAsync(WaterfallStepContext stepContext, CancellationToken cancellationToken) => await stepContext.BeginDialogAsync(nameof(OAuthPrompt), null, cancellationToken); private async Task DisplayTokenStepAsync(WaterfallStepContext stepContext, CancellationToken cancellationToken) { var tokenResponse = (TokenResponse)stepContext.Result; if (tokenResponse != null) await stepContext.Context.SendActivityAsync(MessageFactory.Text($"You are now logged in."), cancellationToken); else await stepContext.Context.SendActivityAsync(MessageFactory.Text("Login was not successful."), cancellationToken); return await stepContext.EndDialogAsync(cancellationToken: cancellationToken); } }6. Integrate with your Dispatch Bot
In your
DispatchBot.cs, inside theOnMessageActivityAsyncmethod:if (turnContext.Activity.Text.Contains("login", StringComparison.OrdinalIgnoreCase)) { await _dialog.RunAsync(turnContext, _conversationState.CreateProperty("DialogState"), cancellationToken); return; } // else route to LUIS / QnA as usual7. Debugging the “Sorry, something went wrong” Error
Check these common points:
Working Example Reference
Here’s a working sample from Microsoft combining QnA + LUIS + Auth:
?? GitHub: BotBuilder-Samples — 51.csharp.AdaptiveBotWithLuisQnAAuth
That example shows exactly how to integrate QnA, LUIS, and Azure AD authentication into one bot.