Error on returning message from bot (Forbidden)
I am creating a bot on facebook and as per the logs I am having , The message is reaching the bot but when the bot is responding I am getting the below error
"System.UnauthorizedAccessException: Authorization for Microsoft App ID failed with status code Forbidden at Microsoft.Bot.Connector.JwtTokenRefresher.d__2.MoveNext()"
I tried on facebook/skype and it's the same error. I added message.From but still facing some issue. But the weird thing that from the emulator I am getting the error
" Microsoft.Rest.SerializationException: Unable to deserialize the response. ---> Newtonsoft.Json.JsonReaderException: Unexpected character encountered while parsing value: T. Path '', line 0, position 0."
I tested the connection from the bot framework and it gave me endpoint authorization succeed
Here is my message returning code.
Activity replyMessage = message.CreateReply(); replyMessage.Text = "Text"; replyMessage.TextFormat = "plain"; await connector.Conversations.SendToConversationAsync(replyMessage); var response = Request.CreateResponse(HttpStatusCode.OK); return response;
Have you tried reading through the authentication troubleshooting guide?
https://docs.botframework.com/en-us/support/troubleshooting-bot-framework-authentication/
Yes I did that , It's pretty confusing . This is my current status :
BotPortal : authorization succeeded
Emulator : Microsoft.Rest.SerializationException: Unable to deserialize the response. ---> Newtonsoft.Json.JsonReaderException: Unexpected character encountered while parsing value: T. Path '', line 0, position 0
Emulator with ngrok : System.UnauthorizedAccessException: Authorization for Microsoft App ID failed with status code unauthorized
facebook/skype : System.UnauthorizedAccessException: Authorization for Microsoft App ID failed with status code Forbidden
If step 2 doesn't succeed, then steps 3 and 4 won't succeed either. Do you have fiddler hooked up? What is the http response from the emulator that fails to deserialize?
You're correct , step 2 didnt succeed so I said I might have issues in my laptop so I went to step 3 directly . But step 3 succeeded. I attached the screenshots of fiddler. I am not sure where I can capture the response that failed to serialize , I am only getting the unable to serialize response.

Any update guys ?
I'm confused by your descriptions - for example, the bot portal would not be tested the same endpoint (generally a cloud endpoint) as the emulator (generally a localhost endpoint).
Yes I am using the emulator to test a local host url, I am just using the machine name instead because I am creating self signed certificate and it l, veripark is just a domain name.
still no update on any of related threads. I even get the same Unauthorized error for example in case of ConversationUpdate event for example:
Activated Event Time Duration Thread Exception: Exception thrown: 'System.UnauthorizedAccessException' in mscorlib.dll ("Authorization for Microsoft App ID 3d4d6c46-e2c9-4f41-8ef4-45c46936e98b failed with status code Unauthorized"). Exception thrown: 'System.UnauthorizedAccessException' in mscorlib.dll ("Authorization for Microsoft App ID 3d4d6c46-e2c9-4f41-8ef4-45c46936e98b failed with status code Unauthorized") 287.62s [18224] Worker Thread
The only code there is on evnet ConversationUpdate:
else if (activity.Type == ActivityTypes.ConversationUpdate) { ConnectorClient connector = new ConnectorClient(new Uri(activity.ServiceUrl)); Activity reply = activity.CreateReply(activity.From.Name); await connector.Conversations.ReplyToActivityAsync(reply); }
If I use the emulator with empty AppId and AppPassword, then it works fine.
Can you try calling MicrosoftAppCredentials.IsTrustedServiceUrl(activity.ServiceUrl) immediately before you call connector.Conversations.ReplyToActivity and see whether it returns true or false?

its True
That's very strange. Which channel are you sending this request to? I'll see if there's anything in the logs on my side.
I got it fixed in my side , the issue was that attribute [BotAuthentication] was commented because for testing i commented that to bypass the authentication . When I uncommented it , the authentication worked.
Its in skype channel,
Sent one message over Skype just now. See error in bot framewokr under SKype
05/09/2016, 23:44:20 There was an error sending this message to your bot: InternalServerError
hmm, thanks for the tip @Mazenx , but I have [BotAuthentication] in the beginning of my Controller calss already. Doesnt seem to help for now
@liiver, it looks like your outbound request is missing its Authorization header. @msft-shahins, do you have any ideas why this would be the case? IsTrustedServiceUrl is returning true. I'm not sure why it would be missing.
but why isnt it there then?
@liiver are you sure that you are not missing MicrosoftAppPasswrod from your web.config? Also test if using MicrosoftAppId and password you can talk to your bot using emulator.
@msft-shahins OMG, I had MicrosoftAppPassword there as MicrosoftAppSecret instead (facepalm) Probably from some times of BotConnecter 1.0.0. Embarrasing stuff. Thanks.
@liiver closing this issue. Assuming that this is resolved now. Feel free to open another issue if you are still having this problem.