Step 1 of 4
Secure Credential Injection
Configure user, password, and authstring in your config file to reference environment variables (e.g., $API_USER).
OAuth2 token relay
Secure OAuth2 token management without hard-coded credentials. Tokens live only in memory; credentials come from your environment.
What is OAUTH2Relay?
OAUTH2Relay is a secure, lightweight middleware designed to simplify OAuth2 token management for third-party API integrations. Unlike traditional solutions, it never stores tokens on disk or in databases—tokens reside exclusively in memory and are wiped at process termination. Credentials (username/password) are sourced securely from environment variables or secrets managers, ensuring no sensitive data is hard-coded in configuration files.
Tokens live only in volatile memory, erased on process shutdown.
Configuration values (username, password, auth strings) can reference environment variables for airtight security.
Seamlessly renews access tokens using refresh tokens, falling back to re-authentication when needed.
Eliminates risks of credential leakage in config files or logs.
Ideal for developers and enterprises prioritizing security, compliance, and simplicity in API integrations (e.g., finance, healthcare, or cloud-native apps).
Advantages
How does it work?
Your App OAUTH2Relay (In-Memory Tokens + Env Vars) Third-Party API
Step 1 of 4
Configure user, password, and authstring in your config file to reference environment variables (e.g., $API_USER).
Step 2 of 4
On launch, OAUTH2Relay fetches credentials from environment variables and authenticates with the third-party API. Initial tokens (access + refresh) are stored in memory.
Step 3 of 4
For each API request, a valid access token is injected automatically. If expired, the in-memory refresh token is used to obtain a new access token or re-authenticate if necessary.
Step 4 of 4
All tokens are purged from memory instantly, ensuring no credential traces remain after process termination or crashes.
Security best practices
Use cases
From serverless functions to edge devices, OAUTH2Relay keeps credentials out of code and tokens out of storage.
Securely integrate with APIs in Kubernetes, AWS Lambda, or Azure Functions, using cloud-native secrets management.
Safely authenticate with APIs during deployments (e.g., Terraform, GitHub Actions) without exposing credentials in scripts.
Process payments via Stripe or PayPal without risking credential leaks, even in high-availability environments.
Connect to HIPAA-compliant EHR systems (e.g., Epic) with credentials sourced from audited secrets managers.
Securely allow stateless services to access third-party APIs, with tokens scoped to each service's lifecycle.
Manage API tokens for devices with limited storage—credentials are injected at runtime, and tokens vanish on reboot.
Technical highlights
Reference variables like ${ENV_API_USER} in the config file and OAUTH2Relay resolves them at startup, so the file itself never holds a secret.
# Example: Launching OAUTH2Relay with environment variables
export ENV_API_USER="client_123"
export ENV_API_PASSWORD="s3cr3t!"
$ cat oauth2relay.json
{
"port": 8080,
"host": "0.0.0.0",
"debug": true,
"logfile": "oauth2relay.log",
"login": {
"user": "${ENV_API_USER}",
"password": "${ENV_API_PASSWORD}",
...
},
...
}
./oauth2relay start --config oauth2relay.json
FAQ
Contact us
If you have questions or need further assistance, please fill out the form below.
User guide
This guide provides detailed configuration information for OAUTH2Relay using a sample config.json file.
{
"port": 8080,
"host": "0.0.0.0",
"debug": true,
"logfile": "oauth2relay.log",
"login": {
"user": "YOUR_USERNAME",
"password": "YOUR_PASSWORD",
"authstring": "${YOUR_AUTHSTRING}",
"refreshtoken": "",
"method": "GET",
"data": "",
"url": "https://saas.example.com/login",
"headers": {
"Authorization": "Basic ${AUTHSTRING}"
},
"parameters": {
"AccessToken": "AccessToken",
"ExpiresIn": "ExpiresIn",
"ExpiresAt": "ExpiresAt",
"TokenType": "TokenType",
"RefreshToken": "RefreshToken"
}
},
"refresh": {
"token": "",
"method": "POST",
"data": "{\"token\": \"${REFRESHTOKEN}\"}",
"url": "https://saas.example.com/refresh",
"headers": {
"Authorization": "${REFRESHTOKEN}"
},
"parameters": {
"AccessToken": "AccessToken",
"ExpiresIn": "ExpiresIn",
"ExpiresAt": "ExpiresAt",
"TokenType": "TokenType",
"RefreshToken": "RefreshToken"
}
},
"relay": {
"url": "https://saas.example.com/",
"method": "GET",
"type": "json",
"fixedtoken": "",
"data": "",
"parameters": {
"country_code": "US"
},
"headers": {
"Authorization": "Bearer ${ACCESSTOKEN}",
"Content-Type": "application/json"
}
}
}
These parameters configure the middleware server:
host: The IP address or hostname (e.g., "0.0.0.0" for all interfaces).port: The TCP port (e.g., 8080).debug: Boolean flag for detailed logging (true or false).logfile: File path for log messages (e.g., "oauth2relay.log").This section configures the authentication flow to obtain initial tokens:
user: The client/user identifier.password: The client's password.authstring: A base64 encoded string (from user:password).refreshtoken: Populated upon authentication success.method: HTTP method (e.g., "GET").url: Endpoint for the login process.headers: Additional HTTP headers used during login.parameters: Mapping of response fields (e.g., AccessToken, ExpiresIn, etc.).This section explains how to obtain a new access token when needed:
token: Current refresh token storage (initially empty).method: HTTP method for token refresh (e.g., "POST").data: JSON payload containing a placeholder for the refresh token (${REFRESHTOKEN}).url: Endpoint for refreshing tokens.headers: Additional headers for the refresh call.parameters: Mapping for response fields (e.g., AccessToken, ExpiresIn, etc.).This section configures how the middleware relays API requests once a valid token is available:
url: The target API endpoint for relayed requests.method: HTTP method for relay (e.g., "GET").type: Request payload type (e.g., "json").fixedtoken: Optional fixed token parameter (left empty for dynamic management).data: Additional data payload if needed.parameters: Fixed key-value pairs for the relay process.headers: HTTP headers for the relay call, including dynamic insertion of the access token.