Search code examples
botframeworkmicrosoft-teams

Teams Bot - get credentials from Key Vault


I have searched a bit but didn't found something which is helping me. I created a bot for teams and like described in all examples I am using the appsettings.json to store the ID and the password for the bot (MicrosoftAppId and MicrosoftAppPassword). These are both handled by the framework somehow. But now I want to use an Azure Key Vault to store the secret instead of having the appsettings file.

So I found some examples explaining how to do this in BotFramework V3 with BotAuthentication Attribute and even something for BotFramework V4 here (working link for the linked example here). But even that example is old and does not exist anymore like that.

How am I supposed to do this for a teams bot and c# dotnet 3.1?


Solution

  • You can use the following method to store the secret value

            var storageSecretValue = keyVaultClient.GetSecretAsync($"{this.configuration.GetSection("KeyVault")["BaseURL"]}{this.configuration["KeyVaultStrings:StorageConnection"]}");
    

    please refer the following sample document to more clarification:- https://github.com/OfficeDev/microsoft-teams-apps-newemployeeonboarding/blob/main/Source/Microsoft.Teams.Apps.NewHireOnboarding/Startup.cs

    https://learn.microsoft.com/en-us/samples/azure-samples/key-vault-dotnet-core-quickstart/get-started-keyvault-net/