question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[BUG] DefaultAzureCredential takes a long time to authenticate

See original GitHub issue

Library name and version

Azure.Identity 1.5.0

Describe the bug

Using DefaultAzureCredential for authentication takes a very long time in package version 1.5.0. The following code snippet takes ~3.5 seconds to run with Azure.Identity v1.4.0, and ~12.5 seconds with Azure.Identity v1.5.0.

var cred = new DefaultAzureCredential();
var result = cred.GetTokenAsync(new TokenRequestContext(new string[] { "<ValidScope>" })).Result;

Expected behavior

DefaultAzureCredential should not take >12 seconds to load credentials.

Actual behavior

DefaultAzureCredential takes >12 seconds to load credentials.

Reproduction Steps

Create an ASP .NET Core app with Azure.Identity v1.5.0 dependency. Add the code snippet above and measure the time taken for GetTokenAsync to complete. I had VisualStudioCredentials configured for authentication. Directly using VisualStudioCredentials for auth has no delay.

Environment

Tried running on .net3.1, .net5 and .net6 - same behavior. Running in Visual Studio 2019.

dotnet --info: .NET SDK (reflecting any global.json): Version: 6.0.101 Commit: ef49f6213a

Runtime Environment: OS Name: Windows OS Version: 10.0.19044 OS Platform: Windows RID: win10-x64 Base Path: C:\Program Files\dotnet\sdk\6.0.101\

Host (useful for support): Version: 6.0.1 Commit: 3a25a7f1cc

.NET SDKs installed: 3.0.103 [C:\Program Files\dotnet\sdk] 3.1.416 [C:\Program Files\dotnet\sdk] 5.0.210 [C:\Program Files\dotnet\sdk] 5.0.403 [C:\Program Files\dotnet\sdk] 5.0.404 [C:\Program Files\dotnet\sdk] 6.0.101 [C:\Program Files\dotnet\sdk]

.NET runtimes installed: Microsoft.AspNetCore.App 3.0.3 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 3.1.22 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 5.0.12 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 5.0.13 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 6.0.1 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.NETCore.App 3.0.3 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 3.1.22 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 5.0.12 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 5.0.13 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 6.0.1 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.WindowsDesktop.App 3.0.3 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 3.1.22 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 5.0.12 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 5.0.13 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 6.0.1 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:18 (6 by maintainers)

github_iconTop GitHub Comments

4reactions
heldersousa-planetpaymentcommented, Aug 16, 2022

@christothes is there an update for this issue? Version 1.6.1 still has this problem.

3reactions
christothescommented, Jan 27, 2022

Looks like the delay comes from ManagedIdentityCredential, as discussed in the other issue you linked. But this is still a significant delay compared to 1.4.0. Is there any plan to refactor DefaultAzureCredential to reduce the extra time taken by ManagedIdentityCredential?

Yes - we have been discussing solutions to this problem and may have a preview of the change soon. cc @schaabs

Read more comments on GitHub >

github_iconTop Results From Across the Web

Speeding up DefaultAzureCredential authentication in ...
However, when working in a local development environment, you might have noticed that DefaultAzureCredential can take up to 10 seconds to ...
Read more >
Azure Identity client library for .NET
Environment - The DefaultAzureCredential will read account information specified via environment variables and use it to authenticate. · Workload ...
Read more >
not able to fetch token using DefaultAzureCredential and ...
I am using Azure.Identity 1.7 and using VS 2022 , trying to get the token using DefaultAzureCredential, var tokenCredential = new ...
Read more >
DefaultAzureCredential().GetTokenAsync fails when using ...
The DefaultAzureCredential attempts to authenticate via the following mechanisms in order. In your local machine, it might be able to get ...
Read more >
Azure Identity client library for .NET - Microsoft .NET
The DefaultAzureCredential will first attempt to authenticate using credentials provided in the environment. In a development environment you can authenticate ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found