Configure Agent Memory Authentication
- how-to
Secure Agent Memory with OIDC/OAuth2 authentication by connecting it to your external identity provider (IdP).
Agent Memory acts as a stateless resource server that validates JWT access tokens issued by an IdP. Agent Memory never issues tokens or stores secrets such as client credentials or refresh tokens. Agent Memory validates each request independently using a cached JSON Web Key Set (JWKS) fetched from your IdP.
You can connect Agent Memory to any OIDC-compliant identity provider, including:
Prerequisites
-
You have an identity provider that supports OIDC and is reachable over HTTPS.
-
Your IdP meets the following technical requirements:
- OIDC Discovery endpoint
-
Your IdP must expose a discovery document at
/.well-known/openid-configuration. - JWKS endpoint
-
The discovery document must contain a
jwks_urifield pointing to the JSON Web Key Set endpoint. - RS256 signing algorithm
-
Access tokens must be signed with RS256 (RSA + SHA-256).
- Key ID (
kid) claim -
The JWT header must include a
kidclaim for key lookup against the JWKS endpoint. - Standard claims
-
Access tokens must include the following claims:
iss,aud,exp.
Procedure
To configure authentication for Agent Memory:
-
Configure a client in your IdP.
The steps to configure a client in your IdP vary by provider. For more information, see your IdP’s documentation. When configuring your client, make sure to complete the following:
-
Create a new client or application. Use a
confidentialclient type with theclient credentialsgrant (service account), so that your application can obtain tokens without user interaction. -
Set the signing algorithm to
RS256. -
Note the following values for the next step:
- Issuer URL
-
The base URL of your IdP realm or tenant, for example
https://your-idp.example.com/realms/myrealm. - Audience
-
The
audvalue that appears in access tokens, typically the client ID or a custom API identifier. - Client ID and Client secret
-
Your application uses these to obtain access tokens from the IdP.
-
-
Add the following environment variables to the
.envfile in your Agent Memory project directory:OIDC_AUTH_ENABLED=true OIDC_ISSUER=$OIDC_ISSUER_URL OIDC_AUDIENCE=$OIDC_AUDIENCEReplace each
$placeholder with the values from your IdP client configuration. For a description of all available variables, see Environment Variables. -
Recreate the Agent Memory container to apply the new environment variables:
This command briefly interrupts the Agent Memory service. In-flight requests fail until the new container is ready. docker compose up -d --force-recreate agentmemory-serverOn startup, Agent Memory fetches and caches the JWKS from your IdP. The JWKS cache has no expiry time and persists until Agent Memory encounters a token signed with an unrecognized
kid, at which point it re-fetches the JWKS once. If your IdP rotates key material while reusing the samekid, Agent Memory cannot detect the change automatically and continues to use the old key until you restart the container. The logs include the following message:OIDC authentication initialized issuer=\https://your-idp.example.com/realms/myrealm -
Verify that authentication is working by sending a request with a Bearer token.
-
Obtain an access token from your IdP using the client credentials flow:
TOKEN=$(curl -s -X POST "$IDP_TOKEN_ENDPOINT" \ -H "Content-Type: application/x-www-form-urlencoded" \ -d "grant_type=client_credentials" \ -d "client_id=$CLIENT_ID" \ -d "client_secret=$CLIENT_SECRET" \ | jq -r '.access_token') -
Send an authenticated request to Agent Memory:
curl -X POST "https://$AGENTMEM_HOST/users" \ -H "Authorization: Bearer $TOKEN" \ -H "Content-Type: application/json" \ -d '{"user_id": "test-user-1", "name": "Test User"}'A
401 Unauthorizedresponse with{"detail": "Authentication required"}means the token was not sent or is invalid.
-
Environment Variables
| Variable | Required | Default | Description |
|---|---|---|---|
|
No |
|
Enable or disable authentication. Set to |
|
Yes1 |
— |
OIDC provider issuer URL, for example |
|
Yes1 |
— |
Expected |
1 Required when OIDC_AUTH_ENABLED=true.
|
Production Considerations
Agent Memory normalizes |
Troubleshooting
If you encounter an error when setting up authentication for your Agent Memory instance, use the following information to help troubleshoot:
| Error | Cause | Solution |
|---|---|---|
"OIDC provider not initialized" |
Auth is enabled but OIDC discovery failed at startup. Agent Memory retries discovery 3 times with exponential backoff, then exits the container. A transient network issue at container start can trigger this, not only a misconfigured issuer URL. |
Verify that |
"Token has expired" |
The token’s |
Obtain a fresh access token from your IdP. |
"Invalid token claims" |
|
Decode your token with |
"Unknown signing key" |
A token arrived with a |
Agent Memory re-fetches the JWKS once on encountering an unknown |
"ID tokens are not accepted" |
An ID token was used instead of an access token. |
Use the |