Implementing Single Sign-On (SSO) using SAML for authentication in web applications | Web SAML SSO Authentication


You have a web based solution/application that your customer utilizes.  The current use case is that users from your customer company registers with your web application for authentication and access to the application. This requires your web application to support a complete User Management Module (that supports user registration, authentication, Password reset and recovery for forgotten passwords, enforcing password policy of your customer in your application, etc.,). 

Considering the support hours and user time in password management and logon issues, your customer would like to have their users automatically authenticated against your web application.

Solution is:

Web SSO which Implements Single Sign-On (SSO) using SAML for authentication in web applications

The Web SAML SSO Authentication is about how to support user logon to a web application/resource without explicitly providing the username and password credentials instead the browser automatically contacts their Identity Management Provider (IdP like ADFS/ or others) and gets a authorization ticket which can be used for authenticating against all web applications that are registered as Relying Parties with the backend Identity Management system.  This way, on Web via browser, user authenticates once with their IdP, and uses the SAML token to automatically authenticate against any other registered web applications/services.  

SAML (Security Assertion Markup Language) is the technology that providers protocols/methods for Web SSO.  Currently in V2.0 SAML supports two general message flows to support the overall process.  They are :

  • SP-initiated SSO:
  • SP-initiated SSO using a Redirect Binding for the SP-to-IdP <AuthnRequest> message and a POST Binding for the IdP-to-SP <Response> message
  • SP-initiated SSO using a POST Binding for the <AuthnRequest> message and an Artifact Binding for the <Response> message
  • IDP-initiated SSO:
  • IDP-initiated SSO using a POST Binding for the IdP-to-SP <Response> message; no SP-to-IdP <AuthnRequest> message is involved.

Here is the detailed explanation of the flow of SP-initiated SSO using a Redirect Binding: This first example describes an SP-initiated SSO exchange. In such an exchange, the user attempts to access a resource on the SP, However they do not have a current logon session on this site and their federated identity is managed by their IdP, They are sent to the IdP to log on and the IdP provides a SAML web SSO assertion for the user’s federated identity back to the SP.  For this specific use case, the HTTP Redirect Binding is used to deliver the SAML <AuthnRequest> message to the IdP and the HTTP POST Binding is used to return the SAML <Response> message containing the assertion to the SP. Figure 12 illustrates the message flow.

SP-Initiated SSO with Redirect and POST Bindings

The processing is as follows:

  1. The user attempts to access a resource on The user does not have a valid logon session (i.e. security context) on this site. The SP saves the requested resource URL in local state information that can be saved across the web SSO exchange.
  2. The SP sends an HTTP redirect response to the browser (HTTP status 302 or 303). The Location
    HTTP header contains the destination URI of the Sign-On Service at the identity provider together with an message encoded as a URL query variable named SAMLRequest.
 <saml:Issuer><a href=""></a><!--<span class="hiddenSpellError" pre=""-->saml:Issuer>
<!--<span class="hiddenSpellError" pre=""-->samlp:AuthnRequest>

The query string is encoded using the DEFLATE encoding. The browser processes the redirect response and issues an HTTP GET request to the IdP’s Single Sign-On Service with the
SAMLRequest query parameter. The local state information (or a reference to it) is also included in the HTTP response encoded in a RelayState query string parameter.

  1. The Single Sign-On Service determines whether the user has an existing logon security context at the identity provider that meets the default or requested (in the ) authentication policy requirements. If not, the IdP interacts with the browser to challenge the user to provide valid credentials.
  2. The user provides valid credentials and a local logon security context is created for the user at the IdP.
  3. The IdP Single Sign-On Service builds a SAML assertion representing the user’s logon security context. Since a POST binding is going to be used, the assertion is digitally signed and then placed within a SAML message. The message is then placed within an HTML FORM as a hidden form control named SAMLResponse. If the IdP received a RelayState value from the SP, it must return it unmodified to the SP in a hidden form control named RelayState. The Single Sign-On Service sends the HTML form back to the browser in the HTTP response. For ease of use purposes, the HTML FORM typically will be accompanied by script code that will automatically post the form to the destination site.
<form method="post" action="" ...>
 <input type="hidden" name="SAMLResponse" value="response" />
 <input type="hidden" name="RelayState" value="token" />
 <input type="submit" value="Submit" />

The value of the SAMLResponse parameter is the base64 encoding of the following element:

 Destination="<a href=";">"</a>>
 <saml:Issuer><a href=""></a><!--<span class="hiddenSpellError" pre=""-->saml:Issuer>
 <saml:Issuer><a href=""></a><!--<span class="hiddenSpellError" pre=""-->saml:Issuer>
 <!-- a POSTed assertion MUST be signed -->
 xmlns:ds="<a href=";">"</a>>...
 <!--<span class="hiddenSpellError" pre=""-->saml:NameID>
 Recipient="<a href=";">"</a>
 <!--<span class="hiddenSpellError" pre=""-->saml:SubjectConfirmation>
 <!--<span class="hiddenSpellError" pre=""-->saml:Subject>
 <saml:Audience><a href=""></a><!--<span class="hiddenSpellError" pre=""-->saml:Audience>
 <!--<span class="hiddenSpellError" pre=""-->saml:AudienceRestriction>
 <!--<span class="hiddenSpellError" pre=""-->saml:Conditions>
 <!--<span class="hiddenSpellError" pre=""-->saml:AuthnContextClassRef>
  1. The browser, due either to a user action or execution of an “auto-submit” script, issues an HTTP POST request to send the form to the SP’s Assertion Consumer Service.
 Content-Type: application/x-www-form-urlencoded
 Content-Length: nnn

where the values of the SAMLResponse and RelayState parameters are taken from the HTML form of Step 5. The service provider’s Assertion Consumer Service obtains the message from the HTML FORM for processing. The digital signature on the SAML assertion must first be validated and then the assertion contents are processed in order to create a local logon security context for the user at the SP. Once this completes, the SP retrieves the local state information indicated by the RelayState data to recall the originally-requested resource URL. It then sends an HTTP redirect response to the browser directing it to access the originally requested resource (not shown).

  1. An access check is made to establish whether the user has the correct authorization to access the resource. If the access check passes, the resource is then returned to the browser.



Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.