botframework-sdk icon indicating copy to clipboard operation
botframework-sdk copied to clipboard

Authorization for Microsoft App ID ... failed with status code Forbidden

Open arminreiter opened this issue 10 years ago • 5 comments

hello,

I have the same issue as others. I get this error (facebook, skype, telegram) when I send a new message via: await connector.Conversations.SendToConversationAsync((Activity)activity);

I use the latest NuGet packages (Microsoft.Bot.Builder v 3.3.1)

I tried a few things and I found out, that it works as long as I don't redeploy my bot service. So I guess that it could be a session issue or something like that.

I tested the following things:

  • send messages from facebook, telegram and skype messenger to my bot.
  • send a message from my bot to all 3 messengers - worked
  • wait 5 minutes - send a message from my bot to all 3 messengers - worked
  • redeployed the bot service
  • send a message from my bot to all 3 messengers - error: Authorization for Microsoft App ID ... failed with status code Forbidden (for all 3 messengers)
  • send a message from facebook and skype to my bot
  • send a message from my bot to all 3 messengers - worked for facebook and skype
  • stopped and started my azure app service (which hosts the bot webservice)
  • send a message from my bot to all 3 messengers - error: Authorization for Microsoft App ID ... failed with status code Forbidden (for all 3 messengers).

Is it possible to persist the session data for the bot and reload it after a reset? thanks

arminreiter avatar Nov 12 '16 12:11 arminreiter

this issue is similar to: 1644

I also downgraded to 3.3.0 and it works.

arminreiter avatar Nov 14 '16 11:11 arminreiter

We are experiencing the same issue using the Twilio channel. Any updates on this?

stephenpgreen avatar Nov 14 '16 15:11 stephenpgreen

I have also experienced this issue where trying to send a message from my bot after a reset and before any incoming messages are received and it fails with the auth error as above, I have tried this using 3.3.1 and 3.3.2

This is also causing an issue in a standalone service fabric app which sends push messages to users as it fails to authenticate and create a connector as below.

var connector = new ConnectorClient(new Uri("https://facebook.botframework.com/"), "xxx" ,"yyy"); var conversationId = await connector.Conversations.CreateDirectConversationAsync(from, to);

But if we revert back to 3.3.0 they both work and we can create messages from both processes.

karlbarber avatar Nov 15 '16 12:11 karlbarber

Have you walked through the authentication troubleshooting guide?

https://docs.botframework.com/en-us/support/troubleshooting-bot-framework-authentication/#navtitle

Do you see any trace log messages regarding trusted service uris? We don't forward the Jwt token unless the service uri is trusted, right, @msft-shahins ?

willportnoy avatar Nov 28 '16 03:11 willportnoy

Connector client only sets the JwtToken for outgoing requests if the request uri is among the set of trusted host names: https://github.com/Microsoft/BotBuilder/blob/master/CSharp/Library/Microsoft.Bot.Connector/MicrosoftAppCredentials.cs#L97

If not, you will see the warning and your calls to connector service will fail with forbidden: https://github.com/Microsoft/BotBuilder/blob/master/CSharp/Library/Microsoft.Bot.Connector/MicrosoftAppCredentials.cs#L132

Service urls will be added to the set of trusted host names if the incoming request is authenticated by BotAuthentication: https://github.com/Microsoft/BotBuilder/blob/master/CSharp/Library/Microsoft.Bot.Connector/BotAuthentication.cs#L76. Currently trusted host names is maintained as an in-memory static cache and if you are sending the message proactively from a new node, e.g a newly deployed node or a webjob, or if in your architecture a different node is responsible for sending the reply message than the one that authenticated the incoming request, you are responsible for trusting that service url before sending the outgoing request. Just call MicrosoftAppCredentials.TrustServiceUrl if that service url is trusted before sending the outgoing/reply message.

For example, builder’s ResumptionCookie maintains a flag indicating if the service url is trusted or not: https://github.com/Microsoft/BotBuilder/blob/master/CSharp/Library/Dialogs/ResumptionCookie.cs#L70 and Conversation.Resume path automatically trust the service url if the flag is set: https://github.com/Microsoft/BotBuilder/blob/master/CSharp/Library/Dialogs/Conversation.cs#L95

This change might be the reason that you started seeing this in recent releases: https://github.com/Microsoft/BotBuilder/commit/45796b84#diff-31252589d90c1e9dd66ccad53adfbf2aL121. The HttpContext.Current == null has been intentionally removed to make sure that the JwtToken of the bot is not sent to a service url that is not trusted.

msft-shahins avatar Nov 30 '16 21:11 msft-shahins