Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to authorise with bot even though credentials are apparently valid #2237

Closed
weedroid opened this issue Feb 10, 2017 · 9 comments
Closed
Assignees

Comments

@weedroid
Copy link

I have deployed a chat bot to an Azure instance, but have been unable to test it using either the emulator or the web chat built into the backend of the bots site. I have configured it with the ID and password generated by the bots site, but the problem still occurs.

Failed request tracing on the Azure instance indicates that requests are causing an "Authorization for Microsoft App ID (guid) failed with status code Unauthorized" error.

I have went through the authentication troubleshooting steps on this page and have found the following:

  • Step 1: The bot can be successfully tested locally without authentication
  • Step 2: The ID and password are valid, as an access token is returned when requesting one manually via Postman
  • Step 3: The bot cannot be tested locally with authentication, it fails with the same error as above

The bot's endpoint has been set up correctly - it points to the address of the Azure instance it is deployed to, uses https, and includes /api/messages at the end. The "test" feature on the bot's configuration page also returns a "Endpoint authorization succeeded" message.

@danmarshall
Copy link
Contributor

Can you paste any error stack trace from the webchat (in your browser's debug console) or from your server?

@weedroid
Copy link
Author

Hi Dan,

The stack trace in the failed request trace file from the server is below:

at Microsoft.Bot.Connector.JwtTokenRefresher.<SendAsync>d__2.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.Bot.Connector.Conversations.<ReplyToActivityWithHttpMessagesAsync>d__8.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.Bot.Connector.ConversationsExtensions.<ReplyToActivityAsync>d__7.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Axa.QuoteAndBuy.ChatBot.MessagesController.<HandleSystemMessage>d__2.MoveNext() in D:\...\MessagesController.cs:line 74
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Axa.QuoteAndBuy.ChatBot.MessagesController.<Post>d__1.MoveNext() in D:\...\MessagesController.cs:line 43
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Threading.Tasks.TaskHelpersExtensions.<CastToObject>d__3`1.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Web.Http.Controllers.ApiControllerActionInvoker.<InvokeActionAsyncCore>d__0.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Web.Http.Controllers.ActionFilterResult.<ExecuteAsync>d__2.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Web.Http.Dispatcher.HttpControllerDispatcher.<SendAsync>d__1.MoveNext()

This is the code preceding and including line 74 of MessageController.cs - line 43 is the call into the HandleSystemMessage method. It is used to send a greeting message to the user when they begin a conversation. Line 74 is the ReplyToActivityAsync call:

else if (message.Type == ActivityTypes.ConversationUpdate)
{
	if (message.MembersAdded.Any(m => m.Id == message.Recipient.Id))
	{
		var connector = new ConnectorClient(new Uri(message.ServiceUrl));
		var greetings = message.CreateReply(ChatBotMessages.MessageController_WelcomeMessage);
		await connector.Conversations.ReplyToActivityAsync(greetings);
	}
}

Configuring a web chat client with the necessary token to interact with the chat bot doesn't produce any results, not even debugging output when chatbotDebug is set to true. However looking at the network tab on Chrome's debugger shows that it does appear to authenticate successfully, as this response is received from the direct line service after loading the web chat:

{
  "conversationId": "LHVYPQBkQkN7hRLD55dnio",
  "token": "0lON9PMm2ok.dAA.TABIAFYAWQBQAFEAQgBrAFEAawBOADcAaABSAEwARAA1ADUAZABuAGkAbwA.sF24396F0gE.gkGjcqW0l_0.S1s-MCejzQ1R1O7JdrPSBKs05SCCDs06cQ4ZiHFwdE8",
  "expires_in": 1800,
  "streamUrl": "v3/directline/conversations/LHVYPQBkQkN7hRLD55dnio/stream?watermark=-&t=0lON9PMm2ok.dAA.TABIAFYAWQBQAFEAQgBrAFEAawBOADcAaABSAEwARAA1ADUAZABuAGkAbwA.sG-Z0tqF0gE.ZySE6ycE36I.W_rae95S24uhUIBcUr9ha0QjyLco7kx0k0YwTfiEjjE"
}

Let me know if there is anything else I can provide which could help. Thanks a lot.

@msft-shahins
Copy link
Contributor

@weedroid can you provide the MicrosoftAppId for your bot?

@weedroid
Copy link
Author

Hi @msft-shahins,

The MicrosoftAppId for my bot is bc0e84e1-29d0-4412-ba19-c3f7f74dffec

@weedroid
Copy link
Author

I'm now encountering the same issue with a bot hosted outwith Azure, whose framework I have upgraded from v3.5.2 to v3.5.3. After deploying the version with the upgraded framework, the bot fails with the "authorisation failed" exception in my first post. Restoring the previous version with framework v3.5.2 makes the bot work again. There have been no other substantial changes. Generating and using a new password has no effect.

@McGern
Copy link

McGern commented Feb 21, 2017

I am having the same issue. It seems that the credentials are being ignored when used in the web.config. With a simple solution (e.g. sandwichbot), if I have the credentials in the web.config and run it through the emulator (without credentials) it gives me an expected error of "Bot's MSA appid or password is incorrect". With the solution I am working on it does not do this, and instead starts the conversation even though the web.config has credentials and the emulator doesn't. If I put credentials into the emulator it does connect, but then gives 500 errors on any user input.

There is code in the global.asax file which is similar to the AlarmBot sample, which has this

        var builder = new ContainerBuilder();
        var config = GlobalConfiguration.Configuration;

        builder.RegisterType<RootDialog>().InstancePerDependency();
        builder.RegisterType<NameDialog>().InstancePerDependency();
        builder.RegisterType<AgeDialog>().InstancePerDependency();

        builder.RegisterApiControllers(Assembly.GetExecutingAssembly());
        builder.RegisterWebApiFilterProvider(config);

        builder.Update(Conversation.Container);

If this code is removed, the correct authorisation behaviour is seen (but subsequently breaks because dialog registration has not happened).

Also noticed while this is a similar setup to the AlarmBot sample, the sample doesn't have credentials in the web.config like the other samples do. Is this a coincidence or is there another means of authenticating the bot?

Thanks.

@thebeebs
Copy link

I'm seeing the same issue. On version 3.5.3

@nwhitmont nwhitmont added the C# label Apr 12, 2017
ignacy130 pushed a commit to ignacy130/Teamdare_SO that referenced this issue May 21, 2017
@nwhitmont
Copy link
Contributor

@weedroid Are you still experiencing the issue after upgrading to BotBuilder 3.8.1?

@GeraltTheWolf
Copy link

I'm using project type of ASP .Net Core 2.0 with target framework net461 and I get the same error that @weedroid mentioned above. Is there any solution to this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
No open projects
Development

No branches or pull requests

8 participants