Beispiel #1
0
        public IActionResult VerifyOtp(TokenInput input)
        {
            if (string.IsNullOrWhiteSpace(input.Token) || string.IsNullOrWhiteSpace(input.Data))
            {
                _logger.LogInformation("Token or OTP is null or empty");
                return(BadRequest());
            }


            if (Guid.TryParse(input.Token, out _) && _memoryCache.TryGetValue("L1" + input.Token, out User cachedUser))
            {
                var token = _authHandler.VerifyOtp(cachedUser, input.Data);
                if (token != null)
                {
                    _activityLogger.LogLogin(Request.HttpContext.Connection.RemoteIpAddress, cachedUser);
                    return(Ok(token));
                }

                _logger.LogInformation("Auth handler rejected OTP.");
                return(BadRequest());
            }

            _logger.LogInformation("Token is invalid.");
            return(BadRequest());
        }