I have an ASP.NET Core application that is using WSFederation as authentication protocol. The application authenticates through our internal ADFS server where a corresponding Relying Party is configured. When attempting to authenticate, the ASP.NET Core application returns the following error message:
SecurityTokenException: No token validator was found for the given token.
Here is the full error page:
I had a look at the application configuration, but everything looked fine there:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
services.AddAuthentication(options => | |
{ | |
options.DefaultScheme = CookieAuthenticationDefaults.AuthenticationScheme; | |
options.DefaultSignInScheme = CookieAuthenticationDefaults.AuthenticationScheme; | |
options.DefaultChallengeScheme = WsFederationDefaults.AuthenticationScheme; | |
}) | |
.AddWsFederation(options => | |
{ | |
options.Wtrealm = "https://exampleapp"; | |
options.MetadataAddress = "https://adfs.example.be/federationmetadata/2007-06/federationmetadata.xml"; | |
}) | |
.AddCookie(); |
The issue turned out to be related to the Relying Party configuration in ADFS. I had enabled token encryption there but this is not supported by the WSFederation middleware in ASP.NET Core.
Here is how to fix it:
- Go to your ADFS server
- Open ADFS Management
- Go to Relying Parties and click on the Relying Party you want to configure
- Go to the Encryption tab and click Remove to delete the existing certificate