private RequestValidationResult GetVaidationErrorResult( string customerId, string targetUrl, QueueEventConfig config, QueueUrlParams qParams, string errorCode) { var query = GetQueryString(customerId, config.EventId, config.Version, config.Culture, config.LayoutName) + $"&queueittoken={qParams.QueueITToken}" + $"&ts={DateTimeHelper.GetUnixTimeStampFromDate(DateTime.UtcNow)}" + (!string.IsNullOrEmpty(targetUrl) ? $"&t={HttpUtility.UrlEncode(targetUrl)}" : ""); var domainAlias = config.QueueDomain; if (!domainAlias.EndsWith("/")) { domainAlias = domainAlias + "/"; } var redirectUrl = $"https://{domainAlias}error/{errorCode}/?{query}"; return(new RequestValidationResult(ActionType.QueueAction) { RedirectUrl = redirectUrl, EventId = config.EventId }); }
public static RequestValidationResult ResolveQueueRequestByLocalConfig( string targetUrl, string queueitToken, QueueEventConfig queueConfig, string customerId, string secretKey) { var debugEntries = new Dictionary <string, string>(); var connectorDiagnostics = ConnectorDiagnostics.Verify(customerId, secretKey, queueitToken); if (connectorDiagnostics.HasError) { return(connectorDiagnostics.ValidationResult); } try { targetUrl = GenerateTargetUrl(targetUrl); return(ResolveQueueRequestByLocalConfig(targetUrl, queueitToken, queueConfig, customerId, secretKey, debugEntries, connectorDiagnostics.IsEnabled)); } catch (Exception e) { if (connectorDiagnostics.IsEnabled) { debugEntries["Exception"] = e.Message; } throw; } finally { SetDebugCookie(debugEntries); } }
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, 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); } return(requestValidationResult); }
private RequestValidationResult GetInQueueRedirectResult( string targetUrl, QueueEventConfig config, string customerId) { var redirectUrl = "https://" + config.QueueDomain + "?" + GetQueryString(customerId, config.EventId, config.Version, config.Culture, config.LayoutName) + (!string.IsNullOrEmpty(targetUrl) ? $"&t={HttpUtility.UrlEncode(targetUrl)}" : ""); return(new RequestValidationResult(ActionType.QueueAction) { RedirectUrl = redirectUrl, EventId = config.EventId }); }
private static RequestValidationResult ResolveQueueRequestByLocalConfig( string targetUrl, string queueitToken, QueueEventConfig queueConfig, string customerId, string secretKey, Dictionary <string, string> debugEntries, bool isDebug) { if (isDebug) { debugEntries["SdkVersion"] = UserInQueueService.SDK_VERSION; debugEntries["Runtime"] = GetRuntime(); debugEntries["TargetUrl"] = targetUrl; debugEntries["QueueitToken"] = queueitToken; debugEntries["QueueConfig"] = queueConfig != null?queueConfig.ToString() : "NULL"; debugEntries["OriginalUrl"] = GetHttpContextProvider().HttpRequest.Url.AbsoluteUri; LogExtraRequestDetails(debugEntries); } if (string.IsNullOrEmpty(customerId)) { throw new ArgumentException("customerId can not be null or empty."); } if (string.IsNullOrEmpty(secretKey)) { throw new ArgumentException("secretKey can not be null or empty."); } if (queueConfig == null) { throw new ArgumentException("eventConfig can not be null."); } if (string.IsNullOrEmpty(queueConfig.EventId)) { throw new ArgumentException("EventId from eventConfig can not be null or empty."); } if (string.IsNullOrEmpty(queueConfig.QueueDomain)) { throw new ArgumentException("QueueDomain from eventConfig can not be null or empty."); } if (queueConfig.CookieValidityMinute <= 0) { throw new ArgumentException("CookieValidityMinute from eventConfig should be greater than 0."); } queueitToken = queueitToken ?? string.Empty; var userInQueueService = GetUserInQueueService(); var result = userInQueueService.ValidateQueueRequest(targetUrl, queueitToken, queueConfig, customerId, secretKey); result.IsAjaxResult = IsQueueAjaxCall(); return(result); }
public static RequestValidationResult ResolveQueueRequestByLocalConfig( string targetUrl, string queueitToken, QueueEventConfig queueConfig, string customerId, string secretKey) { var debugEntries = new Dictionary <string, string>(); try { targetUrl = GenerateTargetUrl(targetUrl); return(ResolveQueueRequestByLocalConfig(targetUrl, queueitToken, queueConfig, customerId, secretKey, debugEntries)); } finally { SetDebugCookie(debugEntries); } }
private RequestValidationResult GetQueueResult( string targetUrl, QueueEventConfig config, string customerId) { var query = GetQueryString(customerId, config.EventId, config.Version, config.ActionName, config.Culture, config.LayoutName) + (!string.IsNullOrEmpty(targetUrl) ? $"&t={Uri.EscapeDataString(targetUrl)}" : ""); var redirectUrl = GenerateRedirectUrl(config.QueueDomain, "", query); return(new RequestValidationResult( ActionType.QueueAction, redirectUrl: redirectUrl, eventId: config.EventId, actionName: config.ActionName)); }
private RequestValidationResult GetErrorResult( string customerId, string targetUrl, QueueEventConfig config, QueueUrlParams qParams, string errorCode) { var query = GetQueryString(customerId, config.EventId, config.Version, config.ActionName, config.Culture, config.LayoutName) + $"&queueittoken={qParams.QueueITToken}" + $"&ts={DateTimeHelper.GetUnixTimeStampFromDate(DateTime.UtcNow)}" + (!string.IsNullOrEmpty(targetUrl) ? $"&t={Uri.EscapeDataString(targetUrl)}" : ""); var redirectUrl = GenerateRedirectUrl(config.QueueDomain, $"error/{errorCode}/", query); return(new RequestValidationResult( ActionType.QueueAction, redirectUrl: redirectUrl, eventId: config.EventId, actionName: config.ActionName)); }
private RequestValidationResult GetValidTokenResult( QueueEventConfig config, QueueUrlParams queueParams, string secretKey) { _userInQueueStateRepository.Store( config.EventId, queueParams.QueueId, queueParams.CookieValidityMinutes, config.CookieDomain, queueParams.RedirectType, secretKey); return(new RequestValidationResult( ActionType.QueueAction, eventId: config.EventId, queueId: queueParams.QueueId, redirectType: queueParams.RedirectType, actionName: config.ActionName)); }
private RequestValidationResult GetQueueITTokenValidationResult( string targetUrl, string eventId, QueueEventConfig config, QueueUrlParams queueParams, string customerId, string secretKey) { string calculatedHash = HashHelper.GenerateSHA256Hash(secretKey, queueParams.QueueITTokenWithoutHash); if (calculatedHash != queueParams.HashCode) { return(GetVaidationErrorResult(customerId, targetUrl, config, queueParams, "hash")); } if (queueParams.EventId != eventId) { return(GetVaidationErrorResult(customerId, targetUrl, config, queueParams, "eventid")); } if (queueParams.TimeStamp < DateTime.UtcNow) { return(GetVaidationErrorResult(customerId, targetUrl, config, queueParams, "timestamp")); } this._userInQueueStateRepository.Store( config.EventId, queueParams.QueueId, queueParams.CookieValidityMinutes, config.CookieDomain, queueParams.RedirectType, secretKey, config.CookieHttpOnly); return(new RequestValidationResult(ActionType.QueueAction) { EventId = config.EventId, QueueId = queueParams.QueueId, RedirectType = queueParams.RedirectType }); }
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, config.CookieHttpOnly); } 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)); } }
private static RequestValidationResult HandleQueueAction( string currentUrlWithoutQueueITToken, string queueitToken, CustomerIntegration customerIntegrationInfo, string customerId, string secretKey, Dictionary <string, string> debugEntries, IntegrationConfigModel matchedConfig, bool?cookieHttpOnly) { var targetUrl = ""; switch (matchedConfig.RedirectLogic) { case "ForcedTargetUrl": case "ForecedTargetUrl": targetUrl = matchedConfig.ForcedTargetUrl; break; case "EventTargetUrl": targetUrl = ""; break; default: targetUrl = GenerateTargetUrl(currentUrlWithoutQueueITToken); break; } var queueEventConfig = new QueueEventConfig() { QueueDomain = matchedConfig.QueueDomain, Culture = matchedConfig.Culture, EventId = matchedConfig.EventId, ExtendCookieValidity = matchedConfig.ExtendCookieValidity.Value, LayoutName = matchedConfig.LayoutName, CookieValidityMinute = matchedConfig.CookieValidityMinute.Value, CookieDomain = matchedConfig.CookieDomain, CookieHttpOnly = cookieHttpOnly, Version = customerIntegrationInfo.Version }; return(ResolveQueueRequestByLocalConfig(targetUrl, queueitToken, queueEventConfig, customerId, secretKey, debugEntries)); }
private TokenValidationResult ValidateToken( QueueEventConfig config, QueueUrlParams queueParams, string secretKey) { string calculatedHash = HashHelper.GenerateSHA256Hash(secretKey, queueParams.QueueITTokenWithoutHash); if (calculatedHash != queueParams.HashCode) { return(new TokenValidationResult(false, "hash")); } if (queueParams.EventId != config.EventId) { return(new TokenValidationResult(false, "eventid")); } if (queueParams.TimeStamp < DateTime.UtcNow) { return(new TokenValidationResult(false, "timestamp")); } return(new TokenValidationResult(true, null)); }