本文整理汇总了C#中SecurityTokenHandlerCollection.ValidateToken方法的典型用法代码示例。如果您正苦于以下问题:C# SecurityTokenHandlerCollection.ValidateToken方法的具体用法?C# SecurityTokenHandlerCollection.ValidateToken怎么用?C# SecurityTokenHandlerCollection.ValidateToken使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SecurityTokenHandlerCollection
的用法示例。
在下文中一共展示了SecurityTokenHandlerCollection.ValidateToken方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ValidateToken
/// <summary>
/// Creates the identities for the represented by the <see cref="SecurityToken"/>.
/// </summary>
/// <param name="securityTokenXml">The <see cref="XmlElement"/> representation of the security token.</param>
/// <param name="securityTokenHandlers">The collection of <see cref="SecurityTokenHandler"/> objects that may
/// be used to read and validate the security token this object represents.</param>
/// <returns>A <see cref="ReadOnlyCollection{T}"/> of <see cref="ClaimsIdentity"/> representing the identities contained in the token.</returns>
/// <exception cref="InvalidOperationException">If either parameter 'securityTokenXml' or 'securityTokenHandlers' are null.</exception>
protected virtual ReadOnlyCollection<ClaimsIdentity> ValidateToken(XmlElement securityTokenXml, SecurityTokenHandlerCollection securityTokenHandlers)
{
if (securityTokenXml == null || securityTokenHandlers == null)
{
throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.GetString(SR.ID4052)));
}
SecurityToken securityToken = GetSecurityToken();
return securityTokenHandlers.ValidateToken(securityToken);
}
示例2: ToClaimsPrincipal
/// <summary>
/// Converts a SecurityToken to an IClaimsPrincipal.
/// </summary>
/// <param name="token">The token.</param>
/// <param name="handler">The handler.</param>
/// <returns>An IClaimsPrincipal</returns>
public static ClaimsPrincipal ToClaimsPrincipal(this SecurityToken token, SecurityTokenHandlerCollection handler)
{
var ids = handler.ValidateToken(token);
return new ClaimsPrincipal(from identity in ids select identity);
}
示例3: ToClaimsPrincipal
/// <summary>
/// Converts a SecurityToken to an IClaimsPrincipal.
/// </summary>
/// <param name="token">The token.</param>
/// <param name="handler">The handler.</param>
/// <returns>
/// An IClaimsPrincipal
/// </returns>
public static ClaimsPrincipal ToClaimsPrincipal(this SecurityToken token, SecurityTokenHandlerCollection handler)
{
return
new ClaimsPrincipal(handler.ValidateToken(token).Select(identity => identity));
}
示例4: ValidateToken
private void ValidateToken(string securityToken, TokenValidationParameters validationParameters, SecurityTokenHandlerCollection tokenHandlers, ExpectedException expectedException)
{
try
{
SecurityToken validatedToken;
tokenHandlers.ValidateToken(securityToken, validationParameters, out validatedToken);
expectedException.ProcessNoException();
}
catch (Exception exception)
{
expectedException.ProcessException(exception);
}
}
开发者ID:richardschneider,项目名称:azure-activedirectory-identitymodel-extensions-for-dotnet,代码行数:14,代码来源:SecurityTokenHandlerCollectionExtensionsTests.cs
示例5: 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;
}
}
示例6: 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;
}
}
示例7: ToClaimsPrincipal
/// <summary>
/// Converts a SecurityToken to an IClaimsPrincipal.
/// </summary>
/// <param name="token">The token.</param>
/// <param name="handler">The handler.</param>
/// <returns>An IClaimsPrincipal</returns>
public static IClaimsPrincipal ToClaimsPrincipal(this SecurityToken token, SecurityTokenHandlerCollection handler)
{
var ids = handler.ValidateToken(token);
return ClaimsPrincipal.CreateFromIdentities(ids);
}