What you’ll learn
- Retrieve access tokens for a Google social connection.
- Integrate with an AI agent to call Google APIs.
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
OpenAI Platform
Set up an OpenAI account and API key.
Hono
Getting started using AI
To get started quickly:Clone auth0-samples/auth0-ai-samples and navigate to
Then, integrate Auth0 AI docs into your preferred AI tool:auth0-ai-samples/call-apis-on-users-behalf/others-api/langchain-next-js directory.- VS Code
- Cursor
- Claude Code
- Claude
or Follow manual steps
1
Start from our Cloudflare Agents template
Our Auth0 Cloudflare Agents Starter Kit provides a starter project that includes the necessary dependencies and configuration to get you up and running quickly.To create a new Cloudflare Agents project using the template, run the following command in your terminal:
2
About the dependencies
The start kit is similar to the Cloudflare Agents starter kit but includes the following dependencies to integrate with Auth0 and AI SDK:
hono: Hono Web Application framework.@auth0/auth0-hono: Auth0 SDK for the Hono web framework.hono-agents: Hono Agents to add intelligent, stateful AI agents to your Hono app.@auth0/auth0-cloudflare-agents-api: Auth0 Cloudflare Agents API SDK to secure Cloudflare Agents using bearer tokens from Auth0.@auth0/ai: Auth0 AI SDK to provide base abstractions for authentication and authorization in AI applications.@auth0/ai-vercel: Auth0 AI SDK to provide building blocks for using Auth0 for AI Agents with the AI SDK.@auth0/ai-cloudflare: Auth0 Cloudflare AI SDK to provide building blocks for using Auth0 for AI Agents with the Cloudflare Agents API.
3
Set up environment variables
In the root directory of your project, copy the
.dev.vars.example into .dev.vars file and configure the Auth0 and OpenAI variables.4
Define a tool to call your API
In this step, you’ll create a AI SDK tool to make the first-party API call to the Auth0 API. You will do the same for third-party APIs.After taking in an Auth0 access token during user login, the Cloudflare Worker sends the token to the Cloudflare Agent using the Authorization header in every web request or WebSocket connection.Since the Agent defined in the class Chat in Then in the
src/agent/chat.ts uses the AuthAgent trait from the @auth0/auth0-cloudflare-agents-api it validates the signature of the token and that it matches the audience of the Agent.The tool we are defining here uses the same access token to call Auth0’s /userinfo endpoint.src/agent/tools.ts
tools export of the src/agent/chat.ts file, add the getUserInfoTool to the tools array:src/agent/chat.ts
5
Test your application
To test the application, run That’s it! You’ve successfully integrated first-party tool-calling into your project.Explore the start kit on GitHub.
npm run start and navigate to http://localhost:3000/ and interact with the AI agent. You can ask questions like “who am I?” to trigger the tool call and test whether it successfully retrieves information about the logged-in user.Continue Learning
Call Your APIs on User's Behalf
With Auth0, your AI apps can securely call your APIs on behalf of authenticated users.
Call Other's APIs on User's Behalf
Token Vault lets your AI agent call external APIs on a user’s behalf.
How-Tos
Check Google Calendar Availability
Use OpenAI, NextJS, and the Auth0-AI SDKs to check your Google Calendar availability.
List GitHub Repositories
Use OpenAI, NextJS, and the Auth0-AI SDKs to list your GitHub repositores
List Slack Channels
Use OpenAI, NextJS, and the Auth0-AI SDKs to list your Slack channels