Gateway Authentication
Every gateway request is authenticated before any tool runs. almyty is default-deny: a gateway with no auth configured rejects all requests with 401. You add auth once, and it guards every transport (MCP, UTCP, A2A) on that gateway.

Add auth in the UI
- Open a gateway’s detail page and click the Authentication tab
- Click Add Auth Method
- Select a type: API Key, Bearer Token, Basic Auth, JWT, OAuth 2.1, or None
- Fill in the configuration and click Save
To issue API keys, click Manage Keys after adding an API Key or Bearer Token method. The raw key is shown once at creation time, then stored only as a SHA-256 hash. Keys support optional expiry, scopes, and lastUsedAt tracking.
A generated key looks like this (the key field appears only in this one response):
{
"id": "key-uuid",
"name": "Production Key",
"key": "almyty_gw_abc123...",
"scopes": ["tools:read", "tools:execute"],
"expiresAt": "2027-01-01T00:00:00Z"
}Authentication methods
| Method | Header / Parameter | Use case |
|---|---|---|
| None | (none) | Public/development gateways (must be set explicitly) |
| API Key | X-API-Key header or api_key query param | Machine-to-machine |
| Bearer Token | Authorization: Bearer <token> | Programmatic access |
| Basic Auth | Authorization: Basic <base64> | Legacy integrations |
| JWT | Authorization: Bearer <jwt> | Signed, self-contained tokens |
| OAuth 2.1 | Authorization: Bearer <oauth-token> | Full authorization code flow with PKCE |
API Key and Bearer Token
Pass the key one of three ways: an X-API-Key header, an api_key query parameter, or an Authorization: Bearer header. In an MCP client config, set it as a header:
{
"mcpServers": {
"petstore": {
"url": "https://api.almyty.com/acme/petstore",
"headers": { "x-api-key": "almyty_gw_abc123..." }
}
}
}Basic Auth
Decodes the Authorization: Basic header, looks up the user by email, and verifies the password with bcrypt.
JWT
Verifies the JWT signature using the secret configured on the auth method (or the server’s JWT_SECRET as a fallback). The payload must contain sub or userId.
Enforcement pipeline
Every request to a gateway endpoint passes through the same pipeline:
- Resolve the organization and gateway from the URL
- Load all active auth configs for that gateway
- If no auth configs exist, reject with 401
- Try each required auth method in order: first success wins
- If all fail, reject with the last error (401 or 403)
- If valid, execute the request
Discovery endpoints (.well-known/*, Agent Cards) are always public.
OAuth 2.1 (MCP OAuth)
almyty implements a full OAuth 2.1 authorization server per the MCP specification:
- Authorization Code flow with PKCE (S256 mandatory)
- Dynamic Client Registration (RFC 7591)
- Token Revocation (RFC 7009)
- Authorization Server Metadata (RFC 8414)
- Protected Resource Metadata (RFC 9728)
MCP clients handle this flow for you. On a 401, the gateway returns a WWW-Authenticate header pointing at the protected resource metadata, and a compatible client registers itself, runs the authorization code exchange, and attaches the token automatically.
Discovery endpoints
https://api.almyty.com/acme/petstore/.well-known/oauth-authorization-server
https://api.almyty.com/acme/petstore/.well-known/oauth-protected-resourceFlow endpoints
| Endpoint | Purpose |
|---|---|
POST /acme/petstore/register | Dynamic Client Registration |
GET /acme/petstore/authorize | Start the authorization code flow (with code_challenge, code_challenge_method=S256) |
POST /acme/petstore/token | Exchange the code (plus code_verifier) for tokens |
Token lifetimes
| Token | Lifetime |
|---|---|
| Access token | 1 hour |
| Refresh token | 30 days |
| Authorization code | 10 minutes |
Refresh tokens rotate on use. Revoking a refresh token also revokes its access tokens.
Validation rules
Auth methods can carry extra validation. Restrict by IP range:
{
"validationRules": {
"allowedIpRanges": ["10.0.0.0/8", "192.168.1.100"]
}
}Or require specific headers:
{
"validationRules": {
"requiredHeaders": ["X-Request-Id", "X-Client-Version"]
}
}Key scopes
| Scope | Description |
|---|---|
tools:read | List and view tool definitions |
tools:execute | Execute/invoke tools |
gateway:read | View gateway configuration |
Multiple auth methods
A gateway can carry several auth methods, each marked required or optional. Required methods are tried in order (first match wins), so you can combine them for a gradual migration, for example adding OAuth while keeping API keys active.