I'm implementing AAD authentication on a Net5 API with the new library Micorosft.Identity.Web
The library exposes a method that only accepts an IConfiguration
with a section that looks like below in the app.settings
Authentication method from Micorosft.Identity.Web
on Startup.cs
public void ConfigureServices(IServiceCollection services)
{
...
services.AddMicrosoftIdentityWebApiAuthentication(Configuration, "AzureAd");
...
}
app.settings.json
"AzureAd": {
"Domain": "contoso.com",
"Instance": "https://login.microsoftonline.com/",
"TenantId": "00000000-0000-0000-0000-000000000000",
"ClientId": "00000000-0000-0000-0000-000000000000"
},
Now, the problem is, I'm using Azure to deploy this API, and of course all of this sensitive values are stored in Key Vault. So, I want to find a way of doing this:
services.AddMicrosoftIdentityWebApiAuthentication(new Configuration {
Domain = KeyVaultClient.GetSecret("domain"),
Instance = KeyVaultClient.GetSecret("instance")
TenantId = KeyVaultClient.GetSecret("tenant")
ClientId = KeyVaultClient.GetSecret("client")
});
And at the same time, I don't find a way of creating this 'section' at a KeyVault so I'm able of doing this
services.AddMicrosoftIdentityWebApiAuthentication(KeyVaultClient.GetSecret("azureadconfig"));
How can I archive one of these options, or how can I avoid depending on the app.settings if I have all my values on Key Vault
EDIT NOTE
I have the Key Vault as a Configuration Provider, but I don't know how to return those values in a Section way, as the methods is expecting