예제 #1
0
        public ActionResult Signin()
        {
            var model = new Models.IdPOptionsModel();

            model.EchoRelayState        = false;
            model.IncludeXmlDeclaration = true;
            model.SetHeaderToUrlEncoded = true;
            model.SignAssertion         = true;
            model.UrlEncodeRelayState   = false;
            model.UrlEncodeSamlResponse = false;
            model.UseNamespaces         = true;
            model.UseSHA256             = false;

            ViewData.Model = model;
            return(View());
        }
예제 #2
0
        public ActionResult Signin(Models.IdPOptionsModel options)
        {
            string requestId            = Session["requestId"].ToString();
            string requestVersion       = Session["requestVersion"].ToString();
            string requestIssuesInstant = Session["requestIssueInstant"].ToString();
            string requestIssuer        = Session["requestIssuer"].ToString();
            string nameIdPolicyFormat   = Session["nameIdPolicyFormat"].ToString();
            string RelayState           = Session["RelayState"].ToString();
            string username             = Session["username"].ToString();
            int    spId = Convert.ToInt32(Session["spId"]);


            SigningHelper.SignatureType signatureType = SigningHelper.SignatureType.Response;
            if (options.SignAssertion)
            {
                signatureType = SigningHelper.SignatureType.Assertion;
            }

            string strRecipient = Properties.Settings.Default.Recipient;
            string strIssuer    = Properties.Settings.Default.Issuer;
            string strSubject   = username;
            string strAudience  = requestIssuer;

            // Set Parameters to the method call to either the configuration value or a default value
            StoreLocation storeLocation    = StoreLocation.CurrentUser;
            StoreName     storeName        = StoreName.My;
            X509FindType  findType         = X509FindType.FindByThumbprint;
            string        certFileLocation = "";
            string        certPassword     = Properties.Settings.Default.CertPassword;
            string        certFindKey      = Properties.Settings.Default.CertThumbprint;

            Dictionary <string, string> attributes = new Dictionary <string, string>();

            attributes.Add("IDPEmail", username);
            string stringSamlResponse = "";

            try
            {
                stringSamlResponse = SamlHelper.GetPostSamlResponse(strRecipient,
                                                                    strIssuer, strSubject, strAudience, requestId, nameIdPolicyFormat,
                                                                    storeLocation, storeName, findType,
                                                                    certFileLocation, certPassword, certFindKey,
                                                                    attributes, signatureType, options);
                if (options.UrlEncodeSamlResponse)
                {
                    stringSamlResponse = System.Web.HttpUtility.UrlEncode(stringSamlResponse);
                }
            }
            catch (Exception ex)
            {
                ViewData["Error"] = ex.ToString();
            }
            Logger.DebugFormat(
                "PostData = {0}", stringSamlResponse);


            //
            var model = new Models.SAMLResponseModel();

            model.SAMLResponse = stringSamlResponse;
            if (options.EchoRelayState)
            {
                if (options.UrlEncodeRelayState)
                {
                    model.RelayState = System.Web.HttpUtility.UrlEncode(RelayState);
                }
                else
                {
                    model.RelayState = RelayState;
                }
            }
            else
            {
                //send hardcoded value back
                model.RelayState = "idp.technicality.online";
                if (options.UrlEncodeRelayState)
                {
                    model.RelayState = System.Web.HttpUtility.UrlEncode(model.RelayState);
                }
            }

            if (spId == 1)
            {
                // return to TestSP URL
                model.Destination = Properties.Settings.Default.TestSPUrl;
            }
            else
            {
                model.Destination = strRecipient;
            }

            if (options.SetHeaderToUrlEncoded)
            {
                model.Enctype = "application/x-www-form-urlencoded";
            }
            else
            {
                model.Enctype = "multipart/form-data";
            }
            ViewData.Model = model;

            return(View("SamlResponse"));
        }