microsoft / botbuilder-dotnet

Welcome to the Bot Framework SDK for .NET repository, which is the home for the libraries and packages that enable developers to build sophisticated bot applications using .NET.
https://github.com/Microsoft/botframework
MIT License
872 stars 480 forks source link

MultiCredentialProvider to authenticate multiple MicrosoftAppId and MicrosoftAppPassword in SDK V4 Enterpise Bot Template #1253

Closed sw-ms-roshanparmar closed 5 years ago

sw-ms-roshanparmar commented 5 years ago

Is your feature request related to a problem? Please describe. I need to use same bot solution for different bots. This is possible in bot builder SDK V3. However, I guess it is not implemented in Bot Builder SDK V4.0 C# . I am currently using enterprise bot template to develop my bot.

Describe the solution you'd like Easily add multiple app id and passwords, so single solution can work for more than one bot. This is helpful when there is a scenario when we need to use same bot for different facebook pages.

If this is already implemented already can you guide me how to use it as I do not find any example.

EricDahlvang commented 5 years ago

Hi @sw-ms-roshanparmar

You can still use a custom ICredentialProvider in Bot Builder V4.0:

    public class MultiCredentialProvider : ICredentialProvider
    {
        public Dictionary<string, string> Credentials = new Dictionary<string, string>
        {
            { "YOUR_MSAPP_ID_1", "YOUR_MSAPP_PASSWORD_1" },
            { "YOUR_MSAPP_ID_2", "YOUR_MSAPP_PASSWORD_2" }
        };

        public Task<bool> IsValidAppIdAsync(string appId)
        {
            return Task.FromResult(this.Credentials.ContainsKey(appId));
        }

        public Task<string> GetAppPasswordAsync(string appId)
        {
            return Task.FromResult(this.Credentials.ContainsKey(appId) ? this.Credentials[appId] : null);
        }

        public Task<bool> IsAuthenticationDisabledAsync()
        {
            return Task.FromResult(!this.Credentials.Any());
        }
    }

Then, in Startup.cs replace the SimpleCredentialProvider when setting options.CredentialProvider:

// options.CredentialProvider = new SimpleCredentialProvider(endpointService.AppId, endpointService.AppPassword);
 options.CredentialProvider = new MultiCredentialProvider();
webdevelperify commented 4 years ago

Hi Eric,

How can I make my endpoint in Bot Framework v4 something like https://[domain].azurewebsites.net/api/message/appId so that I know which one to take appId and appSecret for the process.

Please can you look at this issue: https://stackoverflow.com/questions/60723115/can-we-customize-the-bot-endpoint-given-from-bot-framework-sdk-v4-net-core

Thank you in advance.