[BUG] AzureServiceTokenProvider.GetAccessTokenAsync no longer works with Visual Studio 16.3
See original GitHub issueDescribe the bug
I work on a project that uses Azure Managed Identities. AzureServiceTokenProvider.GetAccessTokenAsync()
is used to get a token, and to debug locally a token provided by Visual Studio is used. After upgrading to Visual Studio 16.3 this no longer works. I have verified this to be the case on two different computers after upgrading to Visual Studio 16.3.
I don’t know if this is a problem with Visual Studio or the NuGet package but the exception is thrown by the NuGet package so I’m reporting it here.
Exception or Stack Trace
Parameters: Connection String: RunAs=Developer; DeveloperTool=VisualStudio, Resource: https://management.azure.com, Authority: . Exception Message: Tried to get token using Visual Studio. Access token could not be acquired. Exception for Visual Studio token provider Microsoft.Asal.TokenService.exe : Token response is not in the expected format. Exception Message: There was an error deserializing the object of type Microsoft.Azure.Services.AppAuthentication.TokenResponse. Encountered unexpected character ‘D’.
at Microsoft.Azure.Services.AppAuthentication.AzureServiceTokenProvider.<GetAuthResultAsyncImpl>d__14.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Runtime.CompilerServices.ConfiguredTaskAwaitable`1.ConfiguredTaskAwaiter.GetResult() at Microsoft.Azure.Services.AppAuthentication.AzureServiceTokenProvider.<GetAuthenticationResultAsync>d__18.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Runtime.CompilerServices.ConfiguredTaskAwaitable`1.ConfiguredTaskAwaiter.GetResult() at Microsoft.Azure.Services.AppAuthentication.AzureServiceTokenProvider.<GetAccessTokenAsync>d__16.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult() at UserQuery.<RunUserAuthoredQuery>d__0.MoveNext()
To Reproduce
Use Visual Studio 16.3 and configure an Azure account in Tools > Options > Azure Service Authentication > Account Selection.
Create a new instance of AzureServiceTokenProvider
with connection string "RunAs=Developer; DeveloperTool=VisualStudio"
and then call GetAccessTokenAsync("https://management.azure.com")
to get a token.
Code Snippet
var connectionString = "RunAs=Developer; DeveloperTool=VisualStudio";
var azureServiceTokenProvider = new AzureServiceTokenProvider(connectionString);
var token = await azureServiceTokenProvider.GetAccessTokenAsync("https://management.azure.com");
Expected behavior
GetAccessTokenAsync
should return a token that can be used to authenticate with Azure based on the configured account in Visual Studio and not throw an exception.
Screenshots
Setup (please complete the following information):
- OS: Windows 10 Pro 1903 18362.356
- IDE: Visual Studio 16.3.0
- Version of the Library used: Microsoft.Azure.Services.AppAuthentication 1.3.1
Additional context
None.
Information Checklist
Kindly make sure that you have added all the following information above and checkoff the required fields otherwise we will treat the issuer as an incomplete report
- Bug Description Added
- Repro Steps Added
- Setup information Added
Issue Analytics
- State:
- Created 4 years ago
- Reactions:1
- Comments:21 (4 by maintainers)
Top GitHub Comments
For me, the problem appeared after upgrading to Visual Studio 2019 16.4.0 from the previous version. I’ve found that this was caused by invalid TokenProvider path, so I was forced to change content of “%LOCALAPPDATA%.IdentityService\AzureServiceAuth\tokenprovider.json” file:
{ "TokenProviders": [ { "Path": "c:\\program files (x86)\\microsoft visual studio\\2019\\enterprise\\common7\\ide\\extensions\\1rzmhu0l.2xx\\TokenService\\Microsoft.Asal.TokenService.exe", "Arguments": [ "--serviceHubConfig", "\"C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Enterprise\\Common7\\servicehub.config.json\"" ], "Preference": 0 }, { "Path": "c:\\program files (x86)\\microsoft visual studio\\2019\\enterprise\\common7\\ide\\extensions\\qglq5p5b.btx\\TokenService\\Microsoft.Asal.TokenService.exe", "Arguments": [ "--serviceHubConfig", "\"C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Enterprise\\Common7\\servicehub.config.json\"" ], "Preference": 1 }, { "Path": "c:\\program files (x86)\\microsoft visual studio\\2019\\enterprise\\common7\\ide\\extensions\\4rin0bzc.yf5\\TokenService\\Microsoft.Asal.TokenService.exe", "Arguments": [ "--serviceHubConfig", "\"C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Enterprise\\Common7\\servicehub.config.json\"" ], "Preference": 2 } ] }
to only one valid entry (note a new extensions folder - “…\extensions\ys2aolp3.2rs”):
{ "TokenProviders": [ { "Path": "c:\\program files (x86)\\microsoft visual studio\\2019\\enterprise\\common7\\ide\\extensions\\ys2aolp3.2rs\\TokenService\\Microsoft.Asal.TokenService.exe", "Arguments": [ "--serviceHubConfig", "\"C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Enterprise\\Common7\\servicehub.config.json\"" ], "Preference": 0 } ] }
and then everything started to work again!
@Liversage awesome that actually makes this much easier to dive into. Let me see if I can get someone on the ASAL side of things to weigh in next week.