Step 1 of 4
Credentials injected at startup
The configuration refers to the client secret or signing key as ${env:NAME} or ${vault:path:key}. The relay resolves them when it starts, and masks them in every log line.
Open source OAuth 2.0 token relay
OAUTH2Relay gets the access token, keeps it in memory, renews it before it expires and adds it to every request your services make. Credentials come from your environment or your secrets manager, never from code.
What is OAUTH2Relay?
OAUTH2Relay sits between your services and an API that needs OAuth 2.0. It logs in to the identity provider, holds the access token in memory, and adds it to each request it relays. Your services call the relay with no token logic of their own. Tokens are never written to disk or a database, and the client secret or signing key comes from an environment variable or a secrets manager, so the configuration file holds no secrets.
Access and refresh tokens live in process memory and disappear when the relay stops.
${env:NAME} placeholders, or AWS Secrets Manager, HashiCorp Vault and Azure Key Vault.
The token is renewed at 80% of its lifetime, by refresh token or a new login, so requests never wait for it.
Health checks, Prometheus metrics, structured JSON logs, TLS and graceful shutdown built in.
Built for server-to-server integrations: backend services, batch jobs and platforms that call third-party or internal APIs protected by OAuth 2.0.
Advantages
${env:NAME} or a secrets manager.--check-config validates a configuration in CI before it is deployed.503 during an outage so they can retry, and recover without a restart.How does it work?
Your service OAUTH2Relay (token in memory) Third-party API
Step 1 of 4
The configuration refers to the client secret or signing key as ${env:NAME} or ${vault:path:key}. The relay resolves them when it starts, and masks them in every log line.
Step 2 of 4
The relay obtains an access token with the client credentials, JWT bearer or password grant, retrying with backoff if the provider is unavailable. It reports ready once it holds a token.
Step 3 of 4
Each request your services send is relayed with the token added. Before the token expires it is renewed in the background, by refresh token or a new login, so no request waits.
Step 4 of 4
On shutdown the relay finishes in-flight requests and exits. The tokens existed only in memory, so nothing remains on disk to steal.
tls, or put the relay behind a TLS-terminating proxy.apiKey so only your services can call the relay.Use cases
Any service that calls an OAuth 2.0 protected API can hand the token work to OAUTH2Relay and keep credentials out of its own code.
Run one relay per API as a shared service or a sidecar, so every service calls the API without its own token handling.
Credentials from Kubernetes Secrets, Vault or workload identity; probes, metrics and certificate reload included.
Short-lived functions call a relay running as a service and get a ready token, instead of logging in on every cold start.
Payment, logistics and SaaS APIs that issue client credentials: one relay holds the token, with the secret kept in your vault.
Finance and healthcare teams keep credentials in an audited secrets manager and tokens off disk, with every request logged.
A single static binary with no database runs on small servers and gateways, and its tokens vanish on reboot.
Technical highlights
Write ${env:API_CLIENT_SECRET} in the configuration and OAUTH2Relay reads the variable at startup, so the file itself never holds a secret. An unset variable stops the relay with a clear error.
$ export API_CLIENT_SECRET='s3cr3t!'
$ cat config.json
{
"port": 8080,
"host": "127.0.0.1",
"login": {
"url": "https://auth.example.com/oauth/token",
"grant_type": "client_credentials",
"client_id": "my-service",
"client_secret": "${env:API_CLIENT_SECRET}"
},
"relay": {
"url": "https://api.example.com/v1",
"headers": { "Authorization": "Bearer ${ACCESSTOKEN}" }
}
}
$ oauth2relay --check-config --config config.json
config.json: configuration is valid
$ oauth2relay --config config.json
$ curl http://127.0.0.1:8080/orders # relayed to /v1/orders with the token
Download
Each archive holds the binary, the licence, the documentation and a hardened systemd unit. Verify the download against SHA256SUMS before installing it.
$ sha256sum -c SHA256SUMS --ignore-missing
oauth2relay_2.1.0_linux_amd64.tar.gz: OK
$ tar xzf oauth2relay_2.1.0_linux_amd64.tar.gz
$ sudo install -m 0755 oauth2relay_2.1.0_linux_amd64/oauth2relay /usr/local/bin/
$ oauth2relay --version
OAUTH2Relay version 2.1.0
Open source
FAQ
${env:NAME}, injected by Kubernetes Secrets, systemd or your container platform, or fetch them from AWS Secrets Manager, HashiCorp Vault or Azure Key Vault. See Secrets.client_credentials, JWT bearer (RFC 7523) or password grant, including signed assertions with RSA, RSA-PSS and ECDSA keys as used by Google service accounts and Salesforce. Providers with their own login format can use a custom request. See Grant types.passthrough mode, the request path is appended to a base URL, so one relay covers a whole API. In parameter mode, callers pass the full target URL in a parameter, and it must point to a host in your allowed_hosts list. One relay uses one identity provider configuration. See Relay modes./metrics with Prometheus and use /healthz and /readyz for liveness and readiness. The operations guide lists the alerts to set, such as failing token renewals and an expiring TLS certificate.Contact us
Questions about OAUTH2Relay, commercial support or the enterprise edition? Send us a message.