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

System.UnauthorizedAccessException: Authorization for Microsoft App ID XXXX failed with status code Forbidden

Open rmatosaw opened this issue 10 years ago • 20 comments

Hi,

After migrate do V3, I have this message trying to send messages (in Telegram, Kik, Slack):

In Skype, Email and WebChat it is ok.

System.UnauthorizedAccessException: Authorization for Microsoft App ID XXXXXX failed with status code Forbidden at Microsoft.Bot.Connector.JwtTokenRefresher.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.d__6.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.d__13.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.SendToConversation(IConversations operations, Activity activity)

rmatosaw avatar Jul 14 '16 18:07 rmatosaw

Thank you for reporting. We're investigating this issue.

dandriscoll avatar Jul 14 '16 19:07 dandriscoll

Hi @rmatosaw, can you send your Bot ID or MSA App ID?

dandriscoll avatar Jul 14 '16 22:07 dandriscoll

Hi, dandriscoll. Here is the complete message.

In out scenario, sometimes we rebuild the conversation using the last conversationId. We did it some days after migrate to V3, but today we couldn't send messages (reply to messages) in Kik, Telegram, etc. Also, we have alerts is this channel: "Sorry, NOVIGO_OMNI is having a problem responding right now."

Thanks

System.UnauthorizedAccessException: Authorization for Microsoft App ID 803aa38b-996f-4e3c-b34f-d8c20ac20d8c failed with status code Forbidden at Microsoft.Bot.Connector.JwtTokenRefresher.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.d__6.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.d__13.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.SendToConversation(IConversations operations, Activity activity)

rmatosaw avatar Jul 15 '16 02:07 rmatosaw

Perfect -- thank you.

dandriscoll avatar Jul 15 '16 02:07 dandriscoll

Any ideas to solve or work around? Thanks

rmatosaw avatar Jul 15 '16 07:07 rmatosaw

Not yet, sorry. Still working on it.

dandriscoll avatar Jul 15 '16 17:07 dandriscoll

Hi dandriscoll. Do you think if I create a new robot I will have the same problem? sorry for my insistence. But some key channels for me are without work, and I have to deliver them next week. If so, I recreate it again on the Microsoft Bot (and keep the accounts of each Kik bot, Telegram, etc) and I re-apply for a new Bot.

rmatosaw avatar Jul 15 '16 22:07 rmatosaw

Hi, I still have this message. Working on V3 only in Skype and Office365.

Telegram, Slack, Kik: Sorry, NOVIGO_OMNI is having a problem responding right now. Skype: Calls to your bot are failing with: 500 InternalServerError

Please, what can I try?

Thanks

rmatosaw avatar Jul 19 '16 22:07 rmatosaw

We're still working on pinning this down. There's some revised code in our Telegram service -- are you still seeing the problem there?

dandriscoll avatar Jul 20 '16 05:07 dandriscoll

Hi dandriscoll. Thanks for your reply.

I just change my code (C #) to keep a dictionary the Activity and then use the method "ReplyToActivity" (in all scenarios for our implementation we will respond to messages asynchronously).

With this change, the situation of the channels looked like this:

  • Skype: running (responding normally) but the status on the dashboard continues with error 500.
  • Kik: respond normally, but the status on the dashboard continues with error.
  • Telegram: back to answer, while still showing in the app "Sorry, xxx is having a problem responding right now.". On the dashboard the status is "Error".

After this implementation, the error [System.UnauthorizedAccessException: Authorization for Microsoft App ID XXXX failed with status code Forbidden] apparently stopped to occur. This is apparently related to the recreation of the Conversation object (even though I was using the same previous ConversationId). Now, I am using the same activity object of the received message.

So in summary (sorry for the long message): the Telegram continues to indicate problems, and the dashboard continues to indicate errors (in Kik, Telegram, Skype), but Exception is no longer occurring.

Do you need any more information? Thanks for the support.

rmatosaw avatar Jul 20 '16 13:07 rmatosaw

That should get us started. Thanks!

dandriscoll avatar Jul 21 '16 15:07 dandriscoll

@dandriscoll I am facing same error in slack when I try to start a conversation with a user with following code:

ConnectorClient connector = new ConnectorClient(new Uri(incomingMessage.ServiceUrl));
            var ConversationId = await connector.Conversations.CreateDirectConversationAsync(incomingMessage.Recipient, incomingMessage.From);
            IMessageActivity message = Activity.CreateMessageActivity();
            message.Recipient = new ChannelAccount(id: "@userId", name: "username"); ;
            message.Conversation = new ConversationAccount(id: ConversationId.Id);
            message.Text = "Hello";
            message.Locale = "en-Us";
            return connector.Conversations.SendToConversation((Activity)message);

Any suggestions or work around?

niyatia avatar Jul 25 '16 22:07 niyatia

@niyatia try setting message.From to your botId message.From = new ChannelAccount { Id = "BotId", Name = "BotId" };

RaffaelHold avatar Jul 26 '16 05:07 RaffaelHold

@RaffaelHold I added the message.From but it still gives the same error. Just to clarify, we need to set both Id and Name, both as the BotId?

niyatia avatar Jul 26 '16 16:07 niyatia

@niyatia I'm sorry set the name as the bots name

RaffaelHold avatar Jul 26 '16 17:07 RaffaelHold

@RaffaelHold Thanks. that worked.

niyatia avatar Jul 26 '16 18:07 niyatia

I have updated to 3.1.0 version and still facing this bug

fercom avatar Aug 22 '16 20:08 fercom

Authorization for Microsoft App ID f196f57b-5b97-4653-aaac-d98824071ed1 failed with status code Unauthorized {Bot Framework V 3.5.1}

Updated bot builder sdk to V3.5.1 from V3.1.0

at Microsoft.Bot.Connector.JwtTokenRefresher.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.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task task) at Microsoft.Bot.Connector.Conversations.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.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 System.Runtime.CompilerServices.TaskAwaiter`1.GetResult() at Synechron.MortgageBot.MessagesController.d__0.MoveNext() in C:\Users\Anand.Chitale\MortgageBot\Synechron.MortgageBot\Synechron.MortgageBot\Controllers\MessagesController.cs:line 54

Works fine with version 3.1.0

AnandChitale avatar Jan 31 '17 06:01 AnandChitale

Hi @AnandChitale, can you open a new issue? This is likely a new problem.

dandriscoll avatar Jan 31 '17 16:01 dandriscoll

Done : https://github.com/Microsoft/BotBuilder/issues/2155

AnandChitale avatar Feb 01 '17 08:02 AnandChitale