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


C# SecurityTokenHandler.ReadToken方法代码示例

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


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

示例1: ReadToken

/// <summary>
/// Reads a serialized token and converts it into a <see cref="SecurityToken"/>.
/// </summary>
/// <param name="reader">An XML reader positioned at the token's start element.</param>
/// <returns>The parsed form of the token.</returns>
public override SecurityToken ReadToken( XmlReader reader )
{
    if ( reader == null )
    {
        throw new ArgumentNullException( "reader" );
    }

    XmlDictionaryReader dictionaryReader = XmlDictionaryReader.CreateDictionaryReader(reader);

    byte[] binaryData;
    string encoding = dictionaryReader.GetAttribute( EncodingType );
    if ( encoding == null || encoding == Base64EncodingType )
    {
        dictionaryReader.Read();
        binaryData = dictionaryReader.ReadContentAsBase64();
    }
    else
    {
        throw new SecurityTokenException(
            "Cannot read SecurityToken as its encoding is" + encoding + ". Expected a BinarySecurityToken with base64 encoding.");
    }
    
    string serializedToken = Encoding.UTF8.GetString(binaryData);

    return ReadSecurityTokenFromString(serializedToken);
}
开发者ID:.NET开发者,项目名称:System.IdentityModel.Tokens,代码行数:31,代码来源:SecurityTokenHandler.ReadToken

示例2: ReadSecurityTokenFromString

/// <summary>
/// Parse the string token and generates a <see cref="SecurityToken"/>.
/// </summary>
/// <param name="serializedToken">The serialized form of the token received.</param>
/// <returns>The parsed form of the token.</returns>
protected SecurityToken ReadSecurityTokenFromString( string serializedToken )
{
    if (String.IsNullOrEmpty(serializedToken))
    {
        throw new ArgumentException("The parameter 'serializedToken' cannot be null or empty string.");
    }

    // Create a collection of SWT name value pairs
    NameValueCollection properties = ParseToken( serializedToken );
    SimpleWebToken swt = new SimpleWebToken( properties, serializedToken );

    return swt;
}
开发者ID:.NET开发者,项目名称:System.IdentityModel.Tokens,代码行数:18,代码来源:SecurityTokenHandler.ReadToken

示例3: ParseToken

/// <summary>
/// Parses the token into a collection.
/// </summary>
/// <param name="encodedToken">The serialized token.</param>
/// <returns>A colleciton of all name-value pairs from the token.</returns>
NameValueCollection ParseToken( string encodedToken )
{
    if ( String.IsNullOrEmpty( encodedToken ) )
    {
        throw new ArgumentException( "The parameter 'encodedToken' cannot be null or empty string.");
    }

    NameValueCollection keyValuePairs = new NameValueCollection();
    foreach ( string nameValue in encodedToken.Split( ParameterSeparator ) )
    {
        string[] keyValueArray = nameValue.Split( '=' );

        if ( ( keyValueArray.Length < 2 ) || String.IsNullOrEmpty( keyValueArray[0] ) )
        {
            throw new SecurityTokenException("The incoming token was not in an expected format.");
        }

        // Names must be decoded for the claim type case
        string key = HttpUtility.UrlDecode( keyValueArray[0].Trim() );

        // remove any unwanted "
        string value = HttpUtility.UrlDecode( keyValueArray[1].Trim().Trim( '"' ) ); 
        keyValuePairs.Add( key, value );
    }

    return keyValuePairs;
}
开发者ID:.NET开发者,项目名称:System.IdentityModel.Tokens,代码行数:32,代码来源:SecurityTokenHandler.ReadToken


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