// GET: Home/Spid/5
        public ActionResult Spid(int id)
        {
            //TEST PURPOSE ONLY
            //DO NOT USE IN PRODUCTION
            //LOAD Identity Provider Info
            string configFile = string.Format("{0}\\IdentityProvider_{1}.xml", _appEnvironment.ContentRootPath, id);

            if (!System.IO.File.Exists(configFile))
            {
                return(NotFound());
            }
            else
            {
                IdentityProvider idp;
                XmlSerializer    xmlSerializer = new XmlSerializer(typeof(IdentityProvider));
                FileStream       xmlData       = new FileStream(configFile, FileMode.Open);
                idp = (IdentityProvider)xmlSerializer.Deserialize(xmlData);
                xmlData.Close();
                //TEST PURPOSE ONLY



                var xmlPrivateKey = idp.ServiceProviderPrivatekey;

                string destinationUrl    = idp.IdentityProviderLoginPostUrl;
                string serviceProviderId = idp.ServiceProviderId;

                string returnUrl = "/";

                if (!string.IsNullOrEmpty(HttpContext.Request.Query["redirectUrl"]))
                {
                    returnUrl = HttpContext.Request.Query["redirectUrl"];
                }

                SAML.AuthRequestOptions requestOptions = new SAML.AuthRequestOptions()
                {
                    AssertionConsumerServiceIndex  = 0,
                    AttributeConsumingServiceIndex = 2,
                    Destination = destinationUrl,
                    SPIDLevel   = SAML.SPIDLevel.SPIDL1,
                    SPUID       = serviceProviderId,
                    UUID        = Guid.NewGuid().ToString()
                };

                SAML.AuthRequest request = new SAML.AuthRequest(requestOptions);

                X509Certificate2 signinCert = new X509Certificate2(_appEnvironment.ContentRootPath + _configuration["SPIDCertPath"], _configuration["SPIDCertPassword"], X509KeyStorageFlags.Exportable);


                string saml = request.GetSignedAuthRequest(signinCert, xmlPrivateKey);



                ViewData["FormUrlAction"] = destinationUrl;
                ViewData["SAMLRequest"]   = System.Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes(saml));
                ViewData["RelayState"]    = System.Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes(returnUrl));

                return(View());
            }
        }
Exemple #2
0
        public void GetSignedAuthRequest()
        {
            SAML.AuthRequestOptions requestOptions = new SAML.AuthRequestOptions()
            {
                AssertionConsumerServiceIndex  = 0,
                AttributeConsumingServiceIndex = 0,
                Destination = "https://spidposte.test.poste.it/jod-fs/ssoservicepost",
                SPIDLevel   = SAML.SPIDLevel.SPIDL1,
                SPUID       = "dotnetcode.it",
                UUID        = Guid.NewGuid().ToString()
            };

            SAML.AuthRequest request = new SAML.AuthRequest(requestOptions);

            string certpath       = string.Format("{0}\\{1}", Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), ConfigurationManager.AppSettings["CertificatePath"].ToString());
            string privatekeypath = string.Format("{0}\\{1}", Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), ConfigurationManager.AppSettings["PrivateKeyPath"].ToString());

            X509Certificate2 signinCert = new X509Certificate2("C:\\SourceCode\\spid-dotnet-sdk\\test\\Developers.Italia.SPID.Test\\Certificates\\Hackathon\\www_dotnetcode_it.pfx", "P@ssw0rd!", X509KeyStorageFlags.Exportable);

            //AsymmetricAlgorithm privateKey=new AsymmetricAlgorithm();



            string saml = request.GetSignedAuthRequest(signinCert);
        }
        // GET: Home/Spid/5
        public ActionResult Spid(int id)
        {
            string destinationUrl    = "https://spidposte.test.poste.it/jod-fs/ssoservicepost";
            string serviceProviderId = "https://www.dotnetcode.it";
            string returnUrl         = "https://*****:*****@ssw0rd!", X509KeyStorageFlags.Exportable);


            string saml = request.GetSignedAuthRequest(signinCert);


            ViewData["saml"]          = saml;
            ViewData["FormUrlAction"] = destinationUrl;
            ViewData["SAMLRequest"]   = System.Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes(saml));
            ViewData["RelayState"]    = System.Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes(returnUrl));

            return(View());
        }
Exemple #4
0
        public void GetAuthRequest()
        {
            SAML.AuthRequestOptions requestOptions = new SAML.AuthRequestOptions()
            {
                AssertionConsumerServiceIndex  = 0,
                AttributeConsumingServiceIndex = 0,
                Destination = "https://spidposte.test.poste.it/jod-fs/ssoservicepost",
                SPIDLevel   = SAML.SPIDLevel.SPIDL1,
                SPUID       = "dotnetcode.it",
                UUID        = Guid.NewGuid().ToString()
            };

            SAML.AuthRequest request = new SAML.AuthRequest(requestOptions);
            string           saml    = request.GetAuthRequest();
        }