public string GetTypesList() { totalizatorEntities dB = new totalizatorEntities(); dB.Configuration.LazyLoadingEnabled = false; var typesList = dB.Types.ToList(); return(JsonConvert.SerializeObject(typesList)); }
public override Task GrantResourceOwnerCredentials(OAuthGrantResourceOwnerCredentialsContext context) { return(Task.Factory.StartNew(() => { totalizatorEntities db = new totalizatorEntities(); var email = context.UserName; var password = context.Password; var userService = new UserService(db); var user = userService.Validate(email, password); if (user != null) { var claims = new List <Claim>() { new Claim(ClaimTypes.Sid, Convert.ToString(user.Id)), new Claim(ClaimTypes.Name, user.UserName), new Claim(ClaimTypes.Email, user.Email) }; foreach (var role in user.Roles) { claims.Add(new Claim(ClaimTypes.Role, role.Name.ToString())); } var data = new Dictionary <string, string> { { "userName", user.UserName }, { "roles", string.Join(",", user.Roles) } }; var properties = new AuthenticationProperties(data); ClaimsIdentity oAuthIdentity = new ClaimsIdentity(claims, Startup.OAuthOptions.AuthenticationType); var ticket = new AuthenticationTicket(oAuthIdentity, properties); context.Validated(ticket); } else { context.SetError("invalid_grant", "Either email or password is incorrect"); } })); }