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


C# SecurityTokenHandlerCollection.ReadToken方法代码示例

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


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

示例1: ToSecurityToken

        /// <summary>
        /// Turns a supported generic XML security token to a security token.
        /// </summary>
        /// <param name="token">The generic XML security token.</param>
        /// <param name="handler">The security token handler.</param>
        /// <returns>A SecurityToken</returns>
        public static SecurityToken ToSecurityToken(this GenericXmlSecurityToken token, SecurityTokenHandlerCollection handler)
        {
            var reader = new XmlTextReader(new StringReader(token.TokenXml.OuterXml));

            if (handler.CanReadToken(reader))
            {
                return handler.ReadToken(reader);
            }
            else
            {
                throw new InvalidOperationException("Unsupported token type");
            }
        }
开发者ID:bykovas,项目名称:IdentityModel,代码行数:19,代码来源:SecurityTokens.cs

示例2: LoginWithUsernamePassword

 private static void LoginWithUsernamePassword(AuthenticationHeaderValue credentials, SecurityTokenHandlerCollection handlers, HttpApplication context)
 {
     try
     {
         var cred = EncodingFactory.ReadFileText(Convert.FromBase64String(credentials.Parameter));
         var separator = cred.IndexOf(':');
         var name = cred.Substring(0, separator);
         var password = cred.Substring(separator + 1);
         var manager = new TokenManager(GetServiceName(context), name, password);
         SecurityToken token = null;
         var xmlSecurityToken = manager.GetToken(HttpContext.Current.Request.Url.ToString()) as GenericXmlSecurityToken;
         if (xmlSecurityToken != null)
         {
             token = handlers.ReadToken(new XmlTextReader(new StringReader(xmlSecurityToken.TokenXml.OuterXml)));
         }
         var securityToken = handlers.ValidateToken(token);
         var principal = new ClaimsPrincipal(securityToken);
         var identity = principal.Identity as ClaimsIdentity;
         if (identity != null) identity.BootstrapContext = new BootstrapContext(xmlSecurityToken.TokenXml.OuterXml);
         Thread.CurrentPrincipal = principal;
         context.Context.User = principal;
         var sessionToken = new SessionSecurityToken(principal);
         FederatedAuthentication.SessionAuthenticationModule.WriteSessionTokenToCookie(sessionToken);
     }
     catch (Exception)
     {
         context.Response.AppendHeader("X-InvalidCredentials", "basic");
         throw;
     }
 }
开发者ID:JonasSyrstad,项目名称:Stardust,代码行数:30,代码来源:WcfRestClaimsModule.cs

示例3: ReadSecurityToken

        /// <summary>
        /// Reads a <see cref="SecurityToken"/> from the provided XML representation.
        /// </summary>
        /// <param name="securityTokenXml">The XML representation of the security token.</param>
        /// <param name="securityTokenHandlers">The <see cref="SecurityTokenHandlerCollection"/> used to
        /// read the token.</param>
        /// <returns>A <see cref="SecurityToken"/>.</returns>
        protected virtual SecurityToken ReadSecurityToken(XmlElement securityTokenXml,
                                                           SecurityTokenHandlerCollection securityTokenHandlers)
        {
            SecurityToken securityToken = null;
            XmlReader reader = new XmlNodeReader(securityTokenXml);

            reader.MoveToContent();

            securityToken = securityTokenHandlers.ReadToken(reader);
            if (securityToken == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.GetString(SR.ID4051, securityTokenXml, reader.LocalName, reader.NamespaceURI)));
            }

            return securityToken;
        }
开发者ID:krytht,项目名称:DotNetReferenceSource,代码行数:23,代码来源:SecurityTokenElement.cs

示例4: LoginWithToken

 private static void LoginWithToken(AuthenticationHeaderValue credentials, SecurityTokenHandlerCollection handlers, HttpApplication context)
 {
     try
     {
         var token = Convert.FromBase64String(credentials.Parameter);
         using (var stream = new MemoryStream(token))
         {
             using (var xmlReader = XmlReader.Create(stream))
             {
                 var securityToken = handlers.ReadToken(xmlReader);
                 var identities = handlers.ValidateToken(securityToken);
                 var principal = new ClaimsPrincipal(identities);
                 var identity = principal.Identity as ClaimsIdentity;
                 if (identity != null) identity.BootstrapContext = new BootstrapContext(token);
                 Thread.CurrentPrincipal = principal;
                 context.Context.User = principal;
             }
         }
     }
     catch (Exception)
     {
         context.Response.AppendHeader("X-InvalidCredentials", "token");
         throw;
     }
 }
开发者ID:JonasSyrstad,项目名称:Stardust,代码行数:25,代码来源:WcfRestClaimsModule.cs


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