Esempio n. 1
0
        public ActionResult FederationMetadata()
        {
            X509Certificate cert   = CustomSecurityTokenService.GetCertificate();
            KeyInfoX509Data kid    = new KeyInfoX509Data(cert, X509IncludeOption.WholeChain);
            var             xml    = kid.GetXml();
            string          theKey = xml.InnerText;

            Uri    uri      = HttpContext.Request.Url;
            string adfsRoot = ConfigurationManager.AppSettings["FakeAdfsAt"];
            string url      = $"{adfsRoot}/FederatedLogin/";

            string serviceDisplayName = "FakeADFS";

            StringBuilder ret = new StringBuilder();

            ret.Append($"<EntityDescriptor ID=\"_F38DBA4E-2F47-458D-BF6F-8A7EFB7C790A\" entityID=\"{url}\" xmlns=\"urn:oasis:names:tc:SAML:2.0:metadata\">");
            ret.Append($"<RoleDescriptor xsi:type=\"fed:SecurityTokenServiceType\" protocolSupportEnumeration=\"http://docs.oasis-open.org/ws-sx/ws-trust/200512 http://schemas.xmlsoap.org/ws/2005/02/trust http://docs.oasis-open.org/wsfed/federation/200706\" ServiceDisplayName=\"{serviceDisplayName}\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:fed=\"http://docs.oasis-open.org/wsfed/federation/200706\">");
            ret.Append($"<KeyDescriptor use=\"signing\"><KeyInfo xmlns=\"http://www.w3.org/2000/09/xmldsig#\"><X509Data><X509Certificate>{theKey}</X509Certificate></X509Data></KeyInfo></KeyDescriptor>");
            ret.Append($"<fed:TokenTypesOffered><fed:TokenType Uri=\"urn:oasis:names:tc:SAML:1.0:assertion\" /></fed:TokenTypesOffered>");
            ret.Append($"<fed:PassiveRequestorEndpoint><EndpointReference xmlns=\"http://www.w3.org/2005/08/addressing\"><Address>{url}</Address></EndpointReference></fed:PassiveRequestorEndpoint>");
            ret.Append("</RoleDescriptor>");
            ret.Append("</EntityDescriptor>");

            return(Content(ret.ToString()));
        }
        private static string ProcessSignIn(Uri url, ClaimsPrincipal user)
        {
            var requestMessage     = (SignInRequestMessage)WSFederationMessage.CreateFromUri(url);
            var signingCredentials = new X509SigningCredentials(CustomSecurityTokenService.GetCertificate(ConfigurationManager.AppSettings["SigningCertificateName"]));
            var config             = new SecurityTokenServiceConfiguration(ConfigurationManager.AppSettings["IssuerName"], signingCredentials);
            var sts             = new CustomSecurityTokenService(config);
            var responseMessage = FederatedPassiveSecurityTokenServiceOperations.ProcessSignInRequest(requestMessage, user, sts);

            return(responseMessage.WriteFormPost());
        }