question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Unable to set MicrosoftAppPassword value in azure function V3

See original GitHub issue

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

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:21 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
carlosscastrocommented, Jan 5, 2021

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.

0reactions
atifgkcommented, Jan 29, 2021

@carlosscastro @dmvtech thanks. implenting !CredentialProvider worked

internal class ConfigurationCredentialProvider : ICredentialProvider
    {
        public Task<bool> IsValidAppIdAsync(string appId)
        {
            return Task.Run(() => true);
        }

        public Task<string> GetAppPasswordAsync(string appId)
        {
            return Task.Run(() => _"App passowrd"));
        }

        public Task<bool> IsAuthenticationDisabledAsync()
        {
            return Task.Run(() => false);
        }

    }
Read more comments on GitHub >

github_iconTop Results From Across the Web

Troubleshooting Bot Framework Authentication - Bot Service
Learn how to troubleshoot bot authentication errors, such as connectivity issues and problems with app IDs and passwords.
Read more >
Getting error "Failed to decrypt settings..." when trying to ...
We have a bot endpoint implemented as an Azure function and it's running fine within Azure. We've followed this process to enable us...
Read more >
Can't create v3 Function project - Developer Community
Go back to creating a new project but select Azure Functions v2. The message 'Making sure all templates are up to date...' shows....
Read more >
Unauthorized: Logon failed due to server configuration. " I can ...
Azure functions app keeps returning 401 unauthorized. all" permission. ... Solution 3: Delete & Create new App Registration When trying to hit the...
Read more >
Azure Function Alert on Failure: A Comprehensive guide
Are you missing out on notifications when there is an Azure Function failure? Read our detailed guide on how to create an alert...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found