Ejemplo n.º 1
0
        public XmlElement RenewTicket(X509Certificate2 sessionCert, XmlElement previousTicket)
        {
            //make the request
            var request = new RequestSecurityTokenRequest()
            {
                RequestSecurityToken = new RequestSecurityTokenType()
                {
                    Context     = "urn:uuid:" + Guid.NewGuid().ToString(),
                    TokenType   = "http://docs.oasis-open.org/wss/oasis-wss-saml-token-profile-1.1#SAMLV1.1",
                    RequestType = RequestTypeEnum.httpdocsoasisopenorgwssxwstrust200512Renew,
                    RenewTarget = new RenewTargetType()
                    {
                        SecurityTokenReference = new SecurityTokenReferenceType()
                        {
                            Embedded = new EmbeddedType()
                            {
                                Any = previousTicket
                            }
                        }
                    }
                }
            };

            RequestSecurityTokenResponse step1 = base.Channel.RequestSecurityToken(request);

            return(Complete(sessionCert, step1));
        }
Ejemplo n.º 2
0
        public XmlElement RequestTicket(X509Certificate2 sessionCert, DateTime notBefore, DateTime notOnOrAfter, IList <Claim> assertingClaims, IList <Claim> additinalClaims)
        {
            //make the request
            var request = new RequestSecurityTokenRequest()
            {
                RequestSecurityToken = new RequestSecurityTokenType()
                {
                    Context     = "urn:uuid:" + Guid.NewGuid().ToString(),
                    TokenType   = "http://docs.oasis-open.org/wss/oasis-wss-saml-token-profile-1.1#SAMLV1.1",
                    RequestType = RequestTypeEnum.httpdocsoasisopenorgwssxwstrust200512Issue,
                    Claims      = new ClaimsType()
                    {
                        Dialect   = "http://docs.oasis-open.org/wsfed/authorization/200706/authclaims",
                        ClaimType = Enumerable.Union(
                            assertingClaims.Select(c => new ClaimType()
                        {
                            Uri  = ClaimTypeExp.Match(c.Type).Groups["name"].Value,
                            Item = c.Value
                        }),
                            additinalClaims.Select(c => new ClaimType()
                        {
                            Uri = ClaimTypeExp.Match(c.Type).Groups["name"].Value
                        })
                            ).ToArray()
                    },
                    Lifetime = new LifetimeType()
                    {
                        Created = new AttributedDateTime()
                        {
                            Value = notBefore.ToString("O")
                        },
                        Expires = new AttributedDateTime()
                        {
                            Value = notOnOrAfter.ToString("O")
                        }
                    },
                    KeyType = "http://docs.oasis-open.org/ws-sx/wstrust/200512/PublicKey",
                    UseKey  = new UseKeyType()
                    {
                        SecurityTokenReference = new SecurityTokenReferenceType()
                        {
                            X509Data = new X509DataType()
                            {
                                ItemsElementName = new ItemsChoiceType[] { ItemsChoiceType.X509Certificate },
                                Items            = new object[] { sessionCert.Export(X509ContentType.Cert) }
                            }
                        }
                    }
                }
            };

            //send it
            RequestSecurityTokenResponse step1 = base.Channel.RequestSecurityToken(request);

            return(Complete(sessionCert, step1));
        }