Summary
This article provides guidance for troubleshooting an authentication issue that occurs in an ASP.NET MVC application that uses both WS-Federation OWIN middleware and Windows Identity Foundation (WIF) to authenticate to Microsoft Entra ID.
Symptoms
The ASP.NET MVC application that was previously working generates the following error message although no changes were made to the application:
Error Details:
Server Error in '/' Application.
WIF10201: No valid key mapping found for securityToken: 'System.IdentityModel.Tokens.X509SecurityToken' and issuer: 'https://sts.windows.net/<Directory ID>/'.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.IdentityModel.Tokens.SecurityTokenValidationException: WIF10201: No valid key mapping found for securityToken: 'System.IdentityModel.Tokens.X509SecurityToken' and issuer: 'https://sts.windows.net/<Directory ID>/'.
Cause
To validate the signature of the token that's returned by the Entra ID after a successful sign-in, WIF uses the certificate thumbprints that are in the Web.config file, as shown in the following example:
<issuerNameRegistry type="System.IdentityModel.Tokens.ValidatingIssuerNameRegistry,
System.IdentityModel.Tokens.ValidatingIssuerNameRegistry">
<authority name="https://sts.windows.net/<Directory ID>/">
<keys>
<add thumbprint="C142E..." />
<add thumbprint="8BA94..." />
<add thumbprint="D92E1..." />
</keys>
<validIssuers>
<add name="https://sts.windows.net/<Directory ID>/" />
</validIssuers>
</authority>
</issuerNameRegistry>
The "WIF10201" error occurs if none of these certificate thumbprints match the one that's used by Entra ID to sign the token.
The Entra ID uses a signing key rollover mechanism to update the certificate that's used to sign authentication tokens periodically. This key rollover causes the initial certificate thumbprints that are configured in the Web.config file to become invalid.
Solution
You can either manually update the certificate thumbprints that are in the Web.config file or automate the process through code. For more information, see Best practices for keys metadata caching and validation.
Source: Microsoft Learn / IT Pro troubleshooting by Microsoft and contributors (upstream author metadata: kaushika-msft). Documentation licensed CC BY 4.0. Code samples are covered by the MIT License. Converted from Markdown, with links normalized and embedded media omitted.
