Created
May 9, 2023 11:07
-
-
Save jeroensmink98/26772ea1f86785fcf0fd1253cff197eb to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var keyVaultName = builder.Configuration["KeyVaultName"]; | |
var azureADDirectoryId = builder.Configuration["AzureADDirectoryId"]; | |
var azureADApplicationId = builder.Configuration["AzureADApplicationId"]; | |
var azureADCertThumbprint = builder.Configuration["AzureADCertThumbprint"]; | |
builder.Host.ConfigureAppConfiguration((hostingContext, config) => | |
{ | |
using (var x509Store = new X509Store(StoreLocation.CurrentUser)) | |
{ | |
x509Store.Open(OpenFlags.ReadOnly); | |
// Retrieve a collection of X.509 certificates from an X.509 certificate store | |
var x509Certificate = x509Store.Certificates | |
.Find( | |
X509FindType.FindByThumbprint, | |
azureADCertThumbprint, | |
validOnly: false) | |
.OfType<X509Certificate2>() | |
.Single(); | |
var clientCertificateCredential = new ClientCertificateCredential( | |
azureADDirectoryId, | |
azureADApplicationId, | |
x509Certificate); | |
config.AddAzureKeyVault( | |
$"https://{keyVaultName}.vault.azure.net/" | |
); | |
} | |
}); | |
var app = builder.Build(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment