public override async Task GrantResourceOwnerCredentials(OAuthGrantResourceOwnerCredentialsContext context) { var allowedOrigin = "http://localhost:8080"; context.OwinContext.Response.Headers.Add("Access-Control-Allow-Origin", new[] { allowedOrigin }); //var userManager = context.OwinContext.GetUserManager<ApplicationUserManager>(); using (AuthRepository _repo = new AuthRepository()) { ApplicationUser user = await _repo.FindUser(context.UserName, context.Password); if (user == null) { context.SetError("invalid_grant", "The user name or password is incorrect."); return; } ClaimsIdentity oAuthIdentity = await user.GenerateUserIdentityAsync(_repo._userManager, "JWT"); //oAuthIdentity.AddClaims(ExtendedClaimProvider.GetClaims(user)); var ticket = new AuthenticationTicket(oAuthIdentity,null); context.Validated(ticket); } }
public override async Task GrantResourceOwnerCredentials(OAuthGrantResourceOwnerCredentialsContext context) { var allowedOrigin = context.OwinContext.Get<string>("as:clientAllowedOrigin"); if (allowedOrigin == null) allowedOrigin = "*"; context.OwinContext.Response.Headers.Add("Access-Control-Allow-Origin", new[] { allowedOrigin }); AuthRepository _repo = new AuthRepository(); ApplicationUser user = await _repo.FindUser(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); var identity = await user.GenerateUserIdentityAsync(_repo._userManager, "JWT"); identity.AddClaim(new Claim(ClaimTypes.Name, context.UserName)); var props = new AuthenticationProperties(new Dictionary<string, string> { { "client_id", (context.ClientId == null) ? string.Empty : context.ClientId }, { "userName", context.UserName } }); var ticket = new AuthenticationTicket(identity, props); context.Validated(ticket); }