public override async Task GrantResourceOwnerCredentials(OAuthGrantResourceOwnerCredentialsContext context)
{
context.OwinContext.Response.Headers.Add("Access-Control-Allow-Origin", new[] { "*" });
using (AuthenticationRepository _repo = new AuthenticationRepository())
{
AppUser user = await _repo.GetUserForEmail(context.UserName, context.Password);
string username = string.Empty;
if (user == null)
{
user = _repo.GetUserForLoginUsingAppId(context.UserName, context.Password);
if (user == null)
{
context.SetError("invalid_grant", "The user name or password is incorrect.");
return;
}
}
var identity = new ClaimsIdentity(context.Options.AuthenticationType);
identity.AddClaim(new Claim(ClaimTypes.Name, context.UserName));
identity.AddClaim(new Claim(HandpickClaimTypes.UserId, user.Id.ToString()));
context.Validated(identity);
}
}
{
context.OwinContext.Response.Headers.Add("Access-Control-Allow-Origin", new[] { "*" });
using (AuthenticationRepository _repo = new AuthenticationRepository())
{
AppUser user = await _repo.GetUserForEmail(context.UserName, context.Password);
string username = string.Empty;
if (user == null)
{
user = _repo.GetUserForLoginUsingAppId(context.UserName, context.Password);
if (user == null)
{
context.SetError("invalid_grant", "The user name or password is incorrect.");
return;
}
}
var identity = new ClaimsIdentity(context.Options.AuthenticationType);
identity.AddClaim(new Claim(ClaimTypes.Name, context.UserName));
identity.AddClaim(new Claim(HandpickClaimTypes.UserId, user.Id.ToString()));
context.Validated(identity);
}
}