NuGet marks Microsoft.IdentityModel.Clients.ActiveDirectory as legacy and points to Microsoft.Identity.Client
Your error
Please note, a newer package is available Microsoft.Identity.Client. This package will continue to receive critical bug fixes until December 2022, we strongly encourage you to upgrade.1 more line it can showFix it fast
Most common cause, 1 of 2Your own code acquires tokens with ADAL's AuthenticationContext
Remove the ADAL package, add Microsoft.Identity.Client, and build one IConfidentialClientApplication for the whole process.
dotnet remove package Microsoft.IdentityModel.Clients.ActiveDirectory
dotnet add package Microsoft.Identity.Client
// created once, kept for the life of the app
IConfidentialClientApplication app = ConfidentialClientApplicationBuilder.Create(clientId)
.WithCertificate(certificate)
.WithAuthority($"https://login.microsoftonline.com/{tenantId}")
.Build();
AuthenticationResult result = await app
.AcquireTokenForClient(new[] { $"{resourceId}/.default" })
.ExecuteAsync();Short answer
NuGet flags Microsoft.IdentityModel.Clients.ActiveDirectory (ADAL.NET) as deprecated and names Microsoft.Identity.Client (MSAL.NET) as the replacement; ADAL gets no further fixes, security ones included. Either your code builds an AuthenticationContext, or a retired Azure package such as Microsoft.Azure.Services.AppAuthentication drags ADAL in. List deprecated packages with transitive ones included, then rewrite the token call or swap that root package.
Which cause do you have?
Ask NuGet which deprecated packages the project resolves, including the ones that come in through other packages. Then trace ADAL back to the package that requests it. On a .NET 9 SDK or older, use the verb-first form dotnet list package with the same options.
dotnet package list --deprecated --include-transitive
dotnet nuget why MyApp.csproj Microsoft.IdentityModel.Clients.ActiveDirectoryThen find the line you see in this list and open its fix:
- 1Your own code acquires tokens with ADAL's AuthenticationContext
dotnet nuget why shows the project itself as the top of the chain, and the source contains new AuthenticationContext( - 2An older Azure SDK package brings ADAL in as a dependency
dotnet nuget why traces ADAL to Microsoft.Azure.Services.AppAuthentication, Microsoft.Azure.KeyVault, a Microsoft.Azure.Management.* package or Microsoft.Kusto.Client
What does the error look like?
Please note, a newer package is available Microsoft.Identity.Client. This package will continue to receive critical bug fixes until December 2022, we strongly encourage you to upgrade.Please note, this package is obsolete as of 3/31/2023 and is no longer maintained or monitored. Microsoft encourages you to upgrade to the replacement package, Azure.Identity
Cause 1 of 2
Your own code acquires tokens with ADAL's AuthenticationContext
You seedotnet nuget why shows the project itself as the top of the chain, and the source contains new AuthenticationContext(
Check
The project asks NuGet for ADAL directly, so the deprecation warning will stay until that code moves. Microsoft's migration guide says ADAL receives no new features or bug fixes, security fixes included, although existing apps keep working. In a confidential client the giveaway is AuthenticationContext.AcquireTokenAsync called with a resource ID and a client credential or certificate.
grep -rn "AuthenticationContext\|AcquireTokenAsync" --include=*.cs .Fix
Remove the ADAL package, add Microsoft.Identity.Client, and build one IConfidentialClientApplication for the whole process. MSAL takes scopes rather than a resource, and for code that ran under ADAL the scope is the old resource ID followed by /.default.
dotnet remove package Microsoft.IdentityModel.Clients.ActiveDirectory
dotnet add package Microsoft.Identity.Client
// created once, kept for the life of the app
IConfidentialClientApplication app = ConfidentialClientApplicationBuilder.Create(clientId)
.WithCertificate(certificate)
.WithAuthority($"https://login.microsoftonline.com/{tenantId}")
.Build();
AuthenticationResult result = await app
.AcquireTokenForClient(new[] { $"{resourceId}/.default" })
.ExecuteAsync();Verify
The project builds, the deprecated list no longer shows ADAL, and the call returns a token the target API accepts.
dotnet package list --deprecated --include-transitiveConfirmed by learn.microsoft.com
Cause 2 of 2
An older Azure SDK package brings ADAL in as a dependency
You seedotnet nuget why traces ADAL to Microsoft.Azure.Services.AppAuthentication, Microsoft.Azure.KeyVault, a Microsoft.Azure.Management.* package or Microsoft.Kusto.Client
Check
ADAL can arrive without any direct reference. Microsoft's ADAL migration page calls it a transitive dependency your app cannot patch, and lists the usual root packages with their current replacements: Azure.Identity for AppAuthentication, the Azure.Security.KeyVault.* packages for Microsoft.Azure.KeyVault, and Azure.ResourceManager.* for the management libraries.
Fix
Replace the root package, not ADAL. For AppAuthentication plus Key Vault that means DefaultAzureCredential from Azure.Identity and the new SecretClient. Code that only needs a raw token asks the credential for one with a /.default scope.
dotnet remove package Microsoft.Azure.Services.AppAuthentication
dotnet remove package Microsoft.Azure.KeyVault
dotnet add package Azure.Identity
dotnet add package Azure.Security.KeyVault.Secrets
var client = new SecretClient(new Uri("https://my-vault.vault.azure.net"), new DefaultAzureCredential());
KeyVaultSecret secret = await client.GetSecretAsync("my-secret");
// a bare access token for another resource
var token = await new DefaultAzureCredential().GetTokenAsync(
new TokenRequestContext(new[] { resourceId + "/.default" }));Verify
dotnet nuget why reports that nothing depends on ADAL any more, and the app still reads the secret in each environment it runs in.
dotnet nuget why MyApp.csproj Microsoft.IdentityModel.Clients.ActiveDirectoryConfirmed by learn.microsoft.com
How do I stop it coming back?
- Run dotnet package list --deprecated --include-transitive in CI and fail the build when an identity package appears in it.
- Keep a single IConfidentialClientApplication or credential instance per process, so MSAL's token cache is reused between calls.
- When you move an AppAuthentication app to DefaultAzureCredential, test it in each hosting environment, since the two try their sign-in methods in a different order.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Projects of mine on the same stack: Raheeb, Loade Driver, Dhero.