aspnetcore: Authentication.WsFederation breaks with on-premise AD FS use
Is there an existing issue for this?
- I have searched the existing issues
Describe the bug
Using Authentication.WsFederation for authentication results in error regardless of new UseSecurityTokenHandlers setting.
options.UseSecurityTokenHandlers = true;
SecurityTokenInvalidIssuerException: IDX10204: Unable to validate issuer. validationParameters.ValidIssuer is null or whitespace AND validationParameters.ValidIssuers is null or empty.
Expected: behavior prior to change introduced with issue 49469.
options.UseSecurityTokenHandlers = false;
XmlReadException: IDX30011: Unable to read XML. Expecting XmlReader to be at ns.element: ‘urn:oasis:names:tc:SAML:2.0:assertion.Assertion’, found: ‘urn:oasis:names:tc:SAML:1.0:assertion.Assertion’.
Expected: to be able to handle SAML 1.0 assertion emitted by WsFed server.
Expected Behavior
options.UseSecurityTokenHandlers = true;
Expected: behavior prior to change introduced with issue 49469.
options.UseSecurityTokenHandlers = false;
Expected: to be able to handle SAML 1.0 assertion emitted by WsFed server.
Steps To Reproduce
Repro project: https://github.com/csowa/aspdotnetcore-auth-sample
Demonstrates WS-Federation issue with change introduced for https://github.com/dotnet/aspnetcore/issues/49469
Based on example at https://learn.microsoft.com/en-us/aspnet/core/security/authentication/ws-federation?view=aspnetcore-8.0#use-ws-federation-without-aspnet-core-identity
Build and run. Home page uses [Authorize] attribute, authentication begins when loading.
Dependency: ADFS server required. Server version tested: 10.0.17763.4644
Exceptions (if any)
options.UseSecurityTokenHandlers = true;
SecurityTokenInvalidIssuerException: IDX10204: Unable to validate issuer. validationParameters.ValidIssuer is null or whitespace AND validationParameters.ValidIssuers is null or empty.
options.UseSecurityTokenHandlers = false;
XmlReadException: IDX30011: Unable to read XML. Expecting XmlReader to be at ns.element: ‘urn:oasis:names:tc:SAML:2.0:assertion.Assertion’, found: ‘urn:oasis:names:tc:SAML:1.0:assertion.Assertion’.
.NET Version
8.0.100
Anything else?
No response
About this issue
- Original URL
- State: open
- Created 3 years ago
- Reactions: 9
- Comments: 42 (13 by maintainers)
We have encountered this issue as well and implemented a workaround.
This may be an issue with a difference in how JsonWebTokenHandler and SamlSecurityTokenHandler handles configuration fetching from ConfigurationManager. I have reported this issue to Microsoft.IdentityModel here: https://github.com/AzureAD/azure-activedirectory-identitymodel-extensions-for-dotnet/issues/2406
The JsonWebTokenHandler fetches BaseConfiguration from the ConfigurationManager when validating a token, the Saml*SecurityTokenHandler does not. This change https://github.com/dotnet/aspnetcore/commit/a56e968c19be1275db6dc462310d723615b006a7#diff-42233637069e62d711d83e163c06bbf11849c4acb594daaf5587697c3ef0789fL99 changed configuration fetching so that this now is delegated to the TokenHandler when using the default ConfigurationManager or StaticConfigurationManager (inherits from BaseConfigurationManager). While this works for JsonWebTokenHandler, the SAML handlers is not compatible.
Had it fixed after replacing:
for:

Microsoft.AspNetCore.Authentication.WsFederation has not been updated to reference 7.4.1, which is the one that contains the fix. The latest version 8.0.4 still references to 7.1.2. Do you know if there is any plan to get that updated ? Thanks
@mkArtakMSFT This issue was specifically for Authentication.WsFederation breaking. Despite the fix to Microsoft.IdentityModel, Authentication.WsFederation still has not been updated to reference the fixed version, and thus the issue raised by this ticket still exists. This was closed prematurely.
Just hit this as well. This is a pretty big breaking change to be undocumented! And how come this has not been fixed? It completely breaks ADFS Integration.
Thanks for the workaround, @Hakon! It works great.
Thank you for the warning. I have submitted a fix to IdentityModel.
please re-open. this is still broken
I do not have really deep insight into this, but maybe this could be helpful for someone:
<PackageReference Include="Microsoft.IdentityModel.Tokens.Saml" Version="8.6.0" />and keepUseSecurityTokenHandlers=falseUnfortunately we aren’t able to take the dependency update in 8.0, as there is a known breaking change between 7.1.2 and 7.4.1 - https://github.com/AzureAD/azure-activedirectory-identitymodel-extensions-for-dotnet/issues/2513. If we were to take that update, then later realize that we’d broken even more people, it would be impossible for us to roll it back.
We realize that this isn’t a great state to be in, but we’re essentially stuck between a rock and a hard place on this one. I’m going to re-open this issue to track our ongoing work to improve the documentation for this one (to suggest adding a
PackageReferenceto user projects), which @halter73 is working on.@wtgodbe As I understand the problem, angle you missed in last message is that WsFederation package is almost completely broken without this update.
What do you mean with that ? If you reference the latest version for WSFederation, it includes the version 7.1.2 for Microsoft.IdentityModel that is broken. The only workaround is to go and manually reference the assembly with the latest version of the SamlHandler that fixes the issue.
It would appear that the 4th preview version for the package with net 9 has finally increased the minimum version to 7.4.1 (and a couple later bumped it again). I’d love if they could release a version with 8, but if you ever upgrade it should eventually be resolved.
Will next patch version of WsFederation depend on fixed versions of IdentityModel?
Closing as the updated packages from the Microsoft.IdentityModel.* version 7.4.1 have shipped now, which includes the fix.
@Hakon @OttoG @csowa @halter73 the workaround is great and can be used until we get the fix into IdentityModel. Please make sure to call TokenValidationParameters.Clone() before modifying and calling ValidateTokenAsync(…) as TokenValidationParameters can persist across http requests.
This is correct. It was not intended as a general fix for everyone but rather a hint at how to work around the problem. I am working on a proper fix in IdentityModel.
Thank you for your response. I am aware of the breaking change as described. Unfortunately, that is not the issue here.
I am attempting to use an ASP.NET Core component, and it breaks regardless of UseSecurityTokenHandlers setting. Please see the provided repro app.
I can confirm the issue noted above https://github.com/dotnet/aspnetcore/issues/52099#issuecomment-1816045784, and I can work around the initialization problem related to that which was introduced in the associated ASP.NET Core change to the WsFederation component.
While that initialization issue may have a root cause deeper in the architecture and in a separate project, the issue is exposed in a component from this project.
There is a separate issue in the new token handler in that it does not appear to handle WS-Fed tokens properly. But again, that is internal to the ASP.NET Core component implementation in its choice of relying on other projects.
I am not using the token handlers directly, there is nothing in the code or the sample app to be switched.
It appears that ASP.NET Core’s Authentication.WsFederation component has relied internally on one or more broken components from other project(s).
I would expect that such internal issues between projects would be addressed by the involved projects’ members.
To reiterate: this is not a question about the breaking change that was noted, it’s an issue with the component not working as documented, requiring user space work arounds.