Search code examples
proxybasic-authenticationsocat

Bypassing HTTP basic auth locally


I have two applications which I cannot change:

A: provides a URL protected by HTTP basic auth. B: needs to access this URL but does not support basic auth. Credentials are available.

How can I make my two applications work together?

I thought a local proxy might be great which injects the authentication. E.g. using socat:

socat TCP4-LISTEN:81,reuseaddr,fork TCP:UrlToA:80,<inject-basic-auth>=user:pass

However, socat does not provide an option like < inject-basic-auth >. Anybody knows any tool that might help? Any other way out?


Solution

  • You must set up a HTTP reverse proxy server that does the authentication for you. No need to hack any software.

    Your reverse proxy listens on some socket (e.g. proxy:8080) and forwards requests to your actual application A, inserting the headers.

    client_B ----> http://proxy:8080 -----> http://server_A:80

    Nginx is lightweight, high performance and easy to set up. And it's easy to find docs online for what you want. See for example http://wiki.apache.org/couchdb/Nginx_As_a_Reverse_Proxy