Skip to content
Draft
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion auth4genai/how-tos/analyze-strava-activities.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Before using this example, make sure you:
## 1. Define the Vercel AI Tool and backend API Route

Define a `getActivities` tool that uses GPT-4 to fetch and analyze a user's recent fitness activity from Strava:
- When the tool calls `getAccessTokenForConnection()` to fetch a Spotify access token, pass in `strava-custom` as the connection name.
- When the tool calls `getAccessTokenFromTokenVault()` to fetch a Spotify access token, pass in `strava-custom` as the connection name.

```tsx wrap lines
import { openai } from "@ai-sdk/openai"
Expand Down
2 changes: 1 addition & 1 deletion auth4genai/how-tos/create-spotify-playlist.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ Before using this example, make sure you:
## 1. Define the Vercel AI Tool and backend API Route

Define a `createPlaylist` tool that uses GPT-4 to create a new Spotify playlist for the user:
- When the tool calls `getAccessTokenForConnection()` to fetch a Spotify access token, pass in `spotify-custom` as the connection name.
- When the tool calls `getAccessTokenFromTokenVault()` to fetch a Spotify access token, pass in `spotify-custom` as the connection name.

```tsx wrap app/api/chat/route.js lines
import { openai } from "@ai-sdk/openai"
Expand Down
2 changes: 1 addition & 1 deletion auth4genai/how-tos/get-github-issues-python.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ Create a function that will return the access token for Github.

```python wrap lines
async def get_token_from_token_vault():
return await auth0.get_access_token_for_connection(
return await auth0.get_access_token_from_token_vault(
options = {
"connection" : "github",
"scope" : "openid profile email offline_access"})
Expand Down
2 changes: 1 addition & 1 deletion auth4genai/how-tos/get-salesforce-opportunities.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ SALESFORCE_INSTANCE_URL=https://your-instance.salesforce.com

Create an AI tool that gets a list of opportunities from Salesforce and a backend route that uses Auth0 to get a Salesforce access token:

- When the tool calls `auth0.getAccessTokenForConnection()`, pass `sfdc` as the connection name to get a Salesforce access token.
- When the tool calls `auth0.getAccessTokenFromTokenVault()`, pass `sfdc` as the connection name to get a Salesforce access token.

```tsx app/api/chat/route.js wrap lines
import { openai } from "@ai-sdk/openai";
Expand Down
4 changes: 2 additions & 2 deletions auth4genai/integrations/github.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ To configure the Token Vault for your GitHub connection, you can use the followi
```tsx wrap lines
const auth0AI = new Auth0AI();

export const withGitHubConnection = auth0AI.withTokenForConnection({
export const withGitHubConnection = auth0AI.withTokenVault({
connection: "github",
// scopes are not supported for GitHub yet. Set required scopes when creating the accompanying GitHub app
scopes: [],
Expand All @@ -96,7 +96,7 @@ To configure the Token Vault for your GitHub connection, you can use the followi
```python wrap lines
auth0_ai = Auth0AI()

with_github_connection = auth0_ai.with_federated_connection(
with_github_connection = auth0_ai.with_token_vault(
connection="github",
# scopes are not supported for GitHub yet. Set required scopes when creating the accompanying GitHub app
scopes=[],
Expand Down
4 changes: 2 additions & 2 deletions auth4genai/integrations/google.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ To configure the Token Vault for your Google connection, you can use the followi
```tsx wrap lines
const auth0AI = new Auth0AI();

export const withGoogleConnection = auth0AI.withTokenForConnection({
export const withGoogleConnection = auth0AI.withTokenVault({
connection: "google-oauth2",
scopes: ["https://www.googleapis.com/auth/calendar.freebusy", ...],
refreshToken: getAuth0RefreshToken(),
Expand All @@ -162,7 +162,7 @@ To configure the Token Vault for your Google connection, you can use the followi
```python wrap lines
auth0_ai = Auth0AI()

with_google_connection = auth0_ai.with_federated_connection(
with_google_connection = auth0_ai.with_token_vault(
connection="google-oauth2",
scopes=["https://www.googleapis.com/auth/calendar.freebusy", ...],
refresh_token=get_auth0_refresh_token,
Expand Down
4 changes: 2 additions & 2 deletions auth4genai/integrations/slack.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ To configure the Token Vault for your GitHub connection, you can use the followi
```tsx wrap lines
const auth0AI = new Auth0AI();

export const withSlackConnection = auth0AI.withTokenForConnection({
export const withSlackConnection = auth0AI.withTokenVault({
connection: "sign-in-with-slack",
scopes: ["channels:read", ...],
refreshToken: getAuth0RefreshToken(),
Expand All @@ -96,7 +96,7 @@ To configure the Token Vault for your GitHub connection, you can use the followi
```python wrap lines
auth0_ai = Auth0AI()

with_slack_connection = auth0_ai.with_federated_connection(
with_slack_connection = auth0_ai.with_token_vault(
connection="sign-in-with-slack",
scopes=["channels:read", ...],
refresh_token=get_auth0_refresh_token,
Expand Down
4 changes: 2 additions & 2 deletions auth4genai/intro/call-others-apis-on-users-behalf.mdx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
title: Call Other's APIs on User's Behalf
description: "[Token Vault](/intro/token-vault) lets your AI agent call external APIs on the user's behalf. We provide SDKs for Python, JavaScript, and popular AI frameworks like LangChain, LlamaIndex, Genkit, and Vercel AI, making it easy and straightforward to get access tokens for your federated connections."
description: "[Token Vault](/intro/token-vault) lets your AI agent call external APIs on the user's behalf. We provide SDKs for Python, JavaScript, and popular AI frameworks like LangChain, LlamaIndex, Genkit, and Vercel AI, making it easy and straightforward to get access tokens for your third-party connections."
---

## Web applications with backend for frontend
Expand Down Expand Up @@ -135,4 +135,4 @@ To begin using Auth0 Token Vault with your AI agents, refer to the following res
icon="key"
horizontal
/>
</Columns>
</Columns>
2 changes: 1 addition & 1 deletion auth4genai/sdks/javascript-sdk.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ This library helps to set up the React components that can be used in AI applica
- Tools for getting access tokens for supported social and enterprise identity providers

```bash wrap lines
npx @auth0/ai-components add FederatedConnections
npx @auth0/ai-components add TokenVault
```

### [Redis Store for Auth0 AI](https://github.com/auth0-lab/auth0-ai-js/tree/main/packages/ai-redis)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ Make sure you have [uv](https://docs.astral.sh/uv/) installed and run the follow
```bash wrap lines
cd backend
uv sync
uv add "auth0-ai-langchain>=1.0.0b3" "langgraph>=0.5.4" langchain-openai "langgraph-cli[inmem]" --prerelease=allow
uv add "auth0-ai-langchain>=TODO_NEW_VERSION_HERE" "langgraph>=0.5.4" langchain-openai "langgraph-cli[inmem]" --prerelease=allow
```

### Update the environment file
Expand All @@ -47,7 +47,7 @@ Integrate the Auth0 AI SDK into your application to secure your async AI agent w

#### Configure the Auth0 AI SDK

To require asynchronous authorization for your tool, the tool needs to be wrapped with the Async authorizer, `with_async_user_confirmation()`. Let's create a helper function to wrap the tool with the Async authorizer.
To require asynchronous authorization for your tool, the tool needs to be wrapped with the Async authorizer, `with_async_authorization()`. Let's create a helper function to wrap the tool with the Async authorizer.

Create a file at `app/core/auth0_ai.py` and instantiate a new Auth0 AI SDK client:

Expand All @@ -68,7 +68,7 @@ auth0_ai = Auth0AI(
)
)

with_async_user_confirmation = auth0_ai.with_async_user_confirmation(
with_async_authorization = auth0_ai.with_async_authorization(
audience=settings.SHOP_API_AUDIENCE,
# add any scopes you want to use with your API
scopes=["openid", "product:buy"],
Expand All @@ -90,9 +90,9 @@ with_async_user_confirmation = auth0_ai.with_async_user_confirmation(
)
```

This will intercept the tool call to initiate a CIBA request:
This will intercept the tool call to initiate an Async Authorization request:

- The CIBA request includes the user ID that will approve the request.
- 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 `/token` endpoint for a user response.
- The mobile application retrieves the `bindingMessage` containing the consent details, in this case, the details of the product to purchase.
- The user responds to the request:
Expand Down Expand Up @@ -146,10 +146,10 @@ Now, create a file `app/agents/tools/shop_online.py` and add the following code:
```python app/agents/tools/shop_online.py wrap lines
import httpx
from langchain_core.tools import StructuredTool
from auth0_ai_langchain.ciba import get_ciba_credentials
from auth0_ai_langchain.ciba import get_async_
from pydantic import BaseModel

from app.core.auth0_ai import with_async_user_confirmation
from app.core.auth0_ai import with_async_authorization
from app.core.config import settings


Expand Down Expand Up @@ -202,7 +202,7 @@ async def shop_online_fn(product: str, quantity: int):
}


shop_online = with_async_user_confirmation(
shop_online = with_async_authorization(
StructuredTool(
name="shop_online",
description="Tool to buy products online.",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ Make sure you have [uv](https://docs.astral.sh/uv/) installed and run the follow
```bash wrap lines
cd backend
uv sync
uv add "auth0-ai-langchain>=1.0.0b3" openfga-sdk langgraph langchain-openai "langgraph-cli[inmem]" --prerelease=allow
uv add "auth0-ai-langchain>=TODO_NEW_VERSION_HERE" openfga-sdk langgraph langchain-openai "langgraph-cli[inmem]" --prerelease=allow
```

### Update the environment file
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { AccountAndAppSteps } from "/snippets/get-started/prerequisites/account-
<Tab
title="Use sample app (recommended)"
>

### Clone sample app
Clone this sample app from the [Auth0 AI samples](https://github.com/auth0-samples/auth0-ai-samples) repository:

Expand Down Expand Up @@ -134,7 +134,7 @@ Make sure you have [uv](https://docs.astral.sh/uv/) installed and run the follow
```bash wrap lines
cd backend
uv sync
uv add "auth0-ai-langchain>=1.0.0b3" "langgraph>=0.5.4" langchain-openai "langgraph-cli[inmem]" google-api-python-client --prerelease=allow
uv add "auth0-ai-langchain>=TODO_NEW_VERSION_HERE" "langgraph>=0.5.4" langchain-openai "langgraph-cli[inmem]>=0.3.6" google-api-python-client --prerelease=allow
```

### Update your environment file
Expand Down Expand Up @@ -191,7 +191,7 @@ auth0_ai = Auth0AI(
)
)

with_calendar_access = auth0_ai.with_federated_connection(
with_calendar_access = auth0_ai.with_token_vault(
connection="google-oauth2",
scopes=["https://www.googleapis.com/auth/calendar.events"],
)
Expand Down Expand Up @@ -244,7 +244,7 @@ from google.oauth2.credentials import Credentials
from googleapiclient.discovery import build
from pydantic import BaseModel
from auth0_ai_langchain.federated_connections import (
get_access_token_for_connection,
get_access_token_from_token_vault,
)
import datetime
import json
Expand All @@ -253,10 +253,10 @@ from app.core.auth0_ai import with_calendar_access

async def list_upcoming_events_fn():
"""List upcoming events from the user's Google Calendar"""
google_access_token = get_access_token_for_connection()
google_access_token = get_access_token_from_token_vault()
if not google_access_token:
raise ValueError(
"Authorization required to access the Federated Connection API"
"Authorization required to access the Token Vault Connection API"
)

calendar_service = build(
Expand Down Expand Up @@ -328,18 +328,18 @@ To implement, install the Auth0 AI Components for React SDK to get the required
```bash wrap lines
cd frontend
npm install @auth0/ai @langchain/langgraph-sdk
npx @auth0/ai-components add FederatedConnections
npx @auth0/ai-components add TokenVault
```

Add a new file, `src/components/auth0-ai/FederatedConnections/FederatedConnectionInterruptHandler.tsx`, with the following code:

```tsx src/components/auth0-ai/FederatedConnections/FederatedConnectionInterruptHandler.tsx wrap lines
import { FederatedConnectionInterrupt } from "@auth0/ai/interrupts";
```tsx src/components/auth0-ai/TokenVault/TokenVaultInterruptHandler.tsx wrap lines
import { TokenVaultInterrupt } from "@auth0/ai/interrupts";
import type { Interrupt } from "@langchain/langgraph-sdk";

import { EnsureAPIAccess } from "@/components/auth0-ai/FederatedConnections";
import { TokenVaultConsent } from "@/components/auth0-ai/TokenVault";

interface FederatedConnectionInterruptHandlerProps {
interface TokenVaultInterruptHandlerProps {
interrupt: Interrupt | undefined | null;
onFinish: () => void;
auth?: {
Expand All @@ -348,21 +348,21 @@ interface FederatedConnectionInterruptHandlerProps {
};
}

export function FederatedConnectionInterruptHandler({
export function TokenVaultInterruptHandler({
interrupt,
onFinish,
auth,
}: FederatedConnectionInterruptHandlerProps) {
}: TokenVaultInterruptHandlerProps) {
if (
!interrupt ||
!FederatedConnectionInterrupt.isInterrupt(interrupt.value)
!TokenVaultInterrupt.isInterrupt(interrupt.value)
) {
return null;
}

return (
<div key={interrupt.ns?.join("")} className="whitespace-pre-wrap">
<EnsureAPIAccess
<TokenVaultConsent
mode="popup"
interrupt={interrupt.value}
onFinish={onFinish}
Expand All @@ -378,11 +378,11 @@ export function FederatedConnectionInterruptHandler({
}
```

Now, update your chat window code to include the `FederatedConnectionInterruptHandler` component, for example:
Now, update your chat window code to include the `TokenVaultInterruptHandler` component, for example:

```tsx src/components/chat-window.tsx wrap lines highlight={2,3,25-50}
//...
import { FederatedConnectionInterruptHandler } from '@/components/auth0-ai/FederatedConnections/FederatedConnectionInterruptHandler';
import { TokenVaultInterruptHandler } from '@/components/auth0-ai/TokenVault/TokenVaultInterruptHandler';
import { getLoginUrl } from "@/lib/use-auth";

//... existing code
Expand Down Expand Up @@ -450,4 +450,4 @@ That's it! You successfully integrated third-party API access using Token Vault
### View a complete example
Want to see how it all comes together? Explore or clone the fully implemented sample application on [GitHub](https://github.com/auth0-samples/auth0-ai-samples/tree/main/call-apis-on-users-behalf/others-api/langchain-fastapi-py).
</Tab>
</Tabs>
</Tabs>
10 changes: 5 additions & 5 deletions auth4genai/snippets/get-started/langchain-next-js/async-auth.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ Integrate the Auth0 AI SDK into your application to secure your async AI agent w

#### Configure the Auth0 AI SDK

To require asynchronous authorization for your tool, the tool needs to be wrapped with the Async authorizer, `withAsyncUserConfirmation()`. Let's create a helper function to wrap the tool with the Async authorizer.
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:

Expand All @@ -47,7 +47,7 @@ import { AccessDeniedInterrupt } from "@auth0/ai/interrupts";
const auth0AI = new Auth0AI();

// CIBA flow for user confirmation
export const withAsyncAuthorization = auth0AI.withAsyncUserConfirmation({
export const withAsyncAuthorization = auth0AI.withAsyncAuthorization({
userID: async (_params, config) => {
return config?.configurable?._credentials?.user?.sub;
},
Expand Down Expand Up @@ -76,9 +76,9 @@ export const withAsyncAuthorization = auth0AI.withAsyncUserConfirmation({
});
```

This will intercept the tool call to initiate a CIBA request:
This will intercept the tool call to initiate an Async Authorization request:

- The CIBA request includes the user ID that will approve the request.
- 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 `/token` endpoint for a user response.
- The mobile application retrieves the `bindingMessage` containing the consent details, in this case, the details of the product to purchase.
- The user responds to the request:
Expand Down Expand Up @@ -167,7 +167,7 @@ export const shopOnlineTool = tool(
priceLimit,
};

const credentials = getCIBACredentials();
const credentials = getAsyncAuthorizationCredentials();
const accessToken = credentials?.accessToken;

if (accessToken) {
Expand Down
Loading