Пример #1
0
        public IActionResult Login([FromBody] LoginViewModel auth)
        {
            IActionResult response;
            var           result = new ResultViewModel();

            result = _login.Authenticate(auth);
            if (!result.IsError)
            {
                var    model           = _login.ManageClaimsIdentity(auth);
                string token           = _login.BuildToken();
                var    responseMessage = new
                {
                    Employee = model,
                    Token    = token
                };
                _login.SetupCookie(HttpContext, token);
                response = Ok(responseMessage);
            }
            else
            {
                response = Unauthorized(result);
            }

            return(response);
        }
        public IActionResult RefreshToken(RefreshTokenViewModel model)
        {
            IActionResult response  = Unauthorized();
            var           principal = _refreshToken.GetPrincipalFromExpiredToken(model.Token);

            if (principal != null && _refreshToken.ValidateRefreshToken(principal.Identity.Name, model.RefreshToken))
            {
                var result = new RefreshTokenViewModel
                {
                    Token        = _login.BuildToken(principal),
                    RefreshToken = _refreshToken.GenerateRefreshToken(principal.Identity.Name)
                };
                _login.SetupCookie(HttpContext, result.Token);
                response = Ok(result);
            }
            return(response);
        }
        public IActionResult Login([FromBody] LoginViewModel auth)
        {
            IActionResult response = Unauthorized();
            var           model    = new EmployeeViewModel();

            if (_login.Authenticate(auth, model))
            {
                string token           = _login.BuildToken();
                var    responseMessage = new
                {
                    Employee     = model,
                    Token        = token,
                    RefreshToken = _refreshToken.GenerateRefreshToken(auth.Username)
                };
                _login.SetupCookie(HttpContext, token);

                response = Ok(responseMessage);
            }

            return(response);
        }