Пример #1
0
        public IResponseBase Execute(IRequestParameter parameters)
        {
            try
            {
                if (null == parameters)
                {
                    parameters = new InitRequest();
                }

                RequestHeaderHelper.GetClientIP(_core);
                _request = (InitRequest)parameters;
                GetDashByDate();
                GetCartDetails();
                GetCheckout();
                SetMenuAndBrands();
                SetSessionInfo();
                SetPingdomStatus();
                //SetLatLonPosition();
                SetEnvironment();
            }
            catch (Exception ex)
            {
                string errorMsg = string.Format("({0}){1}", ex.Message, ex.StackTrace);
                _result.errors.Add(ex.Handle("Init: " + errorMsg, ErrorSeverity.FollowUp, ErrorType.RequestError));
            }
            //FIX ME:CPEREZ. Make me a stand along service to be call from front-end
            _result.resultset.GeoLat = 0;
            _result.resultset.GeoLon = 0;
            return(_result);
        }
Пример #2
0
        protected override async Task <AuthenticateResult> HandleAuthenticateAsync()
        {
            // Get Authorization header value
            var schemeToken = RequestHeaderHelper.GetSchemeAndToken(Request);

            if (string.IsNullOrEmpty(schemeToken.Key) || string.IsNullOrEmpty(schemeToken.Value))
            {
                _logger.LogDebug($"Failed - Schema token Key: {schemeToken.Key}");
                _logger.LogDebug($"Failed - Schema token Value: {schemeToken.Value}");
                return(await Task.FromResult(AuthenticateResult.Fail("Authorization header is unrecognized")));
            }

            var scheme = schemeToken.Key.ToLower();
            var token  = schemeToken.Value;

            if (scheme.Equals("hubtel-bearer", StringComparison.OrdinalIgnoreCase))
            {
                if (ValidateClientIp(Request) && ValidateApiToken(token, out HubtelProfile hubtelProfile))
                {
                    return(await HubtelBearerAuthenticateAsync(scheme, hubtelProfile));
                }
            }

            if (scheme.Equals("bearer", StringComparison.OrdinalIgnoreCase))
            {
                if (ValidateApiJwtToken(token, out ClaimsPrincipal principal))
                {
                    return(await JwtAuthenticateAsync(scheme, principal));
                }
            }

            return(await Task.FromResult(AuthenticateResult.Fail("Authorization Failed")));
        }
Пример #3
0
        public override void RebuildRequest()
        {
            OverrideUserAgent = Config.Params.UserAgent;
            OverrideUseSgmlReaderForConversion            = false;
            OverrideUseCorsisForConversion                = true;
            OverrideUseRemoteCorsisForConversion          = true;
            OverrideUseCustomAttributesInCorsisConversion = true;
            OverrideExpect100               = true;
            OverrideSecurityProtocol        = SecurityProtocolType.Tls11;
            OptionalPreserveOriginalRawData = true;

            Headers.Add("Authorization", "Basic c3RvcmVmcm9udDpyZXZvbHV0aW9u");
            Headers.Add(Config.Params.ClientIPHeader, RequestHeaderHelper.GetClientIP(Core));
            base.RebuildRequest();
        }
Пример #4
0
 private void SetSessionInfo()
 {
     try
     {
         _result.resultset.ClientIP = RequestHeaderHelper.GetClientIP(_core);
         _result.resultset.ID       = EnvironmentHelper.GetLastIPAddressOctet();
         if (_core.Context.Session != null)
         {
             _result.resultset.SessionID = _core.Context.Session.SessionID;
         }
     }
     catch (Exception ex)
     {
         _result.errors.Add(ex.Handle("Init.SetSessionInfo: " + ex, ErrorSeverity.FollowUp, ErrorType.RequestError));
     }
 }
Пример #5
0
        public async Task <IActionResult> RelayRequest([FromBody] ProxyRequest proxyRequest)
        {
            var schemeToken = RequestHeaderHelper.GetSchemeAndToken(Request);

            try
            {
                using (var response = await MakeHttpRequest(proxyRequest, schemeToken.Key, schemeToken.Value))
                {
                    return(await ActionResultAsync(response));
                }
            }
            catch (Exception ex)
            {
                _logger.LogError("Pos proxy failed: " + ex.Message);
            }
            return(BadRequest());
        }
Пример #6
0
        private bool ValidateApiToken(string token, out HubtelProfile hubtelProfile)
        {
            var authKey = _configuration["HubtelAuth:Key"];

            var headerStr = RequestHeaderHelper.Base64Decode(token);

            string[] stringSeparators = new string[] { ":" };
            var      headerStrArr     = headerStr.Split(stringSeparators, 2, StringSplitOptions.None);
            var      basicKeys        = $"{headerStrArr[0]}";

            if ($"{authKey}".Equals(basicKeys))
            {
                hubtelProfile = JsonConvert.DeserializeObject <HubtelProfile>(headerStrArr[1]);
                return(true);
            }
            hubtelProfile = null;
            return(false);
        }