本文整理汇总了C#中System.Security.Claims.ClaimsIdentity.BuildClaims方法的典型用法代码示例。如果您正苦于以下问题:C# ClaimsIdentity.BuildClaims方法的具体用法?C# ClaimsIdentity.BuildClaims怎么用?C# ClaimsIdentity.BuildClaims使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Security.Claims.ClaimsIdentity
的用法示例。
在下文中一共展示了ClaimsIdentity.BuildClaims方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GrantResourceOwnerCredentials
public override Task GrantResourceOwnerCredentials(OAuthGrantResourceOwnerCredentialsContext context)
{
context.OwinContext.Response.Headers.Add("Access-Control-Allow-Origin", new[] { "*" });
var user = _userRepository.GetByUsername(context.UserName);
if (user == null)
{
context.SetError("invalid_grant", "The user and password combination doesn't exist");
return ThreadingExtensions.NoResult;
}
if (user.Locked)
{
context.SetError("invalid_grant", "The user account is locked.");
return ThreadingExtensions.NoResult;
}
if (!_hashingService.ValidateStringHash(context.Password, user.Password))
{
HandleFailedLogin(context, user);
return ThreadingExtensions.NoResult;
}
// Build Claims Identity
var identity = new ClaimsIdentity(ApiOwinAuthConfig.OAuthAuthorizationOptions.AuthenticationType);
identity.BuildClaims(user);
var issuedGuid = Guid.NewGuid();
// Create the Properties
var properties = CreateProperties(user);
properties.SetIssuedGuid(issuedGuid);
// Create the ticket and process it.
var ticket = new AuthenticationTicket(identity, properties);
context.Validated(ticket);
SaveLoginInformation(user, issuedGuid);
return ThreadingExtensions.NoResult;
}