I have a C# application which needs access to Azure to run, While running locally I do "az login" first and run the application.
But while running the same application as windows service this doesn’t work even thought I do "az login" before running the service.
- Visual Studio Token provider can't be accessed at C:Windowssystem32configsystemprofileAppDataLocal.IdentityServiceAzureServiceAuthtokenprovider.json
- Stored credentials not found. Need to authenticate user in VSCode Azure Account. See the troubleshooting guide for more information. https://aka.ms/azsdk/net/identity/vscodecredential/troubleshoot
- Please run 'az login' to set up account
- PowerShell is not installed.
---> System.AggregateException: Multiple exceptions were encountered while attempting to authenticate. (EnvironmentCredential authentication unavailable. Environment variables are not fully configured. See the troubleshooting guide for more information. https://aka.ms/azsdk/net/identity/environmentcredential/troubleshoot) (ManagedIdentityCredential authentication unavailable. The requested identity has not been assigned to this resource.
Status: 400 (Bad Request)
This is the error I get in Event listener.
So is there any way to login to azure while running application as windows service.
2
Answers
I was trying to make Windows service on Azure windows VM.
I was able to login to azure in service by doing this.
At first it was log on as local system account.
I changed it to This account and provided with My Bastion credentials for VM.
Then the service was able to login to azure successfully.
As mentioned in this GitHub Article of Troubleshooting
EnvironmentCredential
authentication issues Section, the mitigation is you need to create the app registration with your app service (windows service) deployed in Azure and login to the Azure before running the service with the cmdlet that contains service principal given in this MS Doc of Azure CLI Login with Service Principal.For this issue, when you’re logged in to Azure in the VS Code, make sure all the settings are syncing. Sync should be turn on from VS Code IDE as shown in the below screenshot:
Try Signing in with Command Palette (Ctrl + Shift + P) > Sign in to the Azure > and then Turn on the Settings Sync from the VS Code Accounts Option.