当前位置: 首页>>代码示例>>C#>>正文


C# SamlSerializer.WriteToken方法代码示例

本文整理汇总了C#中System.IdentityModel.Tokens.SamlSerializer.WriteToken方法的典型用法代码示例。如果您正苦于以下问题:C# SamlSerializer.WriteToken方法的具体用法?C# SamlSerializer.WriteToken怎么用?C# SamlSerializer.WriteToken使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.IdentityModel.Tokens.SamlSerializer的用法示例。


在下文中一共展示了SamlSerializer.WriteToken方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GetIdentityToken

        /// <summary cref="IUserIdentity.GetIdentityToken" />
        public UserIdentityToken GetIdentityToken()
        {
            // check for anonymous.
            if (m_token == null)
            {
                AnonymousIdentityToken token = new AnonymousIdentityToken();
                token.PolicyId = m_policyId;
                return token;
            }

            // return a user name token.
            UserNameSecurityToken usernameToken = m_token as UserNameSecurityToken;

            if (usernameToken != null)
            {
                UserNameIdentityToken token = new UserNameIdentityToken();
                token.PolicyId = m_policyId;
                token.UserName = usernameToken.UserName;
                token.DecryptedPassword = usernameToken.Password;
                return token;
            }

            // return an X509 token.
            X509SecurityToken x509Token = m_token as X509SecurityToken;

            if (x509Token != null)
            {
                X509IdentityToken token = new X509IdentityToken();
                token.PolicyId = m_policyId;
                token.CertificateData = x509Token.Certificate.GetRawCertData();
                token.Certificate = x509Token.Certificate;
                return token;
            }
            
            // handle SAML token.
            SamlSecurityToken samlToken = m_token as SamlSecurityToken;

            if (samlToken != null)
            {
                MemoryStream ostrm = new MemoryStream();      
                XmlTextWriter writer = new XmlTextWriter(ostrm, new UTF8Encoding());   
 
                try
                {
                    SamlSerializer serializer = new SamlSerializer();
                    serializer.WriteToken(samlToken, writer, WSSecurityTokenSerializer.DefaultInstance);
                }
                finally
                {
                    writer.Close();
                }

                IssuedIdentityToken wssToken = new IssuedIdentityToken();
                wssToken.PolicyId = m_policyId;
                wssToken.DecryptedTokenData = ostrm.ToArray();

                return wssToken;
            }

            // return a WSS token by default.
            if (m_token != null)
            {
                MemoryStream ostrm = new MemoryStream();
                XmlWriter writer = new XmlTextWriter(ostrm, new UTF8Encoding());

                try
                {
                    WSSecurityTokenSerializer serializer = new WSSecurityTokenSerializer();
                    serializer.WriteToken(writer, m_token);
                }
                finally
                {
                    writer.Close();
                }

                IssuedIdentityToken wssToken = new IssuedIdentityToken();
                wssToken.PolicyId = m_policyId;
                wssToken.DecryptedTokenData = ostrm.ToArray();

                return wssToken;
            }

            return null;
        }
开发者ID:yuriik83,项目名称:UA-.NET,代码行数:85,代码来源:UserIdentity.cs


注:本文中的System.IdentityModel.Tokens.SamlSerializer.WriteToken方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。