private async Task <ClaimsIdentity> GetClaimsIdentity(string userName, string password) { if (!string.IsNullOrEmpty(userName) && !string.IsNullOrEmpty(password)) { // get the user to verifty var userToVerify = await _userManager.FindByNameAsync(userName); if (userToVerify != null) { // check the credentials if (await _userManager.CheckPasswordAsync(userToVerify, password)) { var claims = await _userManager.GetClaimsAsync(userToVerify); _jwtFactory.AddUniqueNameClaim(claims, userName); var claimsIdentity = new ClaimsIdentity(new GenericIdentity(userName, "Token"), claims); return(await Task.FromResult(claimsIdentity)); } } } // Credentials are invalid, or account doesn't exist return(await Task.FromResult <ClaimsIdentity>(null)); }