Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No support for setting up proxy server #21

Open
lanzer-gaia opened this issue Nov 30, 2024 · 4 comments
Open

No support for setting up proxy server #21

lanzer-gaia opened this issue Nov 30, 2024 · 4 comments

Comments

@lanzer-gaia
Copy link

We have our web servers behind a load balancer and all outgoing calls are routed through a proxy server.

It's easy enough to manually specify the proxy parameter in PaypalServerSdkClient on line 61, but it would be good for the SDK to allow overriding the config options for the Apimatic UniRest client builder.

@LeonarthusMectus
Copy link

Hey @lanzer-gaia

Can you elaborate a bit on the problem you're seeing? I want to make sure I understand the disconnect between setting the proxy and the underlying client using the value properly, or why you'd be interested in directly controlling the SDK's HTTP client.

@lanzer-gaia
Copy link
Author

Sure thing.

Some servers out there sit inside a firewall and have no external IP address for security reasons. A load balancer will direct external traffic to those servers and they have no problem responding to those clients as the TCP connection had already been setup. Those servers cannot initiate outgoing connections to the Internet for security reasons, and any applications must route outgoing requests through a proxy server which grants or deny access based on our access control list. It's kind of like having a default gateway, except the gateway is a firewall and is specified on the application layer instead of automatically handled by the operating system's networking layer.

More information on SOCKS proxy server
https://securityintelligence.com/posts/socks-proxy-primer-what-is-socks5-and-why-should-you-use-it/

When using CURL in PHP all you need to do is to specify the IP address and port number of the proxy server you're using:
https://stackoverflow.com/questions/5211887/how-to-use-curl-via-a-proxy

Pretty much any HTTP libraries for PHP will have support for proxy servers, including Unirest which the PayPal-PHP-Server-SDK uses. You can setup proxy as per their doc at (https://github.com/Kong/unirest-php?tab=readme-ov-file#proxy):
// custom port and proxy type Unirest\Request::proxy('10.10.10.1', 8080, CURLPROXY_HTTP);
Unirest's configurator (Unirest\Configuration) support the option of declaring proxy server as well as proxy server auth if authentication is required.

I just manually specified the config in the Paypal Client.
PaypalServerSdkClient.php line 61:
$this->client = ClientBuilder::init(new HttpClient(Configuration::init($this)->proxy('our.internal.hostname', 3128)))

Though currently the Paypal server SDK client builder already support most of the Unirest\Configuration options such as timeout, enableRetries, retryInterval, etc. We just need proxy and proxyAuth to be added. (/apimatic/unirest-php/src/Configuration.php line 284 & 300)

@8ctopus
Copy link

8ctopus commented Dec 5, 2024

See #13

@LeonarthusMectus
Copy link

Ah, I see.

I had mistakenly thought that the Client/Client Builder had the ability to set the proxy but it appears I was quite mistaken. There definitely does not appear to be a setter/config opt for proxies, which yeah, would present a problem for your (and most) setups.

Let me see what we can do to get this added to the client and exposed the right way.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants