Example #1
0
        public IActionResult Login([FromBody] PasswordLoginModel model)
        {
            var tokenArgs = this.authentification.PasswordLogin(model);

            if (tokenArgs == null)
            {
                return(StatusCode(403, "Введен неверный логин или пароль"));
            }

            JwtSecurityToken token = this.GetJwtToken(tokenArgs);
            var encodedToken       = new JwtSecurityTokenHandler().WriteToken(token);

            return(Ok(new { uid = tokenArgs.UserUid, access_token = encodedToken }));
        }
Example #2
0
        public JwtTokenArgs PasswordLogin(PasswordLoginModel model)
        {
            if (model == null)
            {
                throw new ArgumentNullException(nameof(model));
            }

            UserDTO user = this.userService.FindByLogin(model.Login);

            if (user == null || user.PasswordHash != model.Password)
            {
                return(null);
            }

            DateTime now = DateTime.UtcNow;

            return(new JwtTokenArgs(AuthOptions.Issuer,
                                    AuthOptions.Audience,
                                    now,
                                    this.GetUserClaims(user),
                                    now.Add(TimeSpan.FromMinutes(AuthOptions.LifeTimeInMinutes)),
                                    AuthOptions.Key,
                                    user.Uid));
        }