Ejemplo n.º 1
0
        public async Task <LoginResult> GenerateJwtAsync(string email, string password)
        {
            LoginResult     result;
            ApplicationUser user = await GetValidatedUserAsync(email, password);

            if (user != null)
            {
                IList <string> roles = await _userManager.GetRolesAsync(user);

                string authToken = await _jwtGenerator.GenerateEncodedTokenAsync(user.Id, user.Email, roles);

                var response = new
                {
                    id         = user.Id,
                    auth_token = authToken,
                    expires_in = (int)_jwtOptions.ValidFor.TotalSeconds
                };

                string jsonResponse = JsonConvert.SerializeObject(response, _serializerSettings);
                result = LoginResult.Success(jsonResponse);
            }
            else
            {
                result = LoginResult.Failed();
            }

            return(result);
        }