public override async Task GrantResourceOwnerCredentials(OAuthGrantResourceOwnerCredentialsContext context) { var userManager = context.OwinContext.GetUserManager <ApplicationUserManager>(); var user = _clientsService.GetByUserName(context.UserName); if (user == null) { context.SetError("invalid_grant", "The user name or password is incorrect."); return; } ClaimsIdentity oAuthIdentity = SetClaims(user, OAuthDefaults.AuthenticationType, user.Role); ClaimsIdentity cookiesIdentity = SetClaims(user, CookieAuthenticationDefaults.AuthenticationType, user.Role); AuthenticationProperties properties = CreateProperties(user.UserName); AuthenticationTicket ticket = new AuthenticationTicket(oAuthIdentity, properties); context.Validated(ticket); context.Request.Context.Authentication.SignIn(cookiesIdentity); }
public IEnumerable <Policies> GetByUserName(string userName) { var client = _clientsService.GetByUserName(userName); return(_mockyConnectorService.GetAllById(urlMocky, JsonModels.policies, "clientId", client?.Id).Select(x => Mapper(x))); }