/// <summary> /// /// </summary> /// <param name="context"></param> public override async Task GrantResourceOwnerCredentials(OAuthGrantResourceOwnerCredentialsContext context) { //context.OwinContext.Response.Headers.Add("Access-Control-Allow-Origin", new[] { "http://localhost:4200" }); /*Replace below user authentication code as per your Entity Framework Model ***/ using (AccountProvider obj = new AccountProvider()) { //tblUserMaster entry = obj.tblUserMasters.Where //<tblUserMaster>(record => //record.User_ID == context.UserName && //record.User_Password == context.Password).FirstOrDefault(); Account account = await obj.SignInAsync(context.UserName, context.Password); if (account == null) { context.SetError("invalid_grant", "The user name or password is incorrect."); return; } else { ClaimsIdentity oAuthIdentity = new ClaimsIdentity(context.Options.AuthenticationType); oAuthIdentity.AddClaim(new Claim(ClaimTypes.Name, account.Username)); oAuthIdentity.AddClaim(new Claim(ClaimTypes.Role, account.Role.ToString())); oAuthIdentity.AddClaim(new Claim(ClaimTypes.Email, account.Email)); oAuthIdentity.AddClaim(new Claim("Fullname", account.Fullname)); oAuthIdentity.AddClaim(new Claim(ClaimTypes.Sid, account.ID.ToString())); ClaimsIdentity cookiesIdentity = new ClaimsIdentity(context.Options.AuthenticationType); AuthenticationProperties properties = CreateProperties(context.UserName, account.Fullname, account.Role); AuthenticationTicket ticket = new AuthenticationTicket(oAuthIdentity, properties); context.Validated(ticket); context.Request.Context.Authentication.SignIn(cookiesIdentity); } } }