This is a simple proxy responsible for redirecting authenticated requests using the Authorization Basic user:password header to Lokalise, which currently uses CSRF token-based authentication. The proxy handles cases where the user is not authenticated and lacks those headers by generating new ones using the Authorization header and transparently injecting them into the user's browser."
- Proxy Handler: Intercepts HTTP requests and checks for necessary authentication headers and tokens.
- Cookie and CSRF Token Management: Automatically retrieves and manages login cookies and CSRF tokens.
- Authorization Header Support: Extracts user credentials from the
Authorization
header if cookies and tokens are missing. - Forward Requests: Proxies the request to a target server after successful authentication.
- Go 1.18+
- Target server must support cookie-based authentication with CSRF tokens via Set-Cookie headers.
LOKALISE_URL
: The URL of the target server to which requests should be proxied (default ishttps://app.lokalise.com
)LISTEN_PORT
: The port on which the proxy server will listen (default is8080
).LOGIN_POST_PATH
: The Login URL where the proxy sends the POST request to get the authenticated CSRF token.
-
Clone the repository:
git clone https://github.com/yourusername/lokalise-proxy-authenticator.git
-
Navigate to the project directory:
cd lokalise-proxy-authenticator
-
Build the Go binary:
make build
-
Set the environment variables
export LOKALISE_URL="https://app.lokalise.com" # Optional, default is https://app.lokalise.com export LISTEN_PORT="8080" # Optional, default is 8080 export LOGIN_POST_PATH="/login/signin" # Optional, default is /login/signin
-
Run the proxy server
make run
-
The proxy server will start on the port specified in LISTEN_PORT (default: 8080), and it will forward authenticated requests to the LOKALISE_URL.
- cmd/main.go: Main file containing the proxy logic.
- internal/utils.go: Contains utility functions for handling authentication, such as:
- ExtractCredentialsFromAuth: Extracts email and password from the Authorization header.
- GetInitialCookie: Fetches the initial cookie and CSRF token for the login session.
- GetLoginCookie: Logs in using the credentials and returns the authenticated cookie.
- Makefile: Useful commands for build, test and run the code.
- Dockerfile: For building the docker image
- charts: Helm chart for the application
- .github: CI/CD tools for github repository.
curl -X GET http://localhost:8080/your-path \
-H "Authorization: Basic base64encodedcredentials" \
If the request lacks the Authorization, Cookie, or CSRF token, the proxy server will attempt to authenticate and retrieve them before forwarding the request.
This project is licensed under the MIT License.
Feel free to replace any placeholders like yourusername
in the repository URL.