Пример #1
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")));
        }
Пример #2
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());
        }