Choisissez votre pile technologique
- LangGraph.js + Next.js
- Vercel AI + Next.js
- LangGraph + FastAPI
- Vercel AI + Node.js
Download sample app
Start by downloading and extracting the sample app. Then open in your preferred IDE.Install dependencies
In the root directory of your project, install the following dependencies:@auth0/ai-langchain: Auth0 AI SDK for LangChain built for AI agents powered by LangChain.@langchain/langgraph: For building stateful, multi-actor applications with LLMs.langchain: The LangChain library.@langchain/core: LangChain core libraries.@langchain/openai: OpenAI provider for LangChain.langgraph-nextjs-api-passthrough: API passthrough for LangGraph.
Update the environment file
Copy the.env.example file to .env.local and update the variables with your Auth0 credentials. You can find your Auth0 domain, client ID, and client secret in the application you created in the Auth0 Dashboard.Set up Human-in-the-Loop approvals
Integrate the Auth0 AI SDK into your application to secure your async AI agent workflow. For this quickstart, we will use a blocking request flow. In real use cases, often an asynchronous flow is preferred.Configure the Auth0 AI SDK
To require asynchronous authorization for your tool, the tool needs to be wrapped with the Async authorizer,withAsyncAuthorization(). Let’s create a helper function to wrap the tool with the Async authorizer.Create a file at src/lib/auth0-ai.ts and instantiate a new Auth0 AI SDK client:src/lib/auth0-ai.ts
- The Async Authorization request includes the user ID that will approve the request.
- Auth0 sends the user a mobile push notification. The AI agent polls the
/tokenendpoint for a user response. - The mobile application retrieves the
bindingMessagecontaining the consent details, in this case, the details of the product to purchase. - The user responds to the request:
- If the request is approved, the tool execution will continue.
- If the request is rejected, the tool execution will not continue.

Pass credentials to the tools
Next, add the following code tosrc/lib/auth0.ts:src/lib/auth0.ts
/src/app/api/chat/[..._path]/route.ts file with the following code. The access token will be passed to your LangGraph agent so we can use it from the Auth0 AI SDK to get the current user.src/app/api/chat/[..._path]/route.ts
Add Custom Authentication
For more information on how to add custom authentication for your LangGraph Platform application, read the Custom Auth guide.
langgraph.json, add the path to your auth file:langgraph.json
src/lib/auth.ts
Create a tool to call your API
In this example, we use a tool that buys products on the user’s behalf. When the user approves the transaction, the Auth0 AI SDK retrieves an access token to call the shop’s API. Upon completing the Async Authorization flow, the AI agent responds with a message confirming the purchase. The Auth0 AI SDK returns an error response if the user denies the transaction.Now, create a filesrc/lib/tools/shop-online.ts and add the following code:src/lib/tools/shop-online.ts
Update environment variables
You need to obtain an API Key from OpenAI or another provider to use an LLM.If you want to use an API, it must be registered with Auth0 and have a valid audience.Update the.env.local file with the following variables:.env.local
Require async authorization for your tool
Call the tool from your AI app to make purchases. Update thesrc/lib/agent.ts file with the following code:src/lib/agent.ts
Test the application
Start the application withnpm run all:dev. Then, navigate to http://localhost:3000.This will open the LangGraph Studio in a new tab. You can close it as we won’t
require it for testing the application.
Prochaines étapes
Vous avez ajouté une étape d’autorisation pour protéger l’appel d’outils dans les agents d’IA asynchrones. Pour la suite :- Documentation sur l’autorisation asynchrone.
- En savoir plus sur le flux Client-Initiated Backchannel Authentication.
- Apprendre à configurer Rich Authorization Requests.
- En savoir plus sur la trousse SDK Auth0 Guardian pour Android.
- En savoir plus sur la trousse SDK Auth0 Guardian pour iOS.