SSO in C# MVC

   
        In this Section, We Know about SSO stands for Single Sign-On. Using SAML for exchanging Authentication and authorization. SAML stands for Security Assertion Markup Language.
      You Need to Third Party tool for Using SSO but it cost. sample providers are CommponentSpace tool. Download and install Your Local Machine. You can Use this on Trial But not implement Trial on Your Server.

               We Go on Functionality First thing its Partner IdP it's for Partner Identity Provider. It's Important Connect SSO Connection Server.it's Working Like a Token. But it's not created by Developers. Its Created By Federation Server, not IIS Server and  Certificate File Also give To Access Their Provided. another One is SingleSignOnServiceUrl this Url will go to Your page into Another Web page SSO Login  Function.

    Add Your ComponentSpace DLL To Reference in Your Project.
                 This above There Infomation is Requirement From Your Client.

Step 1: 
       
Add Parner IdP Value set in Web.Config 
         <appSettings>
              <add key="PartnerIdP" value="####DFG#" />
         </appSettings>
      

Step 2:
    Include the Certificate File In Your Project It Will Gives you SSO Federation Server Admins.
I will Set the name to sso.com.cer

Step 3:
   Create one Config File for Saml Settings.  AssertionConsumerServiceUrl Settings is Post from Federation Server to Your [HtttpPost] Action in C# MVC.
  
<?xml version="1.0"?>

<SAMLConfiguration xmlns="urn:componentspace:SAML:2.0:configuration">
  <ServiceProvider Name="XF####mTOqo"
                   Description="OWIN Example Service Provider"
                   AssertionConsumerServiceUrl="~/ssoControl/Login"
                   LocalCertificateFile="sso.com.cer"
                   LocalCertificatePassword=""/>

  <PartnerIdentityProviders>

    <!-- Okta -->
    <PartnerIdentityProvider Name="####DFG#"
                             Description="Okta"
                             SignAuthnRequest="false"
                             SignLogoutRequest="false"
                             SignLogoutResponse="false"
                             WantSAMLResponseSigned="false"
                             WantAssertionSigned="false"
                             WantAssertionEncrypted="false"
                             WantLogoutRequestSigned="true"
                             WantLogoutResponseSigned="true"
                             SingleSignOnServiceBinding="urn:oasis:names:tc:SAML:2.0:bindings:HTTP-POST"                      SingleSignOnServiceUrl="https:// <<URL>>"
                             SingleLogoutServiceBinding="urn:oasis:names:tc:SAML:2.0:bindings:HTTP-POST"
                             SingleLogoutServiceUrl="https:// <<URL>>"
                             PartnerCertificateFile="sso.com.cer"/>


  </PartnerIdentityProviders>
</SAMLConfiguration>




Step 4:

    this Step is Your Page Redirect to Federation Server Page.

       <p>@Html.ActionLink("SSO Login »", "SingleSignOn")</p>

       [AllowAnonymous]
        public ActionResult SingleSignOn()
        {
            string partnerIdP = WebConfigurationManager.AppSettings["PartnerIdP"];
            SAMLServiceProvider.InitiateSSO(Response, null, partnerIdP);

            return new EmptyResult();
        }

Step 5:
    this is the last Step We will create a post to Your Project. Create on controllers and create one action that the AssertionConsumerServiceUrl You See the Step 3... Get Data From attributes output Variable. 

     public class ssocontrolController : Controller
    {

        [HttpPost]
        [AllowAnonymous]
        public ActionResult Login(string msg = "")
        {
            bool isInResponseTo = false;
            string partnerIdP = null;
            string userName = null;
            IDictionary<string, string> attributes = null;
            string targetUrl = null;

            try
            {
                SAMLServiceProvider.ReceiveSSO(Request, out isInResponseTo, out partnerIdP, out userName, out attributes, out targetUrl);
String SSOemail = Convert.ToString(attributes["email"]).Trim().ToLower();
if (SSOemail == "" || SSOemail == null)
       {
          return RedirectToAction("Index", "Account", new { msg = "SSOEmailNull" });
        }
    }
            catch (Exception ex)
            {
                Session["Error"] = ex.Message; 
                return RedirectToAction("Index", "Account", new { msg=ex.Message });
            }
            return RedirectToAction("Index", "Account");

        }

    }





Thank You For watching If Any Doubt in implementing SSO Ping me. and Support Me. Engourage Me.


Comments

Popular posts from this blog

Insecure cookie setting: missing Secure flag

Maximum Stored Procedure Function Trigger or View Nesting Level Exceeded (limit 32) in SQL Server

Display Line Chart Using Chart.js MVC C#