Пример #1
0
        public async Task <TwoFaLoginResponse> LoginWith2Fa(TwoFaLoginRequest request)
        {
            var user = await _applicationUserManager.FindByEmailAsync(request.Username);

            if (user == null)
            {
                return(new TwoFaLoginResponse()
                {
                    IsCodeValid = false
                });
            }
            var authenticatorCode = request.Code.Replace(" ", string.Empty).Replace("-", string.Empty);
            var result            = await _applicationUserManager.VerifyTwoFactorTokenAsync(user, new IdentityOptions().Tokens.AuthenticatorTokenProvider, authenticatorCode);

            if (!result)
            {
                return new TwoFaLoginResponse()
                       {
                           IsCodeValid = false
                       }
            }
            ;

            user = _applicationUserManager.Users.Include(y => y.Groups).First(x => x.UserName.ToLower().Equals(request.Username));
            var roles = await _applicationUserManager.GetRolesAsync(user);

            var groups = user.Groups.Select(x => x.Group.Name);
            var token  = _jwtTokenService.CreateToken(HelperService.ToUser(user), roles);

            return(new TwoFaLoginResponse()
            {
                IsCodeValid = true,
                LoginResponse = LoginResponse.Success(token: token, GetResponseUser(user, token))
            });
        }
Пример #2
0
 public async Task <TwoFaLoginResponse> LoginWith2Fa([FromBody] TwoFaLoginRequest request)
 {
     return(await _authenticationService.LoginWith2Fa(request));
 }