botbuilder-dotnet: Unable to set MicrosoftAppPassword value in azure function V3

I’m trying to set MicrosoftAppPassword in azure function but no success.

I have created ConfigurationCredentialProvider class and inlcuded in Startup.cs

internal class ConfigurationCredentialProvider : SimpleCredentialProvider
    {        
        public ConfigurationCredentialProvider(IConfiguration configuration)
        {
            this.Password = "App password here";
        }
    }
public class Startup : FunctionsStartup
    {
        public override void Configure(IFunctionsHostBuilder builder)
        {
            var config = new ConfigurationBuilder()
                .AddEnvironmentVariables()
                .Build();


            // Set up the dependency injection container
            var serviceCollection = builder.Services;

            serviceCollection.AddSingleton<ICredentialProvider, ConfigurationCredentialProvider>();
        }
    }

I always get this exception Exception while executing function: BotMessagesHandler <--- Value cannot be null. (Parameter 'clientSecret')

If i add key ‘MicrosoftAppPassword’ in local.settings.json then Bot automatically pick app password from json

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 21 (2 by maintainers)

Most upvoted comments

Hello @atifgk!

I just found your code and see what is going on here. You are using AdapterWithErrorHandler which does not receive an ICredentialProvider in the constructor. So even if you are registering your ConfigurationCredentialProvider in your startup, it will never picked up by any class because no class that you are using expects a ICredentialProvider constructor parameter.

The solution is to modify your AdapterWithErrorHandler to receive the ICredentialProvider and pass it to the base class during constructor. This sample implements an AdapterWithErrorHandler that does exactly that. It is not in a functions environment, but the only thing you should take from it is adding the ICredentialProvider parameter to your AdapterWithErrorHandler constructor and then call : base(credentialProvider).

On a separate note, the Bot Framework SDK already has a ConfigurationCredentialProvider class, so I’d suggest you create a new class with a name such as KeyVaultCredentialProvider for your custom provider. Also consider if you need to inherit from SimpleCredentialProvider like you did in the snippet above. If you do not need anything from that class, I’d have your KeyVaultCredentialProvider directly implement the interface ICredentialProvider.

Please let me know if that doesn’t work or if you have questions. I’m very sorry that you had to wait a bit to get this resolved, hopefully we can make it up to you in the future. Also I’m glad you are using functions, I think they are a great way to hosting bots.