title: Single Sign-On using SAML and AJAX
body: <p>We are implementing Single Sign-On (Identity Provider side) based on SAML messages in .NET. When user wants to use some service, he is redirected to our side with SAML Request Message. SAML message is received on Page_Load and stored in global variable. We show him in applet that reads his smart card in browser (client-side) and then these data (just one string) is being sent by AJAX to server-side where we process data and do some validation checks and then return SAML Response to Service Provider.</p>
  
  <p>Problem - that scenario doesn't works, SAML Response message isn't sent and user isn't  logged in.</p>
  
  <p>Useful information:</p>
  
  <ol>
  <li><p>If applet is removed (no Ajax, just classic button that sends data in form by POST method to the server-side) it works perfect - SAML Response message is being sent and user is logged in, but I need that applet that will read users smart cards from any computer.</p></li>
  <li><p>AJAX call works fine, I receive data that is sent by AJAX. I debugged the code, and it executes till the end, but SAML message isn't sent and there is no redirection that must be done based on SAML Response message that SP is waiting for.</p>
  
  <pre><code>    try {
          $.ajax({
              type: "POST",
              url: "SmartAuth.aspx/GetData",
              data: "{mbo : '" + CMBO.toString() + "', serbr : '" + CSerial.toString() + "', notbefore : '" + CNotBefore.toString() + "', notafter : '" + CNotAfter.toString() + "'}",
              contentType: "application/json; charset=utf-8",
              dataType: "json",
              success: function (msg) {
              window.close()},
              failure: function (msg) {
              alert('Failure');},
  
          });
      } catch (e) {
          alert('Ajax error: ' + e.message);
          throw (e); 
          return 0;
      }
  </code></pre></li>
  </ol>
  
  <p>So, my conclusion is that problem is being created when I use AJAX and SAML in the same time, maybe AJAX connection isn't closed, so SAML message can't be send. Both of them use HTTP so maybe there is some collision on protocol level - I don't know, these are just assumptions, I hope you can help me with ideas.</p>
  
  <p>Thanks!</p>