Authentication¶
The Redis Agent Memory Server supports multiple authentication modes for secure API access. All API endpoints (except /health
, /docs
, and /openapi.json
) require valid authentication unless disabled for development.
Authentication Modes¶
The server supports three authentication modes:
- Disabled (default): No authentication required - suitable for development only
- Token Authentication: Simple API tokens stored in Redis with optional expiration
- OAuth2/JWT: Industry-standard authentication using JWT access tokens
Features¶
- Simple Token Authentication: Generate and manage API tokens via CLI with optional expiration
- OAuth2/JWT Bearer Token Authentication: Industry-standard authentication using JWT access tokens
- JWKS Public Key Validation: Automatic fetching and caching of public keys for token signature verification
- Multi-Provider Support: Compatible with Auth0, AWS Cognito, Okta, Azure AD, and any standard OAuth2 provider
- Flexible Configuration: Environment variable-based configuration for different deployment scenarios
- Development Mode:
DISABLE_AUTH
setting for local development and testing - Role and Scope Support: Fine-grained access control using JWT claims
- CLI Token Management: Create, list, view, and remove tokens via command line
Configuration¶
Basic Configuration¶
Authentication is configured using environment variables:
# Authentication Mode Selection
AUTH_MODE=disabled # Options: disabled, token, oauth2 (default: disabled)
# OR legacy setting:
DISABLE_AUTH=true # Set to true to bypass all authentication (development only)
# Token Authentication (when AUTH_MODE=token)
TOKEN_AUTH_ENABLED=true # Alternative way to enable token auth
# OAuth2 Provider Configuration (when AUTH_MODE=oauth2)
OAUTH2_ISSUER_URL=https://your-auth-provider.com
OAUTH2_AUDIENCE=your-api-audience
OAUTH2_JWKS_URL=https://your-auth-provider.com/.well-known/jwks.json # Optional, auto-derived from issuer
OAUTH2_ALGORITHMS=["RS256"] # Supported signing algorithms
Token Authentication Setup¶
To use token authentication:
-
Enable token authentication:
-
Create tokens using the CLI:
-
Use the token in API requests:
Token Management Commands¶
The CLI provides comprehensive token management:
# List all tokens (shows masked token hashes)
uv run agent-memory token list
# Show details for a specific token (supports partial hash matching)
uv run agent-memory token show abc12345
# Remove a token (with confirmation)
uv run agent-memory token remove abc12345
# Remove a token without confirmation
uv run agent-memory token remove abc12345 --force
Security Features: - Tokens are hashed using bcrypt before storage - Only hashed values are stored in Redis (server never has access to plaintext tokens) - Automatic expiration using Redis TTL - Secure token generation using secrets.token_urlsafe()
OAuth2 Provider Examples¶
Auth0¶
AWS Cognito¶
OAUTH2_ISSUER_URL=https://cognito-idp.region.amazonaws.com/your-user-pool-id
OAUTH2_AUDIENCE=your-app-client-id
Okta¶
Azure AD¶
OAUTH2_ISSUER_URL=https://login.microsoftonline.com/your-tenant-id/v2.0
OAUTH2_AUDIENCE=your-application-id
Usage Examples¶
With Token Authentication¶
# First, create a token
uv run agent-memory token add --description "My API token" --expires-days 30
# Use the returned token in API requests
curl -H "Authorization: Bearer YOUR_API_TOKEN" \
-H "Content-Type: application/json" \
http://localhost:8000/v1/working-memory/
# Python example
import httpx
headers = {
"Authorization": "Bearer YOUR_API_TOKEN",
"Content-Type": "application/json"
}
response = httpx.get("http://localhost:8000/v1/working-memory/", headers=headers)
With OAuth2/JWT Authentication¶
# Make authenticated API request with JWT
curl -H "Authorization: Bearer YOUR_JWT_TOKEN" \
-H "Content-Type: application/json" \
http://localhost:8000/v1/working-memory/
# Python example
import httpx
headers = {
"Authorization": "Bearer YOUR_JWT_TOKEN",
"Content-Type": "application/json"
}
response = httpx.get("http://localhost:8000/v1/working-memory/", headers=headers)
Development Mode (Local Testing)¶
# Set environment variable to disable auth
export DISABLE_AUTH=true
# Now you can make requests without tokens
curl -H "Content-Type: application/json" \
http://localhost:8000/v1/working-memory/
Token Requirements¶
API Tokens (Token Authentication)¶
- Valid token: Must exist in Redis and not be expired
- Secure generation: Generated using cryptographically secure random bytes
- Optional expiration: Tokens can be created with or without expiration dates
JWT Tokens (OAuth2 Authentication)¶
JWT tokens must include:
- Valid signature: Verified using JWKS public keys from the issuer
- Not expired:
exp
claim must be in the future - Valid audience:
aud
claim must matchOAUTH2_AUDIENCE
(if configured) - Valid issuer:
iss
claim must matchOAUTH2_ISSUER_URL
- Subject:
sub
claim identifying the user/client
Error Responses¶
Authentication failures return HTTP 401 with details:
Common error scenarios:
General Authentication Errors: - Missing authorization header
: No Authorization: Bearer
header provided - Missing bearer token
: Empty or malformed authorization header
Token Authentication Errors: - Invalid token
: Token not found in Redis or malformed - Token has expired
: Token expiration date has passed
OAuth2/JWT Authentication Errors: - Invalid token header
: Malformed JWT structure - Token has expired
: JWT exp
claim is in the past - Invalid audience
: JWT aud
claim doesn't match expected audience - Unable to find matching public key
: JWKS doesn't contain key for token's kid
Security Best Practices¶
General Security¶
- Never use
DISABLE_AUTH=true
in production - Use HTTPS in production to protect tokens in transit
- Monitor authentication failures and implement rate limiting if needed
- Handle 401 responses appropriately in your clients
- Validate tokens server-side - never trust client-side validation alone
Token Authentication Security¶
- Use token expiration when creating tokens for enhanced security
- Rotate tokens regularly by removing old tokens and creating new ones
- Store tokens securely in your applications (use environment variables, not code)
- Remove unused tokens using the CLI to minimize attack surface
- Monitor token usage and remove tokens that are no longer needed
OAuth2/JWT Security¶
- Implement token refresh in your clients for long-running applications
- Use appropriate scopes/roles for fine-grained access control
- Validate token expiration and audience claims properly
- Cache JWKS appropriately but refresh periodically
Manual Testing¶
For comprehensive Auth0 testing instructions, see the manual OAuth testing guide.