Nina
Nina

Reputation: 11

ADFS Authentication not working in .Net 8

Can anyone help to find out the issue?

One of my existing MVC applications uses ADFS authentication. Now, I am attempting to implement the same authentication in a new application using .NET 8. I have created a separate application identity for the new one (urn:TestDev). I'm using the following code to implement authentication:

builder.Services.AddAuthentication(sharedOptions =>
    {
        sharedOptions.DefaultAuthenticateScheme = WsFederationDefaults.AuthenticationScheme;
        sharedOptions.DefaultSignInScheme = CookieAuthenticationDefaults.AuthenticationScheme;
        sharedOptions.DefaultChallengeScheme = WsFederationDefaults.AuthenticationScheme;
    })
    .AddCookie()
    .AddWsFederation(options =>
    {
        options.MetadataAddress = "https://example.com/FederationMetadata/2007-06/FederationMetadata.xml"; 
        options.Wtrealm = "urn:TestDev"; 
        options.Wreply = "https://myapp.com/";

However, I am getting the IsAuthenticated as false for HttpContext.User.

Upon checking the SAML response using a browser plugin, it appears that the response status is 200. Does this indicate successful authentication from the server?

saml screenshot

Could there be any other issues within the application aside from the provided code? I've attempted to log various events like WsFederationEvents (OnTicketReceived, OnAuthenticationFailed, OnSecurityTokenReceived, OnSecurityTokenValidated, etc.). However, the only event that seems to be triggered is OnRedirectToIdentityProvider. Despite this, I can see the SAML response in the browser extension. Does this imply that the authentication was successful, and any potential configuration issues lie within the code? It's worth noting that I'm using a sample application for testing purposes.

Is there any configuration missing in my code?

Upvotes: 0

Views: 127

Answers (0)

Related Questions