Azure Bot When debugging locally using ngrok for channel teams throws the following exception "Failed to acquire token for client credentials."

Viewed 224

System.AggregateException: 'Failed to acquire token for client credentials. (Parameters: Connection String: RunAs=App;AppId=bc107559-ff62-4f67-8dd4-0dce6a0fe426, Resource: https://api.botframework.com, Authority: . Exception Message: Tried to get token using Managed Service Identity. Unable to connect to the Instance Metadata Service (IMDS). Skipping request to the Managed Service Identity (MSI) token endpoint.)'

Inner Exception : AzureServiceTokenProviderException: Parameters: Connection String: RunAs=App;AppId=bc107559-ff62-4f67-8dd4-0dce6a0fe426, Resource: https://api.botframework.com, Authority: . Exception Message: Tried to get token using Managed Service Identity. Unable to connect to the Instance Metadata Service (IMDS). Skipping request to the Managed Service Identity (MSI) token endpoint.

The above Exception is throw when trying to send message to user or getting user details for ex:

  var messageText ="What can I help you with today?\nSay something like \"Book a flight from Paris to Berlin on March 22, 2020\"";
  var promptMessage = MessageFactory.Text(messageText, messageText, InputHints.ExpectingInput);
  return await stepContext.PromptAsync(nameof(TextPrompt), new PromptOptions { Prompt = promptMessage }, cancellationToken);

The exception is thrown in the 3rd line that is when trying to send the user a prompt message

2 Answers

User-Assigned Managed Identity (UAMI) bots cannot be tested outside Azure. The managed identity endpoints will only respond to requests originating from within Azure, likely for security reasons. As shown in the managed identity docs and in this github issue on the Azure SDK repo.

Your only option to test locally is to create a separate multi-tenant Azure Bot resource and use that to test your bot via ngrok. You don't need to create an App Service, just the bot.

Alternatively, you can always deploy the bot to Azure to test it.

You can try the following workarounds to resolve this issue:

  • Check Visual studio is running as administrator.
  • Checkbotframework.com whether bot is listed.
  • Users have the write to create apps in AD.

enter image description here

Also try the below steps:

  1. go to your bot in the Azure portal.
  2. select the 'Authentication' menu on the left panel.
  3. select 'Accounts in any organizational directory (Any Azure AD directory - Multitenant)' in the 'Supported account types' as below : image
Related