jitbit/AspNetSaml

ASP.Net Webforms: SAMLResponse is null

adawi9 opened this issue · 8 comments

Hello

I am using this package to implement single sign in with saml for asp.net c# webforms app, below the code I use to redirect to Azure ad login page

`var samlEndpoint = "LoginURL";

        var request = new AuthRequest(
            "ID", //TODO: put your app's "entity ID" here
            "https://localhost:44336/About.aspx" //TODO: put Assertion Consumer URL (where the provider should redirect users after authenticating)
            );
        Response.Redirect(request.GetRedirectUrl(samlEndpoint));`

But when the response redirect to About.aspx page the SAMLResponse is null, below the code in About.aspx

string samlCertificate = @"-----BEGIN CERTIFICATE----- XYZ -----END CERTIFICATE-----"; var samlResponse = new Response(samlCertificate, HttpContext.Current.Request.Form["SAMLResponse"]); // 3. We're done! if (samlResponse.IsValid()) { //WOOHOO!!! user is logged in string username = samlResponse.GetNameID(); } }

Note: the codes above implemented in Page_Load methods

Have you tried debugging? Add breakpoint to About.aspx and see what's inside Request.Form

Have you tried debugging? Add breakpoint to About.aspx and see what's inside Request.Form

Sure I did, it is null

This means the IdP simply hasn't passed the payload to you.

Why this may happened? The user sign in successfully

Also I noticed that the network tab in chrome shows two requests to about page one with POST and status 301 this include tbe payload and the second one with GET with status 200 without payload, a d the vs not catch the first one in debug mode

The redirect is exactly the reason. Your app (or the web server) is responding with 301

Any suggestions?

No sorry, this is something in your app that does the redirect