jitbit / AspNetSaml

Very simple SAML 2.0 consumer module for ASP.NET/C#
https://www.jitbit.com
Apache License 2.0
361 stars 118 forks source link

ASP.Net Webforms: SAMLResponse is null #74

Closed adawi9 closed 1 year ago

adawi9 commented 1 year ago

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

alex-jitbit commented 1 year ago

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

adawi9 commented 1 year ago

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

Sure I did, it is null

alex-jitbit commented 1 year ago

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

adawi9 commented 1 year ago

Why this may happened? The user sign in successfully

adawi9 commented 1 year ago

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

alex-jitbit commented 1 year ago

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

adawi9 commented 1 year ago

Any suggestions?

alex-jitbit commented 1 year ago

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