Example #1
0
        public RequestValidationResult ValidateQueueRequest(
            string targetUrl,
            string queueitToken,
            QueueEventConfig config,
            string customerId,
            string secretKey)
        {
            var state = _userInQueueStateRepository.GetState(config.EventId, config.CookieValidityMinute, secretKey);

            if (state.IsValid)
            {
                if (state.IsStateExtendable && config.ExtendCookieValidity)
                {
                    _userInQueueStateRepository.Store(config.EventId,
                                                      state.QueueId,
                                                      null,
                                                      config.CookieDomain,
                                                      config.IsCookieHttpOnly,
                                                      config.IsCookieSecure,
                                                      state.RedirectType,
                                                      secretKey);
                }
                return(new RequestValidationResult(ActionType.QueueAction,
                                                   eventId: config.EventId,
                                                   queueId: state.QueueId,
                                                   redirectType: state.RedirectType,
                                                   actionName: config.ActionName));
            }
            QueueUrlParams queueParams = QueueParameterHelper.ExtractQueueParams(queueitToken);

            RequestValidationResult requestValidationResult;
            bool isTokenValid = false;

            if (queueParams != null)
            {
                var tokenValidationResult = ValidateToken(config, queueParams, secretKey);
                isTokenValid = tokenValidationResult.IsValid;

                if (isTokenValid)
                {
                    requestValidationResult = GetValidTokenResult(config, queueParams, secretKey);
                }
                else
                {
                    requestValidationResult = GetErrorResult(customerId, targetUrl, config, queueParams, tokenValidationResult.ErrorCode);
                }
            }
            else
            {
                requestValidationResult = GetQueueResult(targetUrl, config, customerId);
            }

            if (state.IsFound && !isTokenValid)
            {
                _userInQueueStateRepository.CancelQueueCookie(config.EventId, config.CookieDomain, config.IsCookieHttpOnly, config.IsCookieSecure);
            }

            return(requestValidationResult);
        }
        private static bool GetIsDebug(string queueitToken, string secretKey)
        {
            var qParams = QueueParameterHelper.ExtractQueueParams(queueitToken);

            if (qParams != null && qParams.RedirectType != null && qParams.RedirectType.ToLower() == "debug")
            {
                return(HashHelper.GenerateSHA256Hash(secretKey, qParams.QueueITTokenWithoutHash) == qParams.HashCode);
            }

            return(false);
        }
        internal static ConnectorDiagnostics Verify(string customerId, string secretKey, string queueitToken)
        {
            var diagnostics = new ConnectorDiagnostics();

            var qParams = QueueParameterHelper.ExtractQueueParams(queueitToken);

            if (qParams == null)
            {
                return(diagnostics);
            }

            if (qParams.RedirectType == null)
            {
                return(diagnostics);
            }

            if (!string.Equals(qParams.RedirectType, "debug", StringComparison.OrdinalIgnoreCase))
            {
                return(diagnostics);
            }

            if (string.IsNullOrEmpty(customerId) || string.IsNullOrEmpty(secretKey))
            {
                diagnostics.SetStateWithSetupError();
                return(diagnostics);
            }

            if (HashHelper.GenerateSHA256Hash(secretKey, qParams.QueueITTokenWithoutHash) != qParams.HashCode)
            {
                diagnostics.SetStateWithTokenError(customerId, "hash");
                return(diagnostics);
            }

            if (qParams.TimeStamp < DateTime.UtcNow)
            {
                diagnostics.SetStateWithTokenError(customerId, "timestamp");
                return(diagnostics);
            }

            diagnostics.IsEnabled = true;

            return(diagnostics);
        }
Example #4
0
        public RequestValidationResult ValidateQueueRequest(
            string targetUrl,
            string queueitToken,
            QueueEventConfig config,
            string customerId,
            string secretKey)
        {
            var state = _userInQueueStateRepository.GetState(config.EventId, config.CookieValidityMinute, secretKey);

            if (state.IsValid)
            {
                if (state.IsStateExtendable && config.ExtendCookieValidity)
                {
                    this._userInQueueStateRepository.Store(config.EventId,
                                                           state.QueueId,
                                                           null,
                                                           config.CookieDomain,
                                                           state.RedirectType,
                                                           secretKey);
                }
                return(new RequestValidationResult(ActionType.QueueAction)
                {
                    EventId = config.EventId,
                    QueueId = state.QueueId,
                    RedirectType = state.RedirectType
                });
            }

            QueueUrlParams queueParmas = QueueParameterHelper.ExtractQueueParams(queueitToken);

            if (queueParmas != null)
            {
                return(GetQueueITTokenValidationResult(targetUrl, config.EventId, config, queueParmas, customerId, secretKey));
            }
            else
            {
                return(GetInQueueRedirectResult(targetUrl, config, customerId));
            }
        }