While working with Azure services, especially with Managed Identities, we often rely on DefaultAzureCredential()Ā for seamless authentication.
Managed Identities, however, work only with services deployed on Azure, so when we're developing locallyĀ (like in Visual Studio), we typically fall back on Service PrincipalsĀ with a ClientIdĀ and ClientSecret.
Sensitive informationĀ like the ClientSecret often ends up in config files (appsettings, web.config) to make local development work.
However, you can completely go password-less on your local development boxes too!
Follow these simple steps to make it happen:
Close Visual Studio
Open PowerShellĀ and run az loginĀ (install the az modules if needed).
A browser window will pop up, prompting you to sign in with your Azure account credentials. Once signed in, close the PowerShell window.
Reopen Visual Studio and ensure youāre logged in with the same account used for Azure subscription (check the top right corner to confirm).
Go to ToolsĀ ā OptionsĀ ā Azure Service AuthenticationĀ ā Account Selection. Add your Microsoft accountĀ and sign in with your Azure account.
Thatās it!Ā Youāre now all set for local development and debugging without storing any sensitive credentials.
Hereās a sample code snippetĀ for reference integrating with Azure Key Vault (AKV):
Just the AKV URLĀ and secret nameĀ are required, same as when deploying to Azure.
Make sure you are on the Access ReviewĀ list with the right permissions for the AKV resource.
Hope this was useful.
Comments