Exemple #1
0
        private async Task <ClaimsIdentity> GetClaimsIdentity(string email /*aka userName*/, string password)
        {
            if (string.IsNullOrEmpty(email) || string.IsNullOrEmpty(password))
            {
                return(await Task.FromResult <ClaimsIdentity>(null));
            }

            //Get the user, which is to be verified
            var userToVerify = await _userManager.FindByNameAsync(email);

            if (userToVerify == null)
            {
                return(await Task.FromResult <ClaimsIdentity>(null));
            }

            //Check the credentials
            if (await _userManager.CheckPasswordAsync(userToVerify, password))
            {
                return(await Task.FromResult(_jwtManager.GenerateClaimsIdentity(email, userToVerify.Id)));
            }

            //Credentials are invalid, or account doesn't exist
            return(await Task.FromResult <ClaimsIdentity>(null));
        }