Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions src/langsmith/set-up-custom-auth.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ Now that you have a base LangGraph app, add authentication to it.
In this tutorial, you will start with a hard-coded token for example purposes. You will get to a "production-ready" authentication scheme in the third tutorial.
</Note>

The [`Auth`](https://langchain-ai.github.io/langgraph/cloud/reference/sdk/python-sdk_ref#langgraph_sdk.auth.Auth) object lets you register an authentication function that the LangSmith deployment will run on every request. This function receives each request and decides whether to accept or reject.
The @[Auth] object lets you register an authentication function that the LangSmith deployment will run on every request. This function receives each request and decides whether to accept or reject.

Create a new file `src/security/auth.py`. This is where your code will live to check if users are allowed to access your bot:

Expand Down Expand Up @@ -114,12 +114,12 @@ async def get_current_user(authorization: str | None) -> Auth.types.MinimalUserD
}
```

Notice that your [authentication](https://langchain-ai.github.io/langgraph/cloud/reference/sdk/python-sdk_ref#langgraph_sdk.auth.Auth.authenticate) handler does two important things:
Notice that your @[Auth.authenticate] handler does two important things:

1. Checks if a valid token is provided in the request's [Authorization header](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Authorization)
2. Returns the user's [identity](https://langchain-ai.github.io/langgraph/cloud/reference/sdk/python-sdk_ref#langgraph_sdk.auth.types.MinimalUserDict)
2. Returns the user's @[MinimalUserDict]

Now tell LangGraph to use authentication by adding the following to the [`langgraph.json`](/langsmith/cli#configuration-file) configuration:
Now tell LangGraph to use authentication by adding the following to the @[langgraph.json] configuration:

```json {highlight={7-9}} title="langgraph.json"
{
Expand Down Expand Up @@ -203,4 +203,4 @@ Now that you can control who accesses your bot, you might want to:

1. Continue the tutorial by going to [Make conversations private](/langsmith/resource-auth) to learn about resource authorization.
2. Read more about [authentication concepts](/langsmith/auth).
3. Check out the [API reference](https://langchain-ai.github.io/langgraph/cloud/reference/sdk/python-sdk_ref) for more authentication details.
3. Check out the API reference for @[Auth], @[Auth.authenticate], and @[MinimalUserDict] for more authentication details.