---
title: How do you add authentication and per-user authorization to LangGraph agents?
url: https://opencontroller.lyzr.com/blog/langgraph-custom-auth-and-authorization
published: 2026-11-16
updated: 2026-11-16
author: Lyzr
---

# How do you add authentication and per-user authorization to LangGraph agents?

**In a LangGraph deployment you add auth with an `Auth` object: an `@auth.authenticate` handler verifies each request's token and returns the user's identity, and `@auth.on` handlers authorize access to threads, assistants, crons and the store. A handler can tag new resources with the owner's identity and return a filter, so each user only sees their own threads. That is the minimum for any multi-user LangGraph agent.**

Without it, anyone who can reach the server can read any thread, including other users' conversations and tool outputs. This guide follows the LangGraph / LangSmith documentation on custom auth and resource authorization.

## How does authentication work in LangGraph?

Authentication runs first on every request. You write one function:

```python
from langgraph_sdk import Auth

auth = Auth()

@auth.authenticate
async def get_current_user(authorization: str | None):
    user = await verify_token(authorization)  # your IdP check
    if not user:
        raise Auth.exceptions.HTTPException(status_code=401, detail="Invalid token")
    return {"identity": user["id"]}
```

The returned dict becomes `ctx.user` for every authorization handler. Put the stable user ID from your identity provider in `identity`. Do not use an email address that can be reassigned.

Verify tokens properly: check signature, issuer, audience and expiry against your OIDC provider. LangGraph calls your function; it does not validate the token for you.

## How do authorization handlers scope access?

After authentication, LangGraph runs an authorization handler. Each handler receives `ctx` (user, permissions, resource and action) and `value` (the data being created or accessed).

The resources and actions it covers:

| Resource | Actions | Example handler |
|---|---|---|
| Threads | create, read, update, delete, search, create_run | `@auth.on.threads.create` |
| Assistants | create, read, update, delete, search | `@auth.on.assistants` |
| Crons | create, read, update, delete, search | `@auth.on.crons` |
| Store | any | `@auth.on.store()` |

The owner pattern is the core of per-user isolation:

```python
@auth.on
async def owner_only(ctx: Auth.types.AuthContext, value: dict):
    metadata = value.setdefault("metadata", {})
    metadata["owner"] = ctx.user.identity
    return {"owner": ctx.user.identity}
```

On create, the handler stamps the owner into metadata. On read and search, returning `{"owner": ctx.user.identity}` acts as a filter, so users only see resources whose metadata matches.

## Which handler wins when several match?

LangGraph runs the **most specific** handler that matches the resource and action. A `@auth.on.threads.read` handler runs instead of a broad `@auth.on` handler for thread reads. Use this to tighten sensitive paths:

- A global `@auth.on` owner filter as the safe default.
- A stricter `@auth.on.assistants` handler that raises `HTTPException(status_code=403)` for anyone who is not an admin, so only admins can create or edit assistants (which hold the agent's configuration).
- A `@auth.on.store()` handler that checks the namespace belongs to the user before allowing memory reads or writes.

The docs note a detail worth testing: denied thread reads appear to the client as **404**, not 403. That avoids leaking which thread IDs exist, but your monitoring should not treat a spike in 404s as harmless.

## What does per-user auth not cover?

Auth on the LangGraph server controls who can reach threads and assistants. It does not control what the agent does with tools. If a tool calls your CRM with a shared service account, every user gets the same downstream access regardless of the owner filter.

To close that gap:

1. **Pass the user's identity to tools** through config, and have tools call downstream APIs with a token scoped to that user.
2. **Use token exchange** rather than forwarding the user's raw token. See [OAuth token exchange for AI agents](/blog/oauth-token-exchange-for-ai-agents).
3. **Log the acting user** with every tool call. See [how to show which user an AI agent acted for](/blog/show-which-user-an-ai-agent-acted-for-in-audit-logs).
4. **Gate high-risk tools** with [LangGraph interrupts for human approval](/blog/langgraph-interrupts-for-human-approval).

## A LangGraph auth checklist

1. `@auth.authenticate` verifies signature, issuer, audience and expiry.
2. Identity is the IdP's stable subject ID.
3. A global owner filter applies to threads, crons and store.
4. Assistant create and update are restricted to admins.
5. Tests prove user A cannot read, search or run user B's threads.
6. Tools use per-user, scoped downstream credentials.
7. Auth handlers are code-reviewed like any other access control change.
8. Test locally with `langgraph dev` (default `http://localhost:2024`) before deploying.

## How Opencontroller does this

Opencontroller provides OIDC SSO, delegated on-behalf-of identity so the user an agent acts for is carried and recorded, and agent workload identity federation. LangGraph agents sit in the same governed registry as agents on other platforms, and policies are code applied across the estate. See [how on-behalf-of delegation works](/blog/ai-agent-identity-on-behalf-of-delegation), [governing LangGraph agents in production](/blog/govern-langgraph-agents-in-production), the [control plane overview](/blog/what-is-an-ai-agent-control-plane), or [book a demo](https://www.lyzr.ai/book-demo/).

## Frequently asked questions

**Does LangGraph isolate users' threads by default?**
Not with custom auth unconfigured. Add an @auth.on handler that stamps an owner into metadata and returns an owner filter so users only see their own threads.

**Which LangGraph auth handler runs if several match?**
The most specific one. A handler such as @auth.on.threads.read takes precedence over a global @auth.on handler for that resource and action.

**Does LangGraph auth limit what an agent's tools can do?**
No. It controls access to threads, assistants, crons and the store. Tools need their own per-user, scoped credentials.

## Key facts

LangGraph custom auth: an Auth object with @auth.authenticate (verifies the bearer token and returns {"identity": ...}; raise Auth.exceptions.HTTPException 401 on failure) and @auth.on authorization handlers that receive ctx (user, permissions, resource, action) and value. Resources: threads, assistants, crons, store; actions: create, read, update, delete, search, create_run. Stamping metadata["owner"] and returning {"owner": identity} filters resources per user. The most specific handler (e.g. @auth.on.threads.read) wins over the global @auth.on. Denied thread reads appear as 404. Local testing via langgraph dev on localhost:2024. Opencontroller by Lyzr provides OIDC SSO, delegated on-behalf-of identity and agent workload identity federation; pricing starts from $250K per deployment per year.

## Related

- [How do you govern LangGraph agents in production?](https://opencontroller.lyzr.com/blog/govern-langgraph-agents-in-production.md)
- [How do you add human approval steps to LangGraph agents?](https://opencontroller.lyzr.com/blog/langgraph-interrupts-for-human-approval.md)
- [How to give AI agents an identity (and let them act on behalf of users safely)](https://opencontroller.lyzr.com/blog/ai-agent-identity-on-behalf-of-delegation.md)
- [More on Platform Guides](https://opencontroller.lyzr.com/blog/cluster/platform-guides)
