コード例 #1
0
        private string GetResponse(string stsUrl, string realm)
        {
            RequestSecurityToken rst = new RequestSecurityToken();

            //rst.RequestType = WSTrustFeb2005Constants.RequestTypes.Issue;
            rst.RequestType = "http://docs.oasis-open.org/ws-sx/ws-trust/200512/Issue";


            //bearer token, no encryption
            rst.AppliesTo = new EndpointReference(realm);
            //rst.KeyType = WSTrustFeb2005Constants.KeyTypes.Bearer;
            rst.KeyType = "http://docs.oasis-open.org/ws-sx/ws-trust/200512/Bearer";


            //WSTrustFeb2005RequestSerializer trustSerializer = new WSTrustFeb2005RequestSerializer();
            WSTrust13RequestSerializer trustSerializer = new WSTrust13RequestSerializer();
            WSHttpBinding binding = new WSHttpBinding();

            binding.Security.Mode = SecurityMode.Transport;

            binding.Security.Message.ClientCredentialType     = MessageCredentialType.None;
            binding.Security.Message.EstablishSecurityContext = false;

            binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Windows;
            EndpointAddress address = new EndpointAddress(stsUrl);
            //WSTrustFeb2005ContractClient trustClient = new WSTrustFeb2005ContractClient(binding, address);
            WSTrust13ContractClient trustClient = new WSTrust13ContractClient(binding, address);

            trustClient.ClientCredentials.Windows.AllowNtlm = true;
            trustClient.ClientCredentials.Windows.AllowedImpersonationLevel = TokenImpersonationLevel.Impersonation;

            // Does this need updating to include custom creds?
            //
            //
            //
            //trustClient.ClientCredentials.Windows.ClientCredential = CredentialCache.DefaultNetworkCredentials;
            trustClient.ClientCredentials.Windows.ClientCredential = new System.Net.NetworkCredential(txtUserName.Text, txtPassword.Text, txtDomain.Text);
            //
            //
            //
            //


            System.ServiceModel.Channels.Message response =
                trustClient.EndIssue(trustClient.BeginIssue(
                                         System.ServiceModel.Channels.Message.CreateMessage(
                                             //MessageVersion.Default, WSTrustFeb2005Constants.Actions.Issue,
                                             MessageVersion.Default, "http://docs.oasis-open.org/ws-sx/ws-trust/200512/RST/Issue",
                                             new RequestBodyWriter(trustSerializer, rst)), null, null));
            trustClient.Close();

            XmlDictionaryReader reader = response.GetReaderAtBodyContents();

            return(reader.ReadOuterXml());
        }
コード例 #2
0
        private string SerializeRequest(RequestSecurityToken request)
        {
            var serializer = new WSTrust13RequestSerializer();
            var context    = new WSTrustSerializationContext();
            var sb         = new StringBuilder(128);

            using (var writer = XmlWriter.Create(new StringWriter(sb)))
            {
                serializer.WriteXml(request, writer, context);
                return(sb.ToString());
            }
        }
コード例 #3
0
ファイル: TokenService.cs プロジェクト: highwaychurch/web
        private string SerializeRequest(RequestSecurityToken request)
        {
            var serializer = new WSTrust13RequestSerializer();
            var context = new WSTrustSerializationContext();
            var sb = new StringBuilder(128);

            using (var writer = XmlWriter.Create(new StringWriter(sb)))
            {
                serializer.WriteXml(request, writer, context);
                return sb.ToString();
            }
        }
コード例 #4
0
        string RstToString(RequestSecurityToken token)
        {
            WSTrust13RequestSerializer ser = new WSTrust13RequestSerializer();
            WSTrustSerializationContext context = new WSTrustSerializationContext();


            StringBuilder stringBuilder = new StringBuilder();
            XmlWriter xr = XmlWriter.Create(new StringWriter(stringBuilder), new XmlWriterSettings { OmitXmlDeclaration = true });
            ser.WriteXml(token, xr, context);
            xr.Flush();

            return stringBuilder.ToString();
        }