- Get an Auth0 access token.
- Use the Auth0 access token to make a tool call to your API endpoint, in this case, Auth0’s
/userinfo
endpoint. - Return the data to the user via an AI agent.
Pick your tech stack
Prerequisites
Before getting started, make sure you have completed the following steps:1
Create an Auth0 Account
To continue with this quickstart, you need to have an Auth0 account.
2
Create an Auth0 Application
Go to your Auth0 Dashboard to create a new Auth0 Application.
- Navigate to Applications > Applications in the left sidebar.
- Click the Create Application button in the top right.
- In the pop-up select Regular Web Applications and click Create.
- Once the Application is created, switch to the Settings tab.
- Scroll down to the Application URIs section.
- Set Allowed Callback URLs as:
http://localhost:3000/auth/callback
- Set Allowed Logout URLs as:
http://localhost:3000
- Click Save in the bottom right to save your changes.
3
OpenAI Platform
Set up an OpenAI account and API key.
Prepare Next.js app
Recommended: To use a starter template, clone the Auth0 AI samples repository:Install dependencies
In the root directory of your project, install the following dependencies:@langchain/langgraph
: The core LangGraph module.@langchain/openai
: OpenAI provider for LangChain.langchain
: The core LangChain module.zod
: TypeScript-first schema validation library.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.Pass credentials to the agent
You have to pass the access token from the user’s session to the agent. First, create a helper function to get the access token from the session. Add the following function tosrc/lib/auth0.ts
:src/lib/auth0.ts
/src/app/api/chat/[..._path]/route.ts
file to pass the access token to the agent:src/app/api/chat/[..._path]/route.ts
Define a tool to call your API
In this step, you’ll create a LangChain tool to make the first-party API call. The tool fetches an access token to call the API.In this example, after taking in an Auth0 access token during user login, the tool returns the user profile of the currently logged-in user by calling the /userinfo endpoint.src/lib/tools/user-info.ts
Add the tool to the AI agent
The AI agent processes and runs the user’s request through the AI pipeline, including the tool call. Update the/src/lib/agent.ts
file to add the tool to the agent.src/lib/agent.ts
.env.local
file:.env.local
.env.local
accordingly.Test your application
To test the application, runnpm run all:dev
and 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.
"who am I?"
to trigger the tool call and test whether it successfully retrieves information about the logged-in user.Next steps
- Call your APIs on user’s behalf docs.
- To set up third-party tool calling, complete the Call other’s APIs on user’s behalf quickstart.
- To explore the Auth0 Next.js SDK, see the Github repo.