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

Authorization for Microsoft App ID failed with status code Forbidden

Open dynamicdeploy opened this issue 10 years ago • 5 comments

Hello!

I have built a bot that works great in Slack, Skype, Facebooks, etc.. The name of the bot is meelo Now I am trying to send a proactive message to the Slack channel and I get the following error "Authorization for Microsoft App ID xxxxxxx failed with status code Forbidden"

Here is the code. Am I doing something wrong?

class Program { static void Main(string[] args) { try { string appdId = ConfigurationManager.AppSettings["MicrosoftAppId"]; string appPassword = ConfigurationManager.AppSettings["MicrosoftAppPassword"]; string baseUri = ConfigurationManager.AppSettings["ConnectorClientBaseUri"];

            var client = new ConnectorClient(new Uri(baseUri), appdId, appPassword);

            //https://slack.botframework.com

                     
          
            Activity a = new Activity()
            {
                Type = ActivityTypes.Message,
                ChannelId = "slack",
                From = new ChannelAccount()
                {
                    Id = "xxxxxxx:T2CUWNSAY",
                    Name = "meelo"
                },
                Recipient = new ChannelAccount()
                {
                    Id = "xx:xxxxx",
                    Name = "tredkar"

                },
                ServiceUrl = "https://slack.botframework.com",
                Text = "Look at this!"

            };
          

            var c = client.Conversations.CreateDirectConversation(

                new ChannelAccount()
                {
                    Id = "xxxx",
                    Name = "meelo"
                },
                 new ChannelAccount()
                 {
                     Id = "xxxx:xxxxx",
                     Name = "xxxx"

                 }, a);

dynamicdeploy avatar Nov 24 '16 03:11 dynamicdeploy

@dynamicdeploy MicrosoftAppCredentials only sets the JwtToken of the bot for the post requests to trusted host names. For regular incoming messages to bot, BotAuthenticator adds the service urls to the trusted set if the incoming request to bot is authenticated.

For proactive messages, your implementation needs to add the service url to the set of trusted host names using the TrustServiceUrl, if the call to connector happens in a process that haven't seen the incoming request. For example, the ResumeAsync(...) implementation shows how bot builder trusts the service url if resumption context has the IsTrustedServiceUrl flag set to true: https://github.com/Microsoft/BotBuilder/blob/db2b8f860a3d8f7744a378930f93c4b0baa97978/CSharp/Library/Microsoft.Bot.Builder/ConnectorEx/LocaleFinder.cs#L46

msft-shahins avatar Nov 28 '16 23:11 msft-shahins

All links are dead ...

ghost avatar Feb 24 '17 11:02 ghost

Please update the links :-1:

J4S0Nc avatar Mar 27 '17 14:03 J4S0Nc

links updated!

msft-shahins avatar Aug 07 '17 23:08 msft-shahins

@J4S0Nc You are commenting on a closed issue.

If you have a question or problem, please open a new issue.

nwhitmont avatar Aug 07 '17 23:08 nwhitmont