Skip to content

Authentication

Soxom supports four authentication methods, configured via OpenAPI security schemes or soxom.yaml.

MethodOpenAPI TypeDescription
Bearer Tokenhttp: bearerJWT or opaque tokens
API KeyapiKeyHeader or query parameter
Basic Authhttp: basicUsername/password
OAuth 2.0oauth2Client credentials, authorization code
authentication:
# Primary auth method (from OpenAPI securitySchemes)
default: bearer
# Environment variable mappings
env_vars:
bearer:
token: MY_API_TOKEN
api_key:
key: MY_API_KEY
basic:
username: MY_USERNAME
password: MY_PASSWORD
oauth2:
client_id: MY_CLIENT_ID
client_secret: MY_CLIENT_SECRET
# OAuth 2.0 specific settings
oauth2:
token_url: https://api.example.com/oauth/token
auto_refresh: true
default_scopes:
- read
- write

Define security schemes in your OpenAPI spec:

components:
securitySchemes:
bearerAuth:
type: http
scheme: bearer
bearerFormat: JWT
apiKey:
type: apiKey
in: header
name: X-API-Key
basicAuth:
type: http
scheme: basic
oauth2:
type: oauth2
flows:
clientCredentials:
tokenUrl: https://api.example.com/oauth/token
scopes:
read: Read access
write: Write access

The most common authentication method for modern APIs.

authentication:
default: bearer
env_vars:
bearer:
token: ACME_API_TOKEN
import { Client } from 'my-sdk';
// Direct token
const client = new Client({
token: "your-api-token"
});
// From environment (automatic)
const client = new Client();
// Uses process.env.ACME_API_TOKEN

For APIs using API key authentication in headers or query parameters.

authentication:
default: api_key
env_vars:
api_key:
key: ACME_API_KEY
const client = new Client({
apiKey: "your-api-key"
});

For APIs using HTTP Basic authentication.

authentication:
default: basic
env_vars:
basic:
username: ACME_USERNAME
password: ACME_PASSWORD
const client = new Client({
username: "user",
password: "pass"
});

For APIs using OAuth 2.0 with client credentials or authorization code flow.

authentication:
default: oauth2
env_vars:
oauth2:
client_id: ACME_CLIENT_ID
client_secret: ACME_CLIENT_SECRET
oauth2:
token_url: https://api.example.com/oauth/token
auto_refresh: true
default_scopes:
- read
- write
// Client credentials flow
const client = new Client({
clientId: "your-client-id",
clientSecret: "your-client-secret"
});
// Token is automatically fetched and refreshed
const users = await client.users.list();

Override authentication for specific operations in your OpenAPI spec:

paths:
/public/health:
get:
security: [] # No auth required
responses:
"200":
description: Health status
/admin/users:
get:
security:
- oauth2: [admin:read] # Requires admin scope
responses:
"200":
description: Admin users list

Soxom generates SDKs that automatically read from environment variables:

Auth MethodDefault Env VarCustomizable
Bearer{SDK_NAME}_API_TOKENYes
API Key{SDK_NAME}_API_KEYYes
Basic{SDK_NAME}_USERNAME, {SDK_NAME}_PASSWORDYes
OAuth 2.0{SDK_NAME}_CLIENT_ID, {SDK_NAME}_CLIENT_SECRETYes

Customize with env_vars in soxom.yaml.