{"action":"created","issue":{"url":"https://api.github.com/repos/Microsoft/BotBuilder/issues/2258","repository_url":"https://api.github.com/repos/Microsoft/BotBuilder","labels_url":"https://api.github.com/repos/Microsoft/BotBuilder/issues/2258/labels{/name}","comments_url":"https://api.github.com/repos/Microsoft/BotBuilder/issues/2258/comments","events_url":"https://api.github.com/repos/Microsoft/BotBuilder/issues/2258/events","html_url":"https://github.com/Microsoft/BotBuilder/issues/2258","id":207529367,"node_id":"MDU6SXNzdWUyMDc1MjkzNjc=","number":2258,"title":"Conversation.SendAsync Authentication using custom multi-tenant authentication  (Bot Builder 3.5.2)","user":{"login":"JamesSkladnowski","id":13356699,"node_id":"MDQ6VXNlcjEzMzU2Njk5","avatar_url":"https://avatars2.githubusercontent.com/u/13356699?v=4","gravatar_id":"","url":"https://api.github.com/users/JamesSkladnowski","html_url":"https://github.com/JamesSkladnowski","followers_url":"https://api.github.com/users/JamesSkladnowski/followers","following_url":"https://api.github.com/users/JamesSkladnowski/following{/other_user}","gists_url":"https://api.github.com/users/JamesSkladnowski/gists{/gist_id}","starred_url":"https://api.github.com/users/JamesSkladnowski/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/JamesSkladnowski/subscriptions","organizations_url":"https://api.github.com/users/JamesSkladnowski/orgs","repos_url":"https://api.github.com/users/JamesSkladnowski/repos","events_url":"https://api.github.com/users/JamesSkladnowski/events{/privacy}","received_events_url":"https://api.github.com/users/JamesSkladnowski/received_events","type":"User","site_admin":false},"labels":[{"id":429202671,"node_id":"MDU6TGFiZWw0MjkyMDI2NzE=","url":"https://api.github.com/repos/Microsoft/BotBuilder/labels/.NET%20SDK","name":".NET SDK","color":"1d76db","default":false}],"state":"closed","locked":false,"assignee":{"login":"msft-shahins","id":17562300,"node_id":"MDQ6VXNlcjE3NTYyMzAw","avatar_url":"https://avatars2.githubusercontent.com/u/17562300?v=4","gravatar_id":"","url":"https://api.github.com/users/msft-shahins","html_url":"https://github.com/msft-shahins","followers_url":"https://api.github.com/users/msft-shahins/followers","following_url":"https://api.github.com/users/msft-shahins/following{/other_user}","gists_url":"https://api.github.com/users/msft-shahins/gists{/gist_id}","starred_url":"https://api.github.com/users/msft-shahins/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/msft-shahins/subscriptions","organizations_url":"https://api.github.com/users/msft-shahins/orgs","repos_url":"https://api.github.com/users/msft-shahins/repos","events_url":"https://api.github.com/users/msft-shahins/events{/privacy}","received_events_url":"https://api.github.com/users/msft-shahins/received_events","type":"User","site_admin":false},"assignees":[{"login":"msft-shahins","id":17562300,"node_id":"MDQ6VXNlcjE3NTYyMzAw","avatar_url":"https://avatars2.githubusercontent.com/u/17562300?v=4","gravatar_id":"","url":"https://api.github.com/users/msft-shahins","html_url":"https://github.com/msft-shahins","followers_url":"https://api.github.com/users/msft-shahins/followers","following_url":"https://api.github.com/users/msft-shahins/following{/other_user}","gists_url":"https://api.github.com/users/msft-shahins/gists{/gist_id}","starred_url":"https://api.github.com/users/msft-shahins/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/msft-shahins/subscriptions","organizations_url":"https://api.github.com/users/msft-shahins/orgs","repos_url":"https://api.github.com/users/msft-shahins/repos","events_url":"https://api.github.com/users/msft-shahins/events{/privacy}","received_events_url":"https://api.github.com/users/msft-shahins/received_events","type":"User","site_admin":false}],"milestone":null,"comments":6,"created_at":"2017-02-14T14:25:04Z","updated_at":"2018-10-26T15:37:16Z","closed_at":"2017-02-17T00:04:59Z","author_association":"NONE","body":"I am in the process of creating several different bots that will tie into Facebook Messager.   Each of these bots will have the potential to have 10-100 different Facebook pages connected to them.  This project was originally a POC, created on 3.0.0, that escalated into something much more very rapidly.\r\n\r\nSo far I have upgraded to 3.5.2, and fully implemented my own BotCredentialProvider from the ICredentialProvider interface.\r\nThis seems to work properly, granting me access to the my controller if the MicrosoftAppId exists and is authorized on our system.\r\n\r\nFrom this point we spool up a new Dialog and begin setting up the connector.  In a similar fashion to how BotCredentialProvider work, we instantiate a new MicrosoftAppCredentials class passing the MicrosoftAppId and MicrosoftAppPassword (NOT FROM THE WEB CONFIG).\r\n\r\nThese credentials are used in a new ConnectorClient like so\r\n```\r\nMicrosoftAppCredentials cred = new MicrosoftAppCredentials(appId: microsoftAppId, password: microsoftAppPassword);\r\nConnectorClient connector = new ConnectorClient(new Uri(activity.ServiceUrl), cred);\r\n```\r\nWe then get our StateClient from the activity and retrieve the BotData from the conversation.\r\n```\r\nStateClient stateClient = activity.GetStateClient(cred, activity.ServiceUrl);\r\nBotData botData = stateClient.BotState.GetConversationData(activity.ChannelId, activity.Conversation.Id);\r\n```\r\nThis all seems to work right and we are able to retrieve the information using the latest emulator.\r\n\r\nThe issue occurs on this line of code.\r\n` await Conversation.SendAsync(activity, CreateEnrollmentForm);`\r\nThis line of code seems to interact for a brief second with the emulator before returning an Unauthorized response.\r\n\r\nNote that before this I am able to successfully send a \"typing\" message to the bot using\r\n```\r\nActivity reply = activity.CreateReply();\r\nreply.Type = ActivityTypes.Typing;\r\nreply.Text = null;\r\nawait connector.Conversations.ReplyToActivityAsync(reply);\r\n```\r\n\r\nAm I doing something incorrectly?  There are no obvious ways of supplying credentials to the static class Conversation that I am aware of.   Is there another way to start off this process without using the static class?\r\n\r\nRestoring the MicrosoftAppId and MicrosoftAppPassword in the web config resolves the issue, however that is not a viable solution for us as this data will need to come from a database.\r\n\r\nAlso, is there any reason why the payload of the JWT token differs between using the emulator and  running on a server.  Most notably the presence of \"appid\" when using the emulator and having the appid be in the audience when called from a server.  One would think that this behavior would be the same.\r\n\r\nThank you,\r\n    James\r\n\r\n"},"comment":{"url":"https://api.github.com/repos/Microsoft/BotBuilder/issues/comments/433450343","html_url":"https://github.com/Microsoft/BotBuilder/issues/2258#issuecomment-433450343","issue_url":"https://api.github.com/repos/Microsoft/BotBuilder/issues/2258","id":433450343,"node_id":"MDEyOklzc3VlQ29tbWVudDQzMzQ1MDM0Mw==","user":{"login":"fercom","id":19654168,"node_id":"MDQ6VXNlcjE5NjU0MTY4","avatar_url":"https://avatars0.githubusercontent.com/u/19654168?v=4","gravatar_id":"","url":"https://api.github.com/users/fercom","html_url":"https://github.com/fercom","followers_url":"https://api.github.com/users/fercom/followers","following_url":"https://api.github.com/users/fercom/following{/other_user}","gists_url":"https://api.github.com/users/fercom/gists{/gist_id}","starred_url":"https://api.github.com/users/fercom/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/fercom/subscriptions","organizations_url":"https://api.github.com/users/fercom/orgs","repos_url":"https://api.github.com/users/fercom/repos","events_url":"https://api.github.com/users/fercom/events{/privacy}","received_events_url":"https://api.github.com/users/fercom/received_events","type":"User","site_admin":false},"created_at":"2018-10-26T15:37:16Z","updated_at":"2018-10-26T15:37:16Z","author_association":"NONE","body":"@msft-shahins Hi, would you tell me please how do I know the appId when I am on the dialog or the messages controller? to have a distinct action depending on the bot. Thanks!"}}
{"actor":{"display_login":"fercom"}}