public override async Task GrantResourceOwnerCredentials(OAuthGrantResourceOwnerCredentialsContext context) { context.OwinContext.Response.Headers.Add("Access-Control-Allow-Origin", new[] { "*" }); using (var db = new WissAppContext()) { using (var userService = new Service <Users>(db)) { var user = userService.GetEntity(e => e.UserName == context.UserName && e.Password == context.Password && e.IsActive); if (user != null) { UserConfig.RemoveLoggedOutUser(user.UserName); var identity = new ClaimsIdentity(context.Options.AuthenticationType); identity.AddClaim(new Claim("user", user.UserName)); identity.AddClaim(new Claim("Role", user.Roles.Name)); context.Validated(identity); } else { context.SetError("invalid_grant", "User name or passwor is incorrect"); } } } }
public override async Task GrantResourceOwnerCredentials(OAuthGrantResourceOwnerCredentialsContext context) { context.OwinContext.Response.Headers.Add("Access-Control-Allow-Origin", new[] { "*" }); //tüm url lere izin ver demek * using (var db = new WissAppContext()) { using (var userService = new Service <Users>(db)) { var user = userService.GetEntity(e => e.UserName == context.UserName && e.Password == context.Password && e.Active == true); if (user != null) { UserConfig.RemoveLoggedOutUser(user.UserName); //adı loggedOut listesinde ise çıkar sonra adam giriş yapabilsin. var identity = new ClaimsIdentity(context.Options.AuthenticationType); identity.AddClaim(new Claim("user", user.UserName)); identity.AddClaim(new Claim("role", user.Roles.Name)); context.Validated(identity); //servise lere erişim yetkisi verildi. } else { context.SetError("invalid_grant", "User name or password is incorrect."); } } } }