Hi Richard, you are now working on integrating Azure key vault into your .Net 8 application. So that we have to get the application authorized so that it could access Azure resource. In your code sample, it's using new DefaultAzureCredential()
to get authorization. For this method, you might refer to this section.
As you can see, credentials can be provided in many steps, setting environment variable is one of the options. You just need to add the required environment variable in windows system, then the
DefaultAzureCredential
method would do authorization task automatically. It firstly checks the environment variable, if failed, then goes into the next step.
If you prefer to use Azure Managed Identity to do the authorization, you can use codes below.
builder.Configuration.AddAzureKeyVault(
new Uri("https://vaultName.vault.azure.net/"),
new DefaultAzureCredential(
new DefaultAzureCredentialOptions { ManagedIdentityClientId = "userManagedIdentityClientId" }//required when using user ManagedIdentity
));
If you are working locally using Visual Studio, and you already used your Microsoft account signed in VS, it can also help do the authorization. I don't think you need to worry about security issue as the authorization occurs in the server side and it's controlled by SDK itself. You just need to choose the most suitable approach for your business.
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.
Best regards,
Tiny