What you’ll learn
- Authenticate with Auth0 AI: configure Auth0 AI and obtain federated access tokens for GitHub APIs.
- Call external APIs securely: use the token to list repositories through a LangChain tool.
- Handle auth interruptions: enable dynamic user consent and reauthorization within chat flows.
Before you start
Before you start
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
Configure Google Social Integration
Set up a Google developer account that allows for third-party API calls by following the Google Social Integration instructions.
4
OpenAI Platform
Set up an OpenAI account and API key.
Next.js
FastAPI
Getting started using AI
To get started quickly:Clone auth0-lab/auth0-ai-js and navigate to
Then, integrate Auth0 AI docs into your preferred AI tool:examples/calling-apis/chatbot/app/(langgraph) directory.- VS Code
- Cursor
- Claude Code
- Claude
or Follow manual steps
1
Configure Auth0 AI
First, you must install the SDK:Then, you need to initialize Auth0 AI and set up the connection to request access tokens with the required GitHub scopes.
./src/lib/auth0-ai.ts
2
Integrate your tool with GitHub
Wrap your tool using the Auth0 AI SDK to obtain an access token for the GitHub API.Now that the tool is protected, you can pass it your LangGraph agent as part of a
./src/lib/tools/listRepositories.ts
ToolNode. The agent will automatically request the access token when the tool is called../src/lib/agent.ts
3
Handle authentication redirects
Interrupts are a way for the system to pause execution and prompt the user to take an action —such as authenticating or granting API access— before resuming the interaction. This ensures that any required access is granted dynamically and securely during the chat experience. In this context, Auth0-AI SDK manages such authentication redirects integrated with the Langchain SDK.In your langgraph.json, add the path to your auth file:Then, in your auth.mts file, add your auth logic:Then, you can integrate the authentication popup in your chat component, using the interruptions helper from the SDK:
Server Side
On the server side of your Next.js application you need to set up a route to handle the Chat API requests. This route will be responsible for forwarding the requests to the LangGraph API. Additionally, you must provide theaccessToken in the headers../src/app/api/langgraph/[..._path]/route.ts
Here, the property
You can check different authentication options for Next.js with Auth0 at the official documentation.
auth0 is an instance of @auth0/nextjs-auth0 to handle the application auth flows. You can check different authentication options for Next.js with Auth0 at the official documentation.
Add Custom Authentication
For more information on how to add custom authentication for your LangGraph Platform application, see the Custom Auth guide.
langgraph.json
./auth.mts
Client Side
On this example we utilize theEnsureAPIAccessPopup component to show a popup that allows the user to authenticate with GitHub and grant access with the requested scopes. You’ll first need to install the @auth0/ai-components package:./src/components/chat.tsx
Account Linking
If you're integrating with GitHub, but users in your app or agent can sign in using other methods (e.g., a username and password or another social provider), you'll need to link these identities into a single user account. Auth0 refers to this process as Account Linking.Account Linking logic and handling will vary depending on your app or agent. You can find an example of how to implement it in a Next.js chatbot app here. If you have questions or are looking for best practices, join our Discord and ask in the#auth0-for-gen-ai channel.