diff --git a/auth4genai/how-tos/get-github-issues-python.mdx b/auth4genai/how-tos/get-github-issues-python.mdx index aef765890..f97ac43ce 100644 --- a/auth4genai/how-tos/get-github-issues-python.mdx +++ b/auth4genai/how-tos/get-github-issues-python.mdx @@ -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"}) diff --git a/auth4genai/integrations/github.mdx b/auth4genai/integrations/github.mdx index 40c97fbe5..d44e9198d 100644 --- a/auth4genai/integrations/github.mdx +++ b/auth4genai/integrations/github.mdx @@ -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: [], @@ -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=[], diff --git a/auth4genai/integrations/google.mdx b/auth4genai/integrations/google.mdx index 56d6b933f..247eec184 100644 --- a/auth4genai/integrations/google.mdx +++ b/auth4genai/integrations/google.mdx @@ -163,7 +163,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(), @@ -175,7 +175,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, diff --git a/auth4genai/integrations/slack.mdx b/auth4genai/integrations/slack.mdx index d775c87ef..b7693d8f8 100644 --- a/auth4genai/integrations/slack.mdx +++ b/auth4genai/integrations/slack.mdx @@ -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(), @@ -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, diff --git a/auth4genai/intro/call-others-apis-on-users-behalf.mdx b/auth4genai/intro/call-others-apis-on-users-behalf.mdx index 2e4b2f0be..577ac307c 100644 --- a/auth4genai/intro/call-others-apis-on-users-behalf.mdx +++ b/auth4genai/intro/call-others-apis-on-users-behalf.mdx @@ -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 external applications." --- ## Applications with refresh tokens diff --git a/auth4genai/intro/token-vault.mdx b/auth4genai/intro/token-vault.mdx index e4c067a76..102d4452e 100644 --- a/auth4genai/intro/token-vault.mdx +++ b/auth4genai/intro/token-vault.mdx @@ -49,9 +49,9 @@ By using Token Vault, you can: The process of using Token Vault involves the following key steps: 1. **User authentication and consent:** The [user links](/intro/account-linking) and authenticates with an external Identity Provider (e.g., Google) and grants your application permission to access their data by approving the requested OAuth scopes. -2. **Secure token storage:** Auth0 receives the federated access and refresh tokens from the external provider and stores them securely within Token Vault. -3. **Token exchange:** Your application can then exchange a valid Auth0 refresh token or access token for a federated access token from Token Vault. This allows your application to obtain the necessary credentials to call the third-party API without the user having to re-authenticate. It also means your application does not need to store or manage any credentials. -4. **API call:** With the federated access token, your AI agent can make authorized calls to the third-party API on the user's behalf. +2. **Secure token storage:** Auth0 receives access and refresh tokens from the external provider and stores them securely within Token Vault. +3. **Token exchange:** Your application can then exchange a valid Auth0 refresh token or access token for an external provider's access token from Token Vault. This allows your application to obtain the necessary credentials to call external APIs without the user having to re-authenticate. It also means your application does not need to store or manage any credentials. +4. **API call:** With the external provider's access token, your AI agent can make authorized calls to the external API on the user's behalf. ## Supported integrations diff --git a/auth4genai/sdks/javascript-sdk.mdx b/auth4genai/sdks/javascript-sdk.mdx index 28b3cf792..163ca1bb4 100644 --- a/auth4genai/sdks/javascript-sdk.mdx +++ b/auth4genai/sdks/javascript-sdk.mdx @@ -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) diff --git a/auth4genai/snippets/get-started/langchain-fastapi-py/async-auth.mdx b/auth4genai/snippets/get-started/langchain-fastapi-py/async-auth.mdx index bdf430b50..b4befca57 100644 --- a/auth4genai/snippets/get-started/langchain-fastapi-py/async-auth.mdx +++ b/auth4genai/snippets/get-started/langchain-fastapi-py/async-auth.mdx @@ -33,7 +33,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>=1.0.0b4" "langgraph>=0.5.4" langchain-openai "langgraph-cli[inmem]>=0.3.6" --prerelease=allow ``` ### Update the environment file @@ -46,7 +46,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: @@ -67,8 +67,9 @@ 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, + # param: scopes # add any scopes you want to use with your API scopes=["openid", "product:buy"], binding_message=lambda product, quantity: f"Do you want to buy {quantity} {product}", @@ -77,6 +78,12 @@ with_async_user_confirmation = auth0_ai.with_async_user_confirmation( .get("_credentials") .get("user") .get("sub"), + # param: requested_expiry + # Note: Setting a requested expiry greater than 300 (seconds) will force email verification + # instead of using the push notification flow. + # requested_expiry=301, + + # param: on_authorization_request # When this flag is set to `block`, the execution of the tool awaits # until the user approves or rejects the request. # @@ -86,12 +93,13 @@ with_async_user_confirmation = auth0_ai.with_async_user_confirmation( # In practice, the process that is awaiting the user confirmation # could crash or timeout before the user approves the request. on_authorization_request="block", + ) ``` -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: @@ -138,17 +146,17 @@ async def api_route( #### 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 CIBA 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. +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 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.async_authorization import get_async_authorization_credentials 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 @@ -166,10 +174,10 @@ async def shop_online_fn(product: str, quantity: int): # No API set, mock a response return f"Ordered {quantity} {product}" - credentials = get_ciba_credentials() + credentials = get_async_authorization_credentials() if not credentials: - raise ValueError("CIBA credentials not found") + raise ValueError("Async Authorization credentials not found") headers = { "Authorization": f"Bearer {credentials['access_token']}", @@ -201,7 +209,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.", diff --git a/auth4genai/snippets/get-started/langchain-fastapi-py/auth-for-rag.mdx b/auth4genai/snippets/get-started/langchain-fastapi-py/auth-for-rag.mdx index e4fddac8f..08da7e52b 100644 --- a/auth4genai/snippets/get-started/langchain-fastapi-py/auth-for-rag.mdx +++ b/auth4genai/snippets/get-started/langchain-fastapi-py/auth-for-rag.mdx @@ -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" openfga-sdk langgraph langchain-openai "langgraph-cli[inmem]" --prerelease=allow +uv add "auth0-ai-langchain>=1.0.0b4" openfga-sdk langgraph langchain-openai "langgraph-cli[inmem]" --prerelease=allow ``` ### Update the environment file diff --git a/auth4genai/snippets/get-started/langchain-fastapi-py/call-others-api.mdx b/auth4genai/snippets/get-started/langchain-fastapi-py/call-others-api.mdx index 73d05cac1..b50e7948f 100644 --- a/auth4genai/snippets/get-started/langchain-fastapi-py/call-others-api.mdx +++ b/auth4genai/snippets/get-started/langchain-fastapi-py/call-others-api.mdx @@ -15,7 +15,7 @@ import { DownloadQuickstartButton } from "/snippets/download-quickstart/Download - + ### Download sample app Start by downloading and extracting the sample app. Then open in your preferred IDE. =1.0.0b3" "langgraph>=0.5.4" langchain-openai "langgraph-cli[inmem]" google-api-python-client --prerelease=allow +uv add "auth0-ai-langchain>=1.0.0b4" "langgraph>=0.5.4" langchain-openai "langgraph-cli[inmem]>=0.3.6" google-api-python-client --prerelease=allow ``` ### Update your environment file @@ -192,7 +192,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"], ) @@ -244,8 +244,8 @@ from langchain_core.tools import StructuredTool 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, +from auth0_ai_langchain.token_vault import ( + get_access_token_from_token_vault, ) import datetime import json @@ -254,10 +254,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 Google Calendar API" ) calendar_service = build( @@ -329,18 +329,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: +Add a new file, `src/components/auth0-ai/TokenVault/TokenVaultInterruptHandler.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?: { @@ -349,21 +349,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 (
-
{!!chat.interrupt?.value && ( - - \ No newline at end of file + diff --git a/auth4genai/snippets/get-started/langchain-next-js/async-auth.mdx b/auth4genai/snippets/get-started/langchain-next-js/async-auth.mdx index ac8d44740..d741457cb 100644 --- a/auth4genai/snippets/get-started/langchain-next-js/async-auth.mdx +++ b/auth4genai/snippets/get-started/langchain-next-js/async-auth.mdx @@ -35,7 +35,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: @@ -45,8 +45,8 @@ import { AccessDeniedInterrupt } from "@auth0/ai/interrupts"; const auth0AI = new Auth0AI(); -// CIBA flow for user confirmation -export const withAsyncAuthorization = auth0AI.withAsyncUserConfirmation({ +// Async Authorization flow for user confirmation +export const withAsyncAuthorization = auth0AI.withAsyncAuthorization({ userID: async (_params, config) => { return config.configurable?.langgraph_auth_user?.sub; }, @@ -75,9 +75,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 a 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: @@ -240,7 +240,7 @@ export { auth as authHandler }; #### 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 CIBA 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. +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 file `src/lib/tools/shop-online.ts` and add the following code: @@ -248,7 +248,7 @@ Now, create a file `src/lib/tools/shop-online.ts` and add the following code: import { tool } from "@langchain/core/tools"; import { z } from "zod"; -import { getCIBACredentials } from "@auth0/ai-langchain"; +import { getAsyncAuthorizationCredentials } from "@auth0/ai-langchain"; export const shopOnlineTool = tool( async ({ product, qty, priceLimit }) => { @@ -271,7 +271,7 @@ export const shopOnlineTool = tool( priceLimit, }; - const credentials = getCIBACredentials(); + const credentials = getAsyncAuthorizationCredentials(); const accessToken = credentials?.accessToken; if (accessToken) { diff --git a/auth4genai/snippets/get-started/langchain-next-js/call-others-api.mdx b/auth4genai/snippets/get-started/langchain-next-js/call-others-api.mdx index bed0bb2be..8625c9f27 100644 --- a/auth4genai/snippets/get-started/langchain-next-js/call-others-api.mdx +++ b/auth4genai/snippets/get-started/langchain-next-js/call-others-api.mdx @@ -155,7 +155,7 @@ const auth0AI = new Auth0AI({ }); const withAccessTokenForConnection = (connection: string, scopes: string[]) => - auth0AI.withTokenForConnection({ + auth0AI.withTokenVault({ connection, scopes, accessToken: async (_, config) => { @@ -327,7 +327,7 @@ This example uses `GmailSearch` from the `@langchain/community` tools. This tool ```ts src/lib/tools/gmail-seatch.ts wrap lines highlight={10} //... -import { getAccessTokenForConnection } from "@auth0/ai-langchain"; +import { getAccessTokenFromTokenVault } from "@auth0/ai-langchain"; import { GmailSearch } from "@langchain/community/tools/gmail"; import { withGmailSearch } from "../../lib/auth0-ai"; @@ -335,7 +335,7 @@ import { withGmailSearch } from "../../lib/auth0-ai"; export const gmailSearchTool = withGmailSearch( new GmailSearch({ credentials: { - accessToken: async () => getAccessTokenForConnection(), + accessToken: async () => getAccessTokenFromTokenVault(), }, }) ); @@ -371,36 +371,36 @@ When you try to use the tool, the application requests any additional Google sco To implement, install the Auth0 AI Components for Next.js SDK to get the required UI components: ```bash wrap lines -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: +Add a new file, `src/components/auth0-ai/TokenVault/TokenVaultInterruptHandler.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; } -export function FederatedConnectionInterruptHandler({ +export function TokenVaultInterruptHandler({ interrupt, onFinish, -}: FederatedConnectionInterruptHandlerProps) { +}: TokenVaultInterruptHandlerProps) { if ( !interrupt || - !FederatedConnectionInterrupt.isInterrupt(interrupt.value) + !TokenVaultInterrupt.isInterrupt(interrupt.value) ) { return null; } return (
-
- chat.submit(null)} /> + chat.submit(null)} />
) diff --git a/auth4genai/snippets/get-started/vercel-ai-next-js/async-auth.mdx b/auth4genai/snippets/get-started/vercel-ai-next-js/async-auth.mdx index b54cc17e6..1603c1de7 100644 --- a/auth4genai/snippets/get-started/vercel-ai-next-js/async-auth.mdx +++ b/auth4genai/snippets/get-started/vercel-ai-next-js/async-auth.mdx @@ -35,7 +35,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: @@ -47,8 +47,8 @@ import { getUser } from "./auth0"; const auth0AI = new Auth0AI(); -// CIBA flow for user confirmation -export const withAsyncAuthorization = auth0AI.withAsyncUserConfirmation({ +// Async Authorization flow for user confirmation +export const withAsyncAuthorization = auth0AI.withAsyncAuthorization({ userID: async () => { const user = await getUser(); return user?.sub as string; @@ -113,7 +113,7 @@ Now, create and wrap the tool with the Async authorizer. Create a file `src/lib/ import { tool } from "ai"; import { z } from "zod"; -import { getCIBACredentials } from "@auth0/ai-vercel"; +import { getAsyncAuthorizationCredentials } from "@auth0/ai-vercel"; import { withAsyncAuthorization } from "../auth0-ai"; export const shopOnlineTool = withAsyncAuthorization( @@ -144,7 +144,7 @@ export const shopOnlineTool = withAsyncAuthorization( priceLimit, }; - const credentials = getCIBACredentials(); + const credentials = getAsyncAuthorizationCredentials(); const accessToken = credentials?.accessToken; if (accessToken) { diff --git a/auth4genai/snippets/get-started/vercel-ai-next-js/call-others-api.mdx b/auth4genai/snippets/get-started/vercel-ai-next-js/call-others-api.mdx index 66e2d6b59..e0afdc2bc 100644 --- a/auth4genai/snippets/get-started/vercel-ai-next-js/call-others-api.mdx +++ b/auth4genai/snippets/get-started/vercel-ai-next-js/call-others-api.mdx @@ -2,7 +2,7 @@ import { Prerequisites } from "/snippets/get-started/prerequisites/call-others-a import { AccountAndAppSteps } from "/snippets/get-started/prerequisites/account-app-steps.jsx"; import { DownloadQuickstartButton } from "/snippets/download-quickstart/DownloadQuickstartButton.jsx"; - - + ### Download sample app Start by downloading and extracting the sample app. Then open in your preferred IDE. getAccessTokenForConnection(); +export const getAccessToken = async () => getAccessTokenFromTokenVault(); const auth0AI = new Auth0AI(); // Connection for Google services -export const withGoogleConnection = auth0AI.withTokenForConnection({ +export const withGoogleConnection = auth0AI.withTokenVault({ connection: "google-oauth2", scopes: ["https://www.googleapis.com/auth/calendar.events"], refreshToken: getRefreshToken, @@ -162,7 +162,7 @@ Once the user is authenticated, you can fetch an access token from the Token Vau Once you've obtained the access token for a social connection, you can use it with an AI agent to fetch data during a tool call and provide contextual data in its response. In this example, we define a tool call, `getCalendarEventsTool`, that uses the access token with the Google Calendar API to query for calendar events on a specific date. -Update your tool call to request an access token similar to this example: +Update your tool call to request an access token similar to this example: ```ts src/lib/tools/google-calendar.ts wrap lines import { tool } from 'ai'; @@ -170,7 +170,7 @@ import { endOfDay, formatISO, startOfDay } from 'date-fns'; import { GaxiosError } from 'gaxios'; import { google } from 'googleapis'; import { z } from 'zod'; -import { FederatedConnectionError } from '@auth0/ai/interrupts'; +import { TokenVaultError } from '@auth0/ai/interrupts'; import { getAccessToken, withGoogleConnection } from '../auth0-ai'; @@ -229,7 +229,7 @@ export const getCalendarEventsTool = withGoogleConnection( } catch (error) { if (error instanceof GaxiosError) { if (error.status === 401) { - throw new FederatedConnectionError(`Authorization required to access the Federated Connection`); + throw new TokenVaultError(`Authorization required to access the Token Vault connection`); } } @@ -248,31 +248,31 @@ When you try to use the tool, the application requests any additional Google sco To implement, install the Auth0 AI Components for Next.js SDK to get the required UI components: ```bash wrap lines -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: +Add a new file, `src/components/auth0-ai/TokenVault/TokenVaultInterruptHandler.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 { Auth0InterruptionUI } from "@auth0/ai-vercel/react"; -import { EnsureAPIAccess } from "@/components/auth0-ai/FederatedConnections"; +import { TokenVaultConsent } from "@/components/auth0-ai/TokenVault"; -interface FederatedConnectionInterruptHandlerProps { +interface TokenVaultInterruptHandlerProps { interrupt: Auth0InterruptionUI | null; } -export function FederatedConnectionInterruptHandler({ +export function TokenVaultInterruptHandler({ interrupt, -}: FederatedConnectionInterruptHandlerProps) { - if (!FederatedConnectionInterrupt.isInterrupt(interrupt)) { +}: TokenVaultInterruptHandlerProps) { + if (!TokenVaultInterrupt.isInterrupt(interrupt)) { return null; } return (
-
- +
) @@ -399,4 +399,4 @@ That's it! You successfully integrated third-party API access using Token Vault Want to see how it all comes together? Explore or clone the fully implemented sample application [here on GitHub](https://github.com/auth0-samples/auth0-ai-samples/tree/main/call-apis-on-users-behalf/others-api/vercel-ai-next-js). - \ No newline at end of file + diff --git a/auth4genai/snippets/get-started/vercel-ai-node-js/async-auth.mdx b/auth4genai/snippets/get-started/vercel-ai-node-js/async-auth.mdx index 5b155a86f..4cb58d2f0 100644 --- a/auth4genai/snippets/get-started/vercel-ai-node-js/async-auth.mdx +++ b/auth4genai/snippets/get-started/vercel-ai-node-js/async-auth.mdx @@ -52,11 +52,11 @@ STOCK_API_AUDIENCE=sample-stock-api #### 2. Require async authorization for your tool -To require asynchronous authorization for your tool wrap the tool with the Async authorizer, `withAsyncUserConfirmation()`. +To require asynchronous authorization for your tool wrap the tool with the Async authorizer, `withAsyncAuthorization()`. -Wrap the tool with the Async authorizer in `src/lib/tools/buy.ts`. This will intercept the tool call to initiate a CIBA request: +Wrap the tool with the Async authorizer in `src/lib/tools/buy.ts`. 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 `binding_message` containing the consent details, in this case, the quantity of stock to purchase for a stock ticker. - The user responds to the request: @@ -80,7 +80,7 @@ import "dotenv/config"; import { tool } from "ai"; import { z } from "zod"; -import { Auth0AI, getCIBACredentials } from "@auth0/ai-vercel"; +import { Auth0AI, getAsyncAuthorizationCredentials } from "@auth0/ai-vercel"; import { AccessDeniedInterrupt } from "@auth0/ai/interrupts"; export type Context = { userId: string; @@ -90,7 +90,7 @@ const auth0AI = new Auth0AI(); export const buy = (context: Context) => { // highlight-next-line - const withAsyncAuthorization = auth0AI.withAsyncUserConfirmation({ + const withAsyncAuthorization = auth0AI.withAsyncAuthorization({ // highlight-next-line userID: context.userId, // highlight-next-line @@ -135,7 +135,7 @@ export const buy = (context: Context) => { qty: qty, }; // highlight-next-line - const credentials = getCIBACredentials(); + const credentials = getAsyncAuthorizationCredentials(); const accessToken = credentials?.accessToken?.value; if (accessToken) { diff --git a/auth4genai/snippets/get-started/vercel-ai-react-spa-js/call-others-api.mdx b/auth4genai/snippets/get-started/vercel-ai-react-spa-js/call-others-api.mdx index 8531733e8..039d840dd 100644 --- a/auth4genai/snippets/get-started/vercel-ai-react-spa-js/call-others-api.mdx +++ b/auth4genai/snippets/get-started/vercel-ai-react-spa-js/call-others-api.mdx @@ -87,21 +87,21 @@ PORT=3001 Unlike the Next.js example, which uses refresh tokens, this React SPA approach uses **access tokens** for token exchange with Token Vault. The SPA handles step-up authorization using Auth0 SPA SDK's `loginWithPopup()` method to display the consent screen and allow the user to grant additional permissions. -Create `client/src/components/FederatedConnectionPopup.tsx`: +Create `client/src/components/TokenVaultConsentPopup.tsx`: -```tsx client/src/components/FederatedConnectionPopup.tsx wrap lines +```tsx client/src/components/TokenVaultConsentPopup.tsx wrap lines import { getAuth0Client } from "../lib/auth0"; import { Button } from "./ui/button"; import { Card, CardContent, CardHeader, CardTitle } from "./ui/card"; import type { Auth0InterruptionUI } from "@auth0/ai-vercel/react"; -interface FederatedConnectionPopupProps { +interface TokenVaultConsentPopupProps { interrupt: Auth0InterruptionUI; } -export function FederatedConnectionPopup({ +export function TokenVaultConsentPopup({ interrupt, -}: FederatedConnectionPopupProps) { +}: TokenVaultConsentPopupProps) { const [isLoading, setIsLoading] = useState(false); const { connection, requiredScopes, resume } = interrupt; @@ -199,7 +199,7 @@ import { tool } from "ai"; import { google } from "googleapis"; import { z } from "zod"; -import { getAccessTokenForConnection } from "@auth0/ai-vercel"; +import { getAccessTokenFromTokenVault } from "@auth0/ai-vercel"; import type { ToolWrapper } from "@auth0/ai-vercel"; @@ -217,7 +217,7 @@ export const createListUserCalendarsTool = ( parameters: z.object({}), execute: async () => { // Get the access token from Token Vault using the enhanced SDK - const token = getAccessTokenForConnection(); + const token = getAccessTokenFromTokenVault(); const calendar = google.calendar("v3"); const auth = new google.auth.OAuth2(); @@ -267,7 +267,7 @@ export const createGoogleCalendarTool = (c: Context): ToolWrapper => { if (!accessToken) { throw new Error("Access token not available in auth context"); } - return auth0AI.withTokenForConnection({ + return auth0AI.withTokenVault({ accessToken: async () => accessToken, subjectTokenType: SUBJECT_TOKEN_TYPES.SUBJECT_TYPE_ACCESS_TOKEN, connection: process.env.GOOGLE_CONNECTION_NAME || "google-oauth2", @@ -355,7 +355,7 @@ export const app = new Hono().post("/chat", jwtAuthMiddleware(), async (c) => { // Handle Auth0 AI interrupts if ( error.cause instanceof Auth0Interrupt || - error.cause instanceof FederatedConnectionInterrupt + error.cause instanceof TokenVaultInterrupt ) { const serializableError = { ...error.cause.toJSON(), @@ -392,7 +392,7 @@ import { Loader2, Send, Trash2 } from "lucide-react"; import { useChat } from "@ai-sdk/react"; import { useInterruptions } from "@auth0/ai-vercel/react"; import { useAuth0 } from "../hooks/useAuth0"; -import { FederatedConnectionPopup } from "./FederatedConnectionPopup"; +import { TokenVaultConsentPopup } from "./TokenVaultConsentPopup"; import { Button } from "./ui/button"; import { Card, CardContent, CardHeader, CardTitle } from "./ui/card"; import { Input } from "./ui/input"; @@ -512,7 +512,7 @@ export function Chat() { {/* Step-Up Auth Interrupt Handling */} {toolInterrupt && ( - + )} {/* Input form */} @@ -562,6 +562,6 @@ function MessageBubble({ message }: { message: Message }) { The application will automatically prompt for additional calendar permissions when needed using Auth0's step-up authorization flow. -That's it! You've successfully integrated federated connections with access tokens into your React SPA + Vercel AI application. +That's it! You've successfully integrated Token Vault with access tokens into your React SPA + Vercel AI application. Explore [the example app on GitHub](https://github.com/auth0-lab/auth0-ai-js/tree/main/examples/calling-apis/spa-with-backend-api/react-hono-ai-sdk). diff --git a/auth4genai/snippets/how-tos/github/ai-sdk.mdx b/auth4genai/snippets/how-tos/github/ai-sdk.mdx index 7e19b69d5..0b17715bb 100644 --- a/auth4genai/snippets/how-tos/github/ai-sdk.mdx +++ b/auth4genai/snippets/how-tos/github/ai-sdk.mdx @@ -14,7 +14,7 @@ import { auth0 } from "@/lib/auth0"; const auth0AI = new Auth0AI(); -export const withGitHub = auth0AI.withTokenForConnection({ +export const withGitHub = auth0AI.withTokenVault({ connection: "github", scopes: ["repo"], refreshToken: async () => { @@ -37,8 +37,8 @@ Wrap your tool using the Auth0 AI SDK to obtain an access token for the GitHub A ```typescript ./src/lib/tools/listRepositories.ts wrap lines highlight={2-4,9,15,19-21,31-33} import { Octokit, RequestError } from "octokit"; -import { getAccessTokenForConnection } from "@auth0/ai-vercel"; -import { FederatedConnectionError } from "@auth0/ai/interrupts"; +import { getAccessTokenFromTokenVault } from "@auth0/ai-vercel"; +import { TokenVaultError } from "@auth0/ai/interrupts"; import { withGitHub } from "@/lib/auth0-ai"; import { tool } from "ai"; import { z } from "zod"; @@ -50,7 +50,7 @@ export const listRepositories = withGitHub( parameters: z.object({}), execute: async () => { // Get the access token from Auth0 AI - const accessToken = getAccessTokenForConnection(); + const accessToken = getAccessTokenFromTokenVault(); // GitHub SDK try { @@ -66,8 +66,8 @@ export const listRepositories = withGitHub( if (error instanceof RequestError) { if (error.status === 401) { - throw new FederatedConnectionError( - `Authorization required to access the Federated Connection` + throw new TokenVaultError( + `Authorization required to access the Token Vault connection` ); } } @@ -126,10 +126,10 @@ export async function POST(request: Request) { #### Client Side -On this example we utilize the `EnsureAPIAccessPopup` 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: +On this example we utilize the `TokenVaultConsentPopup` 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: ```bash wrap lines -npx @auth0/ai-components add FederatedConnections +npx @auth0/ai-components add TokenVault ``` Then, you can integrate the authentication popup in your chat component, using the interruptions helper from the SDK: @@ -139,8 +139,8 @@ Then, you can integrate the authentication popup in your chat component, using t import { useChat } from "@ai-sdk/react"; import { useInterruptions } from "@auth0/ai-vercel/react"; -import { FederatedConnectionInterrupt } from "@auth0/ai/interrupts"; -import { EnsureAPIAccessPopup } from "@/components/auth0-ai/FederatedConnections/popup"; +import { TokenVaultInterrupt } from "@auth0/ai/interrupts"; +import { TokenVaultConsentPopup } from "@/components/auth0-ai/TokenVault/popup"; export default function Chat() { const { messages, handleSubmit, input, setInput, toolInterrupt } = @@ -159,8 +159,8 @@ export default function Chat() {
))} - {FederatedConnectionInterrupt.isInterrupt(toolInterrupt) && ( - ({ threadID: getAgent().name })); const auth0AI = new Auth0AI(); -export const withGitHub = auth0AI.withTokenForConnection({ +export const withGitHub = auth0AI.withTokenVault({ connection: "github", scopes: ["repo"], refreshToken: async () => { @@ -52,8 +52,8 @@ Wrap your tool using the Auth0 AI SDK to obtain an access token for the Github A ```typescript ./src/agent/tools/listRepositories.ts wrap lines highlight={2-4,9,15,19-21,31-33} import { Octokit, RequestError } from "octokit"; -import { getAccessTokenForConnection } from "@auth0/ai-vercel"; -import { FederatedConnectionError } from "@auth0/ai/interrupts"; +import { getAccessTokenFromTokenVault } from "@auth0/ai-vercel"; +import { TokenVaultError } from "@auth0/ai/interrupts"; import { withGitHub } from "@/lib/auth0-ai"; import { tool } from "ai"; import { z } from "zod"; @@ -65,7 +65,7 @@ export const listRepositories = withGitHub( parameters: z.object({}), execute: async () => { // Get the access token from Auth0 AI - const accessToken = getAccessTokenForConnection(); + const accessToken = getAccessTokenFromTokenVault(); // GitHub SDK try { @@ -81,8 +81,8 @@ export const listRepositories = withGitHub( if (error instanceof RequestError) { if (error.status === 401) { - throw new FederatedConnectionError( - `Authorization required to access the Federated Connection` + throw new TokenVaultError( + `Authorization required to access the Token Vault connection` ); } } @@ -180,10 +180,10 @@ The name of the user is ${claims?.name ?? "unknown"}. #### Client Side -On this example we utilize the `EnsureAPIAccessPopup` 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: +In this example, we utilize the `TokenVaultConsentPopup` component to show a pop-up 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: ```bash wrap lines -npx @auth0/ai-components add FederatedConnections +npx @auth0/ai-components add TokenVault ``` Then, you can integrate the authentication popup in your chat component, using the interruptions helper from the SDK: @@ -193,8 +193,8 @@ Then, you can integrate the authentication popup in your chat component, using t import { useChat } from "@ai-sdk/react"; import { useAgentChatInterruptions } from "@auth0/ai-cloudflare/react"; -import { FederatedConnectionInterrupt } from "@auth0/ai/interrupts"; -import { EnsureAPIAccessPopup } from "@/components/auth0-ai/FederatedConnections/popup"; +import { TokenVaultInterrupt } from "@auth0/ai/interrupts"; +import { TokenVaultConsentPopup } from "@/components/auth0-ai/TokenVault/popup"; export default function Chat() { @@ -221,8 +221,8 @@ export default function Chat() {
))} - {FederatedConnectionInterrupt.isInterrupt(toolInterrupt) && ( - { @@ -42,8 +42,8 @@ Wrap your tool using the Auth0 AI SDK to obtain an access token for the GitHub A ```typescript ./src/lib/tools/listRepositories.ts wrap lines highlight={3-5,11,19,33-35} import { Octokit, RequestError } from "octokit"; import { z } from "zod"; -import { getAccessTokenForConnection } from "@auth0/ai-genkit"; -import { FederatedConnectionError } from "@auth0/ai/interrupts"; +import { getAccessTokenFromTokenVault } from "@auth0/ai-genkit"; +import { TokenVaultError } from "@auth0/ai/interrupts"; import { withGoogleCalendar } from "@/lib/auth0-ai"; // importing GenKit instance @@ -58,7 +58,7 @@ export const listRepositories = ai.defineTool( }, async () => { // Get the access token from Auth0 AI - const accessToken = getAccessTokenForConnection(); + const accessToken = getAccessTokenFromTokenVault(); try { // GitHub SDK @@ -72,8 +72,8 @@ export const listRepositories = ai.defineTool( } catch (error) { if (error instanceof RequestError) { if (error.status === 401) { - throw new FederatedConnectionError( - `Authorization required to access the Federated Connection` + throw new TokenVaultError( + `Authorization required to access the Token Vault connection` ); } } @@ -174,10 +174,10 @@ export async function GET( #### Client Side -On this example we utilize the `EnsureAPIAccessPopup` component to show a popup that allows the user to authenticate with Google Calendar and grant access with the requested scopes. You'll first need to install the `@auth0/ai-components` package: +In this example, we utilize the `TokenVaultConsentPopup` component to show a pop-up that allows the user to authenticate with Google Calendar and grant access with the requested scopes. You'll first need to install the `@auth0/ai-components` package: ```bash wrap lines -npx @auth0/ai-components add FederatedConnections +npx @auth0/ai-components add TokenVault ``` Then, you can integrate the authentication popup in your chat component, using the interruptions helper from the SDK: @@ -186,8 +186,8 @@ Then, you can integrate the authentication popup in your chat component, using t "use client"; import { useQueryState } from "nuqs"; import { FormEventHandler, useEffect, useRef, useState } from "react"; -import { FederatedConnectionInterrupt } from "@auth0/ai/interrupts"; -import { EnsureAPIAccessPopup } from "@/components/auth0-ai/FederatedConnections/popup"; +import { TokenVaultInterrupt } from "@auth0/ai/interrupts"; +import { TokenVaultConsentPopup } from "@/components/auth0-ai/TokenVault/popup"; import Markdown from "react-markdown"; const useFocus = () => { @@ -304,14 +304,14 @@ export default function Chat() { {!isLoading && message.content[0].metadata?.interrupt && - FederatedConnectionInterrupt.isInterrupt( + TokenVaultInterrupt.isInterrupt( message.content[0].metadata?.interrupt ) ? (() => { const interrupt: any = message.content[0].metadata?.interrupt; return (
- submit({ interruptedToolRequest: message.content[0] })} interrupt={interrupt} connectWidget={{ diff --git a/auth4genai/snippets/how-tos/github/langgraph-python.mdx b/auth4genai/snippets/how-tos/github/langgraph-python.mdx index 3388d5bac..444a9c888 100644 --- a/auth4genai/snippets/how-tos/github/langgraph-python.mdx +++ b/auth4genai/snippets/how-tos/github/langgraph-python.mdx @@ -13,7 +13,7 @@ from auth0_ai_langchain.auth0_ai import Auth0AI auth0_ai = Auth0AI() -with_github = auth0_ai.with_federated_connection( +with_github = auth0_ai.with_token_vault( connection="github", scopes=["repo"] # Optional: By default, the SDK will expect the refresh token from @@ -32,7 +32,7 @@ from github import Github from github.GithubException import BadCredentialsException from pydantic import BaseModel from langchain_core.tools import StructuredTool -from auth0_ai_langchain.federated_connections import get_access_token_for_connection, FederatedConnectionError +from auth0_ai_langchain.token_vault import get_access_token_from_token_vault, TokenVaultError from src.lib.auth0_ai import with_github class EmptySchema(BaseModel): @@ -40,7 +40,7 @@ class EmptySchema(BaseModel): def list_repositories_tool_function(date: datetime): # Get the access token from Auth0 AI - access_token = get_access_token_for_connection() + access_token = get_access_token_from_token_vault() # GitHub SDK try: @@ -50,7 +50,7 @@ def list_repositories_tool_function(date: datetime): repo_names = [repo.name for repo in repos] return repo_names except BadCredentialsException: - raise FederatedConnectionError("Authorization required to access the Federated Connection API") + raise TokenVaultError("Authorization required to access the Token Vault API") list_github_repositories_tool = with_github(StructuredTool( name="list_github_repositories", @@ -98,7 +98,7 @@ workflow = ( "tools", ToolNode( [ - # a tool with federated connection access + # a tool with Token Vault access list_github_repositories_tool, # ... other tools ], @@ -167,18 +167,18 @@ You can check different authentication options for Next.js with Auth0 at the [of #### Client Side -On this example we utilize the `EnsureAPIAccessPopup` 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: +In this example, we utilize the `TokenVaultConsentPopup` component to show a pop-up 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: ```bash wrap lines -npx @auth0/ai-components add FederatedConnections +npx @auth0/ai-components add TokenVault ``` Then, you can integrate the authentication popup in your chat component, using the interruptions helper from the SDK: ```tsx ./src/components/chat.tsx wrap lines highlight={2-3,62-74} import { useStream } from "@langchain/langgraph-sdk/react"; -import { FederatedConnectionInterrupt } from "@auth0/ai/interrupts"; -import { EnsureAPIAccessPopup } from "@/components/auth0-ai/FederatedConnections/popup"; +import { TokenVaultInterrupt } from "@auth0/ai/interrupts"; +import { TokenVaultConsentPopup } from "@/components/auth0-ai/TokenVault/popup"; const useFocus = () => { const htmlElRef = useRef(null); @@ -237,9 +237,9 @@ export default function Chat() {
))} - {thread.interrupt && FederatedConnectionInterrupt.isInterrupt(thread.interrupt.value) ? ( + {thread.interrupt && TokenVaultInterrupt.isInterrupt(thread.interrupt.value) ? (
- thread.submit(null)} connectWidget={{ diff --git a/auth4genai/snippets/how-tos/github/langgraph.mdx b/auth4genai/snippets/how-tos/github/langgraph.mdx index c6adce65c..f2255da74 100644 --- a/auth4genai/snippets/how-tos/github/langgraph.mdx +++ b/auth4genai/snippets/how-tos/github/langgraph.mdx @@ -21,7 +21,7 @@ const auth0AI = new Auth0AI({ }); const withAccessTokenForConnection = (connection: string, scopes: string[]) => - auth0AI.withTokenForConnection({ + auth0AI.withTokenVault({ connection, scopes, accessToken: async (_, config) => { @@ -40,8 +40,8 @@ Wrap your tool using the Auth0 AI SDK to obtain an access token for the GitHub A ```typescript ./src/lib/tools/listRepositories.ts wrap lines highlight={3-5,9,12,16-18,28-30} import { Octokit } from "@octokit/rest"; import { RequestError } from "@octokit/request-error"; -import { getAccessTokenForConnection } from "@auth0/ai-langchain"; -import { FederatedConnectionError } from "@auth0/ai/interrupts"; +import { getAccessTokenFromTokenVault } from "@auth0/ai-langchain"; +import { TokenVaultError } from "@auth0/ai/interrupts"; import { withGitHub } from "@/lib/auth0-ai"; import { tool } from "@langchain/core/tools"; import { z } from "zod"; @@ -49,7 +49,7 @@ import { z } from "zod"; export const listRepositories = withGitHub( tool(async () => { // Get the access token from Auth0 AI - const accessToken = getAccessTokenForConnection(); + const accessToken = getAccessTokenFromTokenVault(); // GitHub SDK try { @@ -65,8 +65,8 @@ export const listRepositories = withGitHub( if (error instanceof RequestError) { if (error.status === 401) { - throw new FederatedConnectionError( - `Authorization required to access the Federated Connection` + throw new TokenVaultError( + `Authorization required to access the Token Vault connection` ); } } @@ -116,7 +116,7 @@ const stateGraph = new StateGraph(MessagesAnnotation) "tools", new ToolNode( [ - // A tool with federated connection access + // A tool with Token Vault access listRepositories, // ... other tools ], @@ -297,18 +297,18 @@ export { auth as authHandler }; #### Client Side -On this example we utilize the `EnsureAPIAccessPopup` 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: +In this example, we utilize the `TokenVaultConsentPopup` component to show a pop-up 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: ```bash wrap lines -npx @auth0/ai-components add FederatedConnections +npx @auth0/ai-components add TokenVault ``` Then, you can integrate the authentication popup in your chat component, using the interruptions helper from the SDK: ```tsx ./src/components/chat.tsx wrap lines highlight={2-3,62-74} import { useStream } from "@langchain/langgraph-sdk/react"; -import { FederatedConnectionInterrupt } from "@auth0/ai/interrupts"; -import { EnsureAPIAccessPopup } from "@/components/auth0-ai/FederatedConnections/popup"; +import { TokenVaultInterrupt } from "@auth0/ai/interrupts"; +import { TokenVaultConsentPopup } from "@/components/auth0-ai/TokenVault/popup"; const useFocus = () => { const htmlElRef = useRef(null); @@ -367,9 +367,9 @@ export default function Chat() {
))} - {thread.interrupt && FederatedConnectionInterrupt.isInterrupt(thread.interrupt.value) ? ( + {thread.interrupt && TokenVaultInterrupt.isInterrupt(thread.interrupt.value) ? (
- thread.submit(null)} connectWidget={{ diff --git a/auth4genai/snippets/how-tos/github/llamaindex-python.mdx b/auth4genai/snippets/how-tos/github/llamaindex-python.mdx index d20405916..b0bfc643f 100644 --- a/auth4genai/snippets/how-tos/github/llamaindex-python.mdx +++ b/auth4genai/snippets/how-tos/github/llamaindex-python.mdx @@ -14,7 +14,7 @@ from flask import session auth0_ai = Auth0AI() -with_github = auth0_ai.with_federated_connection( +with_github = auth0_ai.with_token_vault( connection="github", scopes=["repo"], refresh_token=lambda *_args, **_kwargs:session["user"]["refresh_token"], @@ -32,12 +32,12 @@ Wrap your tool using the Auth0 AI SDK to obtain an access token for the GitHub A from github import Github from github.GithubException import BadCredentialsException from llama_index.core.tools import FunctionTool -from auth0_ai_llamaindex.federated_connections import get_access_token_for_connection, FederatedConnectionError +from auth0_ai_llamaindex.token_vault import get_access_token_from_token_vault, TokenVaultError from src.lib.auth0_ai import with_github def list_github_repositories_tool_function(): # Get the access token from Auth0 AI - access_token = get_access_token_for_connection() + access_token = get_access_token_from_token_vault() # GitHub SDK try: @@ -47,7 +47,7 @@ def list_github_repositories_tool_function(): repo_names = [repo.name for repo in repos] return repo_names except BadCredentialsException: - raise FederatedConnectionError("Authorization required to access the Federated Connection") + raise TokenVaultError("Authorization required to access the Token Vault API") list_github_repositories_tool = with_github(FunctionTool.from_defaults( name="list_github_repositories", @@ -70,7 +70,7 @@ system_prompt = f"""You are an assistant designed to answer random user's questi agent = OpenAIAgent.from_tools( tools=[ - # a tool with federated connection access + # a tool with Token Vault access list_github_repositories_tool # ... other tools ], @@ -88,14 +88,14 @@ Interrupts are a way for the system to pause execution and prompt the user to ta On the server side of your Flask application you will need to set up a route to handle the Chat API requests. This route will be responsible for forwarding the requests to the OpenAI API utilizing LlamaIndex's SDK, that has been initialized with Auth0 AI's protection enhancements for tools. -When `FederatedConnectionInterrupt` error ocurrs, the server side will signal the front-end about the level access restrictions, and the front-end should prompt the user to trigger a new authorization (or login) request with the necessary permissions. +When `TokenVaultInterrupt` error ocurrs, the server side will signal the front-end about the level access restrictions, and the front-end should prompt the user to trigger a new authorization (or login) request with the necessary permissions. ```python ./src/app.py wrap lines highlight={3-5,19-20} from dotenv import load_dotenv from flask import Flask, request, jsonify, session from auth0_ai_llamaindex.auth0_ai import Auth0AI -from auth0_ai_llamaindex.federated_connections import FederatedConnectionInterrupt +from auth0_ai_llamaindex.token_vault import TokenVaultInterrupt from src.lib.agent import agent load_dotenv() @@ -110,7 +110,7 @@ async def chat(): message = request.json.get("message") response = agent.achat(message) return jsonify({"response": str(response)}) - except FederatedConnectionInterrupt as e: + except TokenVaultInterrupt as e: return jsonify({"error": str(e.to_json())}), 403 except Exception as e: return jsonify({"error": str(e)}), 500 diff --git a/auth4genai/snippets/how-tos/github/llamaindex.mdx b/auth4genai/snippets/how-tos/github/llamaindex.mdx index f25ebff31..3c7c59a0b 100644 --- a/auth4genai/snippets/how-tos/github/llamaindex.mdx +++ b/auth4genai/snippets/how-tos/github/llamaindex.mdx @@ -14,7 +14,7 @@ import { auth0 } from "@/lib/auth0"; const auth0AI = new Auth0AI(); -export const withGitHub = auth0AI.withTokenForConnection({ +export const withGitHub = auth0AI.withTokenVault({ connection: "github", scopes: ["repo"], refreshToken: async () => { @@ -38,8 +38,8 @@ Wrap your tool using the Auth0 AI SDK to obtain an access token for the GitHub A import { Octokit, RequestError } from "octokit"; import { z } from "zod"; import { withGitHub } from "@/lib/auth0-ai"; -import { getAccessTokenForConnection } from "@auth0/ai-vercel"; -import { FederatedConnectionError } from "@auth0/ai/interrupts"; +import { getAccessTokenFromTokenVault } from "@auth0/ai-vercel"; +import { TokenVaultError } from "@auth0/ai/interrupts"; import { tool } from "llamaindex"; export const listRepositories = () => @@ -47,7 +47,7 @@ export const listRepositories = () => tool( async () => { // Get the access token from Auth0 AI - const accessToken = getAccessTokenForConnection(); + const accessToken = getAccessTokenFromTokenVault(); // GitHub SDK try { @@ -61,8 +61,8 @@ export const listRepositories = () => } catch (error) { if (error instanceof RequestError) { if (error.status === 401) { - throw new FederatedConnectionError( - `Authorization required to access the Federated Connection` + throw new TokenVaultError( + `Authorization required to access the Token Vault connection` ); } } @@ -132,10 +132,10 @@ export async function POST(request: Request) { #### Client Side -On this example we utilize the `EnsureAPIAccessPopup` 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: +In this example, we utilize the `TokenVaultConsentPopup` component to show a pop-up 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: ```bash wrap lines -npx @auth0/ai-components add FederatedConnections +npx @auth0/ai-components add TokenVault ``` Then, you can integrate the authentication popup in your chat component, using the interruptions helper from the SDK: @@ -144,9 +144,9 @@ Then, you can integrate the authentication popup in your chat component, using t "use client"; import { generateId } from "ai"; -import { EnsureAPIAccessPopup } from "@/components/auth0-ai/FederatedConnections/popup"; +import { TokenVaultConsentPopup } from "@/components/auth0-ai/TokenVault/popup"; import { useInterruptions } from "@auth0/ai-vercel/react"; -import { FederatedConnectionInterrupt } from "@auth0/ai/interrupts"; +import { TokenVaultInterrupt } from "@auth0/ai/interrupts"; import { useChat } from "@ai-sdk/react"; export default function Chat() { @@ -169,8 +169,8 @@ export default function Chat() { {message.parts && message.parts.length > 0 && (
{toolInterrupt?.toolCall.id.includes(message.id) && - FederatedConnectionInterrupt.isInterrupt(toolInterrupt) && ( - { @@ -40,8 +40,8 @@ Wrap your tool using the Auth0 AI SDK to obtain an access token for the Google C import { addHours, formatISO } from "date-fns"; import { GaxiosError } from "gaxios"; import { google } from "googleapis"; -import { getAccessTokenForConnection } from "@auth0/ai-vercel"; -import { FederatedConnectionError } from "@auth0/ai/interrupts"; +import { getAccessTokenFromTokenVault } from "@auth0/ai-vercel"; +import { TokenVaultError } from "@auth0/ai/interrupts"; import { withGoogleCalendar } from "@/lib/auth0-ai"; import { tool } from "ai"; import { z } from "zod"; @@ -55,7 +55,7 @@ export const checkUsersCalendar = withGoogleCalendar( }), execute: async ({ date }) => { // Get the access token from Auth0 AI - const accessToken = getAccessTokenForConnection(); + const accessToken = getAccessTokenFromTokenVault(); // Google SDK try { @@ -82,8 +82,8 @@ export const checkUsersCalendar = withGoogleCalendar( } catch (error) { if (error instanceof GaxiosError) { if (error.status === 401) { - throw new FederatedConnectionError( - `Authorization required to access the Federated Connection` + throw new TokenVaultError( + `Authorization required to access the Token Vault connection` ); } } @@ -142,10 +142,10 @@ export async function POST(request: Request) { #### Client Side -On this example we utilize the `EnsureAPIAccessPopup` component to show a popup that allows the user to authenticate with Google Calendar and grant access with the requested scopes. You'll first need to install the `@auth0/ai-components` package: +In this example, we utilize the `TokenVaultConsentPopup` component to show a pop-up that allows the user to authenticate with Google Calendar and grant access with the requested scopes. You'll first need to install the `@auth0/ai-components` package: ```bash wrap lines -npx @auth0/ai-components add FederatedConnections +npx @auth0/ai-components add TokenVault ``` Then, you can integrate the authentication popup in your chat component, using the interruptions helper from the SDK: @@ -155,8 +155,8 @@ Then, you can integrate the authentication popup in your chat component, using t import { useChat } from "@ai-sdk/react"; import { useInterruptions } from "@auth0/ai-vercel/react"; -import { FederatedConnectionInterrupt } from "@auth0/ai/interrupts"; -import { EnsureAPIAccessPopup } from "@/components/auth0-ai/FederatedConnections/popup"; +import { TokenVaultInterrupt } from "@auth0/ai/interrupts"; +import { TokenVaultConsentPopup } from "@/components/auth0-ai/TokenVault/popup"; export default function Chat() { const { messages, handleSubmit, input, setInput, toolInterrupt } = @@ -175,8 +175,8 @@ export default function Chat() {
))} - {FederatedConnectionInterrupt.isInterrupt(toolInterrupt) && ( - ({ threadID: getAgent().name })); const auth0AI = new Auth0AI(); -export const withGoogleCalendar = auth0AI.withTokenForConnection({ +export const withGoogleCalendar = auth0AI.withTokenVault({ connection: "google-oauth2", scopes: ["https://www.googleapis.com/auth/calendar.freebusy"], refreshToken: async () => { @@ -52,8 +52,8 @@ Wrap your tool using the Auth0 AI SDK to obtain an access token for the Google C import { addHours, formatISO } from "date-fns"; import { GaxiosError } from "gaxios"; import { google } from "googleapis"; -import { getAccessTokenForConnection } from "@auth0/ai-vercel"; -import { FederatedConnectionError } from "@auth0/ai/interrupts"; +import { getAccessTokenFromTokenVault } from "@auth0/ai-vercel"; +import { TokenVaultError } from "@auth0/ai/interrupts"; import { withGoogleCalendar } from "@/lib/auth0-ai"; import { tool } from "ai"; import { z } from "zod"; @@ -67,7 +67,7 @@ export const checkUsersCalendar = withGoogleCalendar( }), execute: async ({ date }) => { // Get the access token from Auth0 AI - const accessToken = getAccessTokenForConnection(); + const accessToken = getAccessTokenFromTokenVault(); // Google SDK try { @@ -94,8 +94,8 @@ export const checkUsersCalendar = withGoogleCalendar( } catch (error) { if (error instanceof GaxiosError) { if (error.status === 401) { - throw new FederatedConnectionError( - `Authorization required to access the Federated Connection` + throw new TokenVaultError( + `Authorization required to access the Token Vault connection` ); } } @@ -193,10 +193,10 @@ The name of the user is ${claims?.name ?? "unknown"}. #### Client Side -On this example we utilize the `EnsureAPIAccessPopup` component to show a popup that allows the user to authenticate with Google Calendar and grant access with the requested scopes. You'll first need to install the `@auth0/ai-components` package: +In this example, we utilize the `TokenVaultConsentPopup` component to show a pop-up that allows the user to authenticate with Google Calendar and grant access with the requested scopes. You'll first need to install the `@auth0/ai-components` package: ```bash wrap lines -npx @auth0/ai-components add FederatedConnections +npx @auth0/ai-components add TokenVault ``` Then, you can integrate the authentication popup in your chat component, using the interruptions helper from the SDK: @@ -206,8 +206,8 @@ Then, you can integrate the authentication popup in your chat component, using t import { useChat } from "@ai-sdk/react"; import { useAgentChatInterruptions } from "@auth0/ai-cloudflare/react"; -import { FederatedConnectionInterrupt } from "@auth0/ai/interrupts"; -import { EnsureAPIAccessPopup } from "@/components/auth0-ai/FederatedConnections/popup"; +import { TokenVaultInterrupt } from "@auth0/ai/interrupts"; +import { TokenVaultConsentPopup } from "@/components/auth0-ai/TokenVault/popup"; export default function Chat() { @@ -234,8 +234,8 @@ export default function Chat() {
))} - {FederatedConnectionInterrupt.isInterrupt(toolInterrupt) && ( - { @@ -41,8 +41,8 @@ Wrap your tool using the Auth0 AI SDK to obtain an access token for the Google C ```typescript ./src/lib/tools/checkUsersCalendar.ts wrap lines highlight={3-5,11,24,31-33,51-53} import { addHours } from "date-fns"; import { z } from "zod"; -import { getAccessTokenForConnection } from "@auth0/ai-genkit"; -import { FederatedConnectionError } from "@auth0/ai/interrupts"; +import { getAccessTokenFromTokenVault } from "@auth0/ai-genkit"; +import { TokenVaultError } from "@auth0/ai/interrupts"; import { withGoogleCalendar } from "@/lib/auth0-ai"; // importing GenKit instance @@ -62,7 +62,7 @@ export const checkUsersCalendar = ai.defineTool( }, async ({ date }) => { // Get the access token from Auth0 AI - const accessToken = getAccessTokenForConnection(); + const accessToken = getAccessTokenFromTokenVault(); // Google SDK try { @@ -89,8 +89,8 @@ export const checkUsersCalendar = ai.defineTool( } catch (error) { if (error instanceof GaxiosError) { if (error.status === 401) { - throw new FederatedConnectionError( - `Authorization required to access the Federated Connection` + throw new TokenVaultError( + `Authorization required to access the Token Vault connection` ); } } @@ -191,10 +191,10 @@ export async function GET( #### Client Side -On this example we utilize the `EnsureAPIAccessPopup` component to show a popup that allows the user to authenticate with Google Calendar and grant access with the requested scopes. You'll first need to install the `@auth0/ai-components` package: +In this example, we utilize the `TokenVaultConsentPopup` component to show a pop-up that allows the user to authenticate with Google Calendar and grant access with the requested scopes. You'll first need to install the `@auth0/ai-components` package: ```bash wrap lines -npx @auth0/ai-components add FederatedConnections +npx @auth0/ai-components add TokenVault ``` Then, you can integrate the authentication popup in your chat component, using the interruptions helper from the SDK: @@ -203,8 +203,8 @@ Then, you can integrate the authentication popup in your chat component, using t "use client"; import { useQueryState } from "nuqs"; import { FormEventHandler, useEffect, useRef, useState } from "react"; -import { FederatedConnectionInterrupt } from "@auth0/ai/interrupts"; -import { EnsureAPIAccessPopup } from "@/components/auth0-ai/FederatedConnections/popup"; +import { TokenVaultInterrupt } from "@auth0/ai/interrupts"; +import { TokenVaultConsentPopup } from "@/components/auth0-ai/TokenVault/popup"; import Markdown from "react-markdown"; const useFocus = () => { @@ -321,14 +321,14 @@ export default function Chat() { {!isLoading && message.content[0].metadata?.interrupt && - FederatedConnectionInterrupt.isInterrupt( + TokenVaultInterrupt.isInterrupt( message.content[0].metadata?.interrupt ) ? (() => { const interrupt: any = message.content[0].metadata?.interrupt; return (
- submit({ interruptedToolRequest: message.content[0] })} interrupt={interrupt} connectWidget={{ @@ -350,4 +350,4 @@ export default function Chat() {
); } -``` \ No newline at end of file +``` diff --git a/auth4genai/snippets/how-tos/google-calendar/langgraph-python.mdx b/auth4genai/snippets/how-tos/google-calendar/langgraph-python.mdx index 26b9cc271..72e82bb40 100644 --- a/auth4genai/snippets/how-tos/google-calendar/langgraph-python.mdx +++ b/auth4genai/snippets/how-tos/google-calendar/langgraph-python.mdx @@ -13,7 +13,7 @@ from auth0_ai_langchain.auth0_ai import Auth0AI auth0_ai = Auth0AI() -with_google = auth0_ai.with_federated_connection( +with_google = auth0_ai.with_token_vault( connection="google-oauth2", scopes=["https://www.googleapis.com/auth/calendar.freebusy"] # Optional: By default, the SDK will expect the refresh token from @@ -34,7 +34,7 @@ from googleapiclient.discovery import build from google.oauth2.credentials import Credentials from pydantic import BaseModel from langchain_core.tools import StructuredTool -from auth0_ai_langchain.federated_connections import get_access_token_for_connection, FederatedConnectionError +from auth0_ai_langchain.token_vault import get_access_token_from_token_vault, TokenVaultError from lib.auth0_ai import with_google class CheckUserCalendarSchema(BaseModel): @@ -42,7 +42,7 @@ class CheckUserCalendarSchema(BaseModel): def check_user_calendar_tool_function(date: datetime): # Get the access token from Auth0 AI - access_token = get_access_token_for_connection() + access_token = get_access_token_from_token_vault() # Google SDK try: @@ -61,7 +61,7 @@ def check_user_calendar_tool_function(date: datetime): return {"available": len(busy_times) == 0} except HttpError as e: if e.resp.status == 401: - raise FederatedConnectionError("Authorization required to access the Federated Connection API") + raise TokenVaultError("Authorization required to access the Token Vault API") raise ValueError(f"Invalid response from Google Calendar API: {response.status_code} - {response.text}") @@ -111,7 +111,7 @@ workflow = ( "tools", ToolNode( [ - # a tool with federated connection access + # a tool with Token Vault access check_user_calendar_tool, # ... other tools ], @@ -180,18 +180,18 @@ You can check different authentication options for Next.js with Auth0 at the [of #### Client Side -On this example we utilize the `EnsureAPIAccessPopup` component to show a popup that allows the user to authenticate with Google Calendar and grant access with the requested scopes. You'll first need to install the `@auth0/ai-components` package: +In this example, we utilize the `TokenVaultConsentPopup` component to show a pop-up that allows the user to authenticate with Google Calendar and grant access with the requested scopes. You'll first need to install the `@auth0/ai-components` package: ```bash wrap lines -npx @auth0/ai-components add FederatedConnections +npx @auth0/ai-components add TokenVault ``` Then, you can integrate the authentication popup in your chat component, using the interruptions helper from the SDK: ```tsx ./src/components/chat.tsx wrap lines highlight={2-3,62-74} import { useStream } from "@langchain/langgraph-sdk/react"; -import { FederatedConnectionInterrupt } from "@auth0/ai/interrupts"; -import { EnsureAPIAccessPopup } from "@/components/auth0-ai/FederatedConnections/popup"; +import { TokenVaultInterrupt } from "@auth0/ai/interrupts"; +import { TokenVaultConsentPopup } from "@/components/auth0-ai/TokenVault/popup"; const useFocus = () => { const htmlElRef = useRef(null); @@ -250,9 +250,9 @@ export default function Chat() {
))} - {thread.interrupt && FederatedConnectionInterrupt.isInterrupt(thread.interrupt.value) ? ( + {thread.interrupt && TokenVaultInterrupt.isInterrupt(thread.interrupt.value) ? (
- thread.submit(null)} connectWidget={{ diff --git a/auth4genai/snippets/how-tos/google-calendar/langgraph.mdx b/auth4genai/snippets/how-tos/google-calendar/langgraph.mdx index 828075d88..efdbe3506 100644 --- a/auth4genai/snippets/how-tos/google-calendar/langgraph.mdx +++ b/auth4genai/snippets/how-tos/google-calendar/langgraph.mdx @@ -21,7 +21,7 @@ const auth0AI = new Auth0AI({ }); const withAccessTokenForConnection = (connection: string, scopes: string[]) => - auth0AI.withTokenForConnection({ + auth0AI.withTokenVault({ connection, scopes, accessToken: async (_, config) => { @@ -44,8 +44,8 @@ Wrap your tool using the Auth0 AI SDK to obtain an access token for the Google C import { addHours, formatISO } from "date-fns"; import { GaxiosError } from "gaxios"; import { google } from "googleapis"; -import { getAccessTokenForConnection } from "@auth0/ai-langchain"; -import { FederatedConnectionError } from "@auth0/ai/interrupts"; +import { getAccessTokenFromTokenVault } from "@auth0/ai-langchain"; +import { TokenVaultError } from "@auth0/ai/interrupts"; import { withGoogleCalendar } from "@/lib/auth0-ai"; import { tool } from "@langchain/core/tools"; import { z } from "zod"; @@ -53,7 +53,7 @@ import { z } from "zod"; export const checkUsersCalendar = withGoogleCalendar( tool(async ({ date }) => { // Get the access token from Auth0 AI - const accessToken = getAccessTokenForConnection(); + const accessToken = getAccessTokenFromTokenVault(); // Google SDK try { @@ -79,8 +79,8 @@ export const checkUsersCalendar = withGoogleCalendar( }; } catch (err) { if (err instanceof GaxiosError && err.status === 401) { - throw new FederatedConnectionError( - `Authorization required to access the Federated Connection` + throw new TokenVaultError( + `Authorization required to access the Token Vault connection` ); } throw err; @@ -131,7 +131,7 @@ const stateGraph = new StateGraph(MessagesAnnotation) "tools", new ToolNode( [ - // A tool with federated connection access + // A tool with Token Vault access checkUsersCalendar, // ... other tools ], @@ -310,18 +310,18 @@ export { auth as authHandler }; #### Client Side -On this example we utilize the `EnsureAPIAccessPopup` component to show a popup that allows the user to authenticate with Google Calendar and grant access with the requested scopes. You'll first need to install the `@auth0/ai-components` package: +In this example, we utilize the `TokenVaultConsentPopup` component to show a pop-up that allows the user to authenticate with Google Calendar and grant access with the requested scopes. You'll first need to install the `@auth0/ai-components` package: ```bash wrap lines -npx @auth0/ai-components add FederatedConnections +npx @auth0/ai-components add TokenVault ``` Then, you can integrate the authentication popup in your chat component, using the interruptions helper from the SDK: ```tsx ./src/components/chat.tsx wrap lines highlight={2-3,63-73} import { useStream } from "@langchain/langgraph-sdk/react"; -import { FederatedConnectionInterrupt } from "@auth0/ai/interrupts"; -import { EnsureAPIAccessPopup } from "@/components/auth0-ai/FederatedConnections/popup"; +import { TokenVaultInterrupt } from "@auth0/ai/interrupts"; +import { TokenVaultConsentPopup } from "@/components/auth0-ai/TokenVault/popup"; const useFocus = () => { const htmlElRef = useRef(null); @@ -380,9 +380,9 @@ export default function Chat() {
))} - {thread.interrupt && FederatedConnectionInterrupt.isInterrupt(thread.interrupt.value) ? ( + {thread.interrupt && TokenVaultInterrupt.isInterrupt(thread.interrupt.value) ? (
- thread.submit(null)} connectWidget={{ diff --git a/auth4genai/snippets/how-tos/google-calendar/llamaindex-python.mdx b/auth4genai/snippets/how-tos/google-calendar/llamaindex-python.mdx index a4394f9ff..82306d17b 100644 --- a/auth4genai/snippets/how-tos/google-calendar/llamaindex-python.mdx +++ b/auth4genai/snippets/how-tos/google-calendar/llamaindex-python.mdx @@ -14,7 +14,7 @@ from flask import session auth0_ai = Auth0AI() -with_google = auth0_ai.with_federated_connection( +with_google = auth0_ai.with_token_vault( connection="google-oauth2", scopes=["https://www.googleapis.com/auth/calendar.freebusy"], refresh_token=lambda *_args, **_kwargs:session["user"]["refresh_token"], @@ -35,14 +35,14 @@ from googleapiclient.discovery import build from google.oauth2.credentials import Credentials from typing import Annotated from llama_index.core.tools import FunctionTool -from auth0_ai_llamaindex.federated_connections import get_access_token_for_connection, FederatedConnectionError +from auth0_ai_llamaindex.token_vault import get_access_token_from_token_vault, TokenVaultError from src.lib.auth0_ai import with_google def check_user_calendar_tool_function( date: Annotated[str, "Date and time in ISO 8601 format."] ): # Get the access token from Auth0 AI - access_token = get_access_token_for_connection() + access_token = get_access_token_from_token_vault() # Google SDK try: @@ -61,7 +61,7 @@ def check_user_calendar_tool_function( return {"available": len(busy_times) == 0} except HttpError as e: if e.resp.status == 401: - raise FederatedConnectionError("Authorization required to access the Federated Connection API") + raise TokenVaultError("Authorization required to access the Token Vault API") raise ValueError(f"Invalid response from Google Calendar API: {response.status_code} - {response.text}") @@ -86,7 +86,7 @@ system_prompt = f"""You are an assistant designed to answer random user's questi agent = OpenAIAgent.from_tools( tools=[ - # a tool with federated connection access + # a tool with Token Vault access check_user_calendar_tool # ... other tools ], @@ -104,14 +104,14 @@ Interrupts are a way for the system to pause execution and prompt the user to ta On the server side of your Flask application you will need to set up a route to handle the Chat API requests. This route will be responsible for forwarding the requests to the OpenAI API utilizing LlamaIndex's SDK, that has been initialized with Auth0 AI's protection enhancements for tools. -When `FederatedConnectionInterrupt` error ocurrs, the server side will signal the front-end about the level access restrictions, and the front-end should prompt the user to trigger a new authorization (or login) request with the necessary permissions. +When `TokenVaultInterrupt` error ocurrs, the server side will signal the front-end about the level access restrictions, and the front-end should prompt the user to trigger a new authorization (or login) request with the necessary permissions. ```python ./src/app.py wrap lines highlight={3-5,19-20} from dotenv import load_dotenv from flask import Flask, request, jsonify, session from auth0_ai_llamaindex.auth0_ai import Auth0AI -from auth0_ai_llamaindex.federated_connections import FederatedConnectionInterrupt +from auth0_ai_llamaindex.token_vault import TokenVaultInterrupt from src.lib.agent import agent load_dotenv() @@ -126,7 +126,7 @@ async def chat(): message = request.json.get("message") response = agent.achat(message) return jsonify({"response": str(response)}) - except FederatedConnectionInterrupt as e: + except TokenVaultInterrupt as e: return jsonify({"error": str(e.to_json())}), 403 except Exception as e: return jsonify({"error": str(e)}), 500 diff --git a/auth4genai/snippets/how-tos/google-calendar/llamaindex.mdx b/auth4genai/snippets/how-tos/google-calendar/llamaindex.mdx index 6fa468fd6..a8822606b 100644 --- a/auth4genai/snippets/how-tos/google-calendar/llamaindex.mdx +++ b/auth4genai/snippets/how-tos/google-calendar/llamaindex.mdx @@ -14,7 +14,7 @@ import { auth0 } from "@/lib/auth0"; const auth0AI = new Auth0AI(); -export const withGoogleCalendar = auth0AI.withTokenForConnection({ +export const withGoogleCalendar = auth0AI.withTokenVault({ connection: "google-oauth2", scopes: ["https://www.googleapis.com/auth/calendar.freebusy"], refreshToken: async () => { @@ -40,8 +40,8 @@ import { GaxiosError } from "gaxios"; import { google } from "googleapis"; import { tool } from "llamaindex"; import { withGoogleCalendar } from "@/lib/auth0-ai"; -import { getAccessTokenForConnection } from "@auth0/ai-llamaindex"; -import { FederatedConnectionError } from "@auth0/ai/interrupts"; +import { getAccessTokenFromTokenVault } from "@auth0/ai-llamaindex"; +import { TokenVaultError } from "@auth0/ai/interrupts"; import { z } from "zod"; export const checkUsersCalendar = () => @@ -49,7 +49,7 @@ export const checkUsersCalendar = () => tool( async ({ date }) => { // Get the access token from Auth0 AI - const accessToken = getAccessTokenForConnection(); + const accessToken = getAccessTokenFromTokenVault(); // Google SDK try { @@ -76,8 +76,8 @@ export const checkUsersCalendar = () => } catch (error) { if (error instanceof GaxiosError) { if (error.status === 401) { - throw new FederatedConnectionError( - `Authorization required to access the Federated Connection` + throw new TokenVaultError( + `Authorization required to access the Token Vault connection` ); } } @@ -150,10 +150,10 @@ export async function POST(request: Request) { #### Client Side -On this example we utilize the `EnsureAPIAccessPopup` 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: +In this example, we utilize the `TokenVaultConsentPopup` component to show a pop-up 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: ```bash wrap lines -npx @auth0/ai-components add FederatedConnections +npx @auth0/ai-components add TokenVault ``` Then, you can integrate the authentication popup in your chat component, using the interruptions helper from the SDK: @@ -162,9 +162,9 @@ Then, you can integrate the authentication popup in your chat component, using t "use client"; import { generateId } from "ai"; -import { EnsureAPIAccessPopup } from "@/components/auth0-ai/FederatedConnections/popup"; +import { TokenVaultConsentPopup } from "@/components/auth0-ai/TokenVault/popup"; import { useInterruptions } from "@auth0/ai-vercel/react"; -import { FederatedConnectionInterrupt } from "@auth0/ai/interrupts"; +import { TokenVaultInterrupt } from "@auth0/ai/interrupts"; import { useChat } from "@ai-sdk/react"; export default function Chat() { @@ -187,8 +187,8 @@ export default function Chat() { {message.parts && message.parts.length > 0 && (
{toolInterrupt?.toolCall.id.includes(message.id) && - FederatedConnectionInterrupt.isInterrupt(toolInterrupt) && ( - { @@ -36,8 +36,8 @@ Wrap your tool using the Auth0 AI SDK to obtain an access token for the Slack AP ```typescript ./src/lib/tools/listChannels.ts wrap lines highlight={2-4,8,14,18,30-32} import { ErrorCode, WebClient } from "@slack/web-api"; -import { getAccessTokenForConnection } from "@auth0/ai-vercel"; -import { FederatedConnectionError } from "@auth0/ai/interrupts"; +import { getAccessTokenFromTokenVault } from "@auth0/ai-vercel"; +import { TokenVaultError } from "@auth0/ai/interrupts"; import { withSlack } from "@/lib/auth0-ai"; import { tool } from "ai"; import { z } from "zod"; @@ -48,7 +48,7 @@ export const listChannels = withSlack( parameters: z.object({}), execute: async () => { // Get the access token from Auth0 AI - const accessToken = getAccessTokenForConnection(); + const accessToken = getAccessTokenFromTokenVault(); // Slack SDK try { @@ -64,8 +64,8 @@ export const listChannels = withSlack( } catch (error) { if (error && typeof error === "object" && "code" in error) { if (error.code === ErrorCode.HTTPError) { - throw new FederatedConnectionError( - `Authorization required to access the Federated Connection` + throw new TokenVaultError( + `Authorization required to access the Token Vault connection` ); } } @@ -124,10 +124,10 @@ export async function POST(request: Request) { #### Client Side -On this example we utilize the `EnsureAPIAccessPopup` component to show a popup that allows the user to authenticate with Slack and grant access with the requested scopes. You'll first need to install the `@auth0/ai-components` package: +In this example, we utilize the `TokenVaultConsentPopup` component to show a pop-up that allows the user to authenticate with Slack and grant access with the requested scopes. You'll first need to install the `@auth0/ai-components` package: ```bash wrap lines -npx @auth0/ai-components add FederatedConnections +npx @auth0/ai-components add TokenVault ``` Then, you can integrate the authentication popup in your chat component, using the interruptions helper from the SDK: @@ -137,8 +137,8 @@ Then, you can integrate the authentication popup in your chat component, using t import { useChat } from "@ai-sdk/react"; import { useInterruptions } from "@auth0/ai-vercel/react"; -import { FederatedConnectionInterrupt } from "@auth0/ai/interrupts"; -import { EnsureAPIAccessPopup } from "@/components/auth0-ai/FederatedConnections/popup"; +import { TokenVaultInterrupt } from "@auth0/ai/interrupts"; +import { TokenVaultConsentPopup } from "@/components/auth0-ai/TokenVault/popup"; export default function Chat() { const { messages, handleSubmit, input, setInput, toolInterrupt } = @@ -157,8 +157,8 @@ export default function Chat() {
))} - {FederatedConnectionInterrupt.isInterrupt(toolInterrupt) && ( - ({ threadID: getAgent().name })); const auth0AI = new Auth0AI(); -export const withSlack = auth0AI.withTokenForConnection({ +export const withSlack = auth0AI.withTokenVault({ connection: "sign-in-with-slack", scopes: ["channels:read", "groups:read"], refreshToken: async () => { @@ -50,8 +50,8 @@ Wrap your tool using the Auth0 AI SDK to obtain an access token for the Slack AP ```typescript ./src/agent/tools/listRepositories.ts wrap lines highlight={2-4,8,14,18,30-32} import { ErrorCode, WebClient } from "@slack/web-api"; -import { getAccessTokenForConnection } from "@auth0/ai-vercel"; -import { FederatedConnectionError } from "@auth0/ai/interrupts"; +import { getAccessTokenFromTokenVault } from "@auth0/ai-vercel"; +import { TokenVaultError } from "@auth0/ai/interrupts"; import { withSlack } from "@/lib/auth0-ai"; import { tool } from "ai"; import { z } from "zod"; @@ -62,7 +62,7 @@ export const listChannels = withSlack( parameters: z.object({}), execute: async () => { // Get the access token from Auth0 AI - const accessToken = getAccessTokenForConnection(); + const accessToken = getAccessTokenFromTokenVault(); // Slack SDK try { @@ -78,8 +78,8 @@ export const listChannels = withSlack( } catch (error) { if (error && typeof error === "object" && "code" in error) { if (error.code === ErrorCode.HTTPError) { - throw new FederatedConnectionError( - `Authorization required to access the Federated Connection` + throw new TokenVaultError( + `Authorization required to access the Token Vault connection` ); } } @@ -177,10 +177,10 @@ The name of the user is ${claims?.name ?? "unknown"}. #### Client Side -On this example we utilize the `EnsureAPIAccessPopup` 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: +In this example, we utilize the `TokenVaultConsentPopup` component to show a pop-up 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: ```bash wrap lines -npx @auth0/ai-components add FederatedConnections +npx @auth0/ai-components add TokenVault ``` Then, you can integrate the authentication popup in your chat component, using the interruptions helper from the SDK: @@ -190,8 +190,8 @@ Then, you can integrate the authentication popup in your chat component, using t import { useChat } from "@ai-sdk/react"; import { useAgentChatInterruptions } from "@auth0/ai-cloudflare/react"; -import { FederatedConnectionInterrupt } from "@auth0/ai/interrupts"; -import { EnsureAPIAccessPopup } from "@/components/auth0-ai/FederatedConnections/popup"; +import { TokenVaultInterrupt } from "@auth0/ai/interrupts"; +import { TokenVaultConsentPopup } from "@/components/auth0-ai/TokenVault/popup"; export default function Chat() { @@ -218,8 +218,8 @@ export default function Chat() {
))} - {FederatedConnectionInterrupt.isInterrupt(toolInterrupt) && ( - { @@ -40,8 +40,8 @@ Wrap your tool using the Auth0 AI SDK to obtain an access token for the Slack AP ```typescript ./src/lib/tools/listChannels.ts wrap lines highlight={2-4,11,18,22,34-36} import { z } from "zod"; -import { getAccessTokenForConnection } from "@auth0/ai-genkit"; -import { FederatedConnectionError } from "@auth0/ai/interrupts"; +import { getAccessTokenFromTokenVault } from "@auth0/ai-genkit"; +import { TokenVaultError } from "@auth0/ai/interrupts"; import { withSlack } from "@/lib/auth0-ai"; import { ErrorCode, WebClient } from "@slack/web-api"; @@ -56,7 +56,7 @@ export const listChannels = ai.defineTool( name: "listChannels", }, async () => { - const accessToken = getAccessTokenForConnection(); + const accessToken = getAccessTokenFromTokenVault(); try { // Slack SDK @@ -72,8 +72,8 @@ export const listChannels = ai.defineTool( } catch (error) { if (error && typeof error === "object" && "code" in error) { if (error.code === ErrorCode.HTTPError) { - throw new FederatedConnectionError( - `Authorization required to access the Federated Connection` + throw new TokenVaultError( + `Authorization required to access the Token Vault connection` ); } } @@ -174,10 +174,10 @@ export async function GET( #### Client Side -On this example we utilize the `EnsureAPIAccessPopup` component to show a popup that allows the user to authenticate with Google Calendar and grant access with the requested scopes. You'll first need to install the `@auth0/ai-components` package: +In this example, we utilize the `TokenVaultConsentPopup` component to show a pop-up that allows the user to authenticate with Google Calendar and grant access with the requested scopes. You'll first need to install the `@auth0/ai-components` package: ```bash wrap lines -npx @auth0/ai-components add FederatedConnections +npx @auth0/ai-components add TokenVault ``` Then, you can integrate the authentication popup in your chat component, using the interruptions helper from the SDK: @@ -186,8 +186,8 @@ Then, you can integrate the authentication popup in your chat component, using t "use client"; import { useQueryState } from "nuqs"; import { FormEventHandler, useEffect, useRef, useState } from "react"; -import { FederatedConnectionInterrupt } from "@auth0/ai/interrupts"; -import { EnsureAPIAccessPopup } from "@/components/auth0-ai/FederatedConnections/popup"; +import { TokenVaultInterrupt } from "@auth0/ai/interrupts"; +import { TokenVaultConsentPopup } from "@/components/auth0-ai/TokenVault/popup"; import Markdown from "react-markdown"; const useFocus = () => { @@ -304,14 +304,14 @@ export default function Chat() { {!isLoading && message.content[0].metadata?.interrupt && - FederatedConnectionInterrupt.isInterrupt( + TokenVaultInterrupt.isInterrupt( message.content[0].metadata?.interrupt ) ? (() => { const interrupt: any = message.content[0].metadata?.interrupt; return (
- submit({ interruptedToolRequest: message.content[0] })} interrupt={interrupt} connectWidget={{ diff --git a/auth4genai/snippets/how-tos/slack/langgraph-python.mdx b/auth4genai/snippets/how-tos/slack/langgraph-python.mdx index 92aa3aa12..17d52719c 100644 --- a/auth4genai/snippets/how-tos/slack/langgraph-python.mdx +++ b/auth4genai/snippets/how-tos/slack/langgraph-python.mdx @@ -13,7 +13,7 @@ from auth0_ai_langchain.auth0_ai import Auth0AI auth0_ai = Auth0AI() -with_slack = auth0_ai.with_federated_connection( +with_slack = auth0_ai.with_token_vault( connection="sign-in-with-slack", scopes=["channels:read groups:read"], # Optional: By default, the SDK will expect the refresh token from @@ -32,7 +32,7 @@ from slack_sdk import WebClient from slack_sdk.errors import SlackApiError from pydantic import BaseModel from langchain_core.tools import StructuredTool -from auth0_ai_langchain.federated_connections import get_access_token_for_connection, FederatedConnectionError +from auth0_ai_langchain.token_vault import get_access_token_from_token_vault, TokenVaultError from lib.auth0_ai import with_slack class EmptySchema(BaseModel): @@ -40,7 +40,7 @@ class EmptySchema(BaseModel): def list_channels_tool_function(date: datetime): # Get the access token from Auth0 AI - access_token = get_access_token_for_connection() + access_token = get_access_token_from_token_vault() # Slack SDK try: @@ -55,7 +55,7 @@ def list_channels_tool_function(date: datetime): return channel_names except SlackApiError as e: if e.response['error'] == 'not_authed': - raise FederatedConnectionError("Authorization required to access the Federated Connection API") + raise TokenVaultError("Authorization required to access the Token Vault API") raise ValueError(f"An error occurred: {e.response['error']}") @@ -105,7 +105,7 @@ workflow = ( "tools", ToolNode( [ - # a tool with federated connection access + # a tool with Token Vault access list_slack_channels_tool, # ... other tools ], @@ -174,18 +174,18 @@ You can check different authentication options for Next.js with Auth0 at the [of #### Client Side -On this example we utilize the `EnsureAPIAccessPopup` component to show a popup that allows the user to authenticate with Slack and grant access with the requested scopes. You'll first need to install the `@auth0/ai-components` package: +In this example, we utilize the `TokenVaultConsentPopup` component to show a pop-up that allows the user to authenticate with Slack and grant access with the requested scopes. You'll first need to install the `@auth0/ai-components` package: ```bash wrap lines -npx @auth0/ai-components add FederatedConnections +npx @auth0/ai-components add TokenVault ``` Then, you can integrate the authentication popup in your chat component, using the interruptions helper from the SDK: ```tsx ./src/components/chat.tsx wrap lines highlight={2-3,62-74} import { useStream } from "@langchain/langgraph-sdk/react"; -import { FederatedConnectionInterrupt } from "@auth0/ai/interrupts"; -import { EnsureAPIAccessPopup } from "@/components/auth0-ai/FederatedConnections/popup"; +import { TokenVaultInterrupt } from "@auth0/ai/interrupts"; +import { TokenVaultConsentPopup } from "@/components/auth0-ai/TokenVault/popup"; const useFocus = () => { const htmlElRef = useRef(null); @@ -244,9 +244,9 @@ export default function Chat() {
))} - {thread.interrupt && FederatedConnectionInterrupt.isInterrupt(thread.interrupt.value) ? ( + {thread.interrupt && TokenVaultInterrupt.isInterrupt(thread.interrupt.value) ? (
- thread.submit(null)} connectWidget={{ diff --git a/auth4genai/snippets/how-tos/slack/langgraph.mdx b/auth4genai/snippets/how-tos/slack/langgraph.mdx index eac31652c..89361cfcf 100644 --- a/auth4genai/snippets/how-tos/slack/langgraph.mdx +++ b/auth4genai/snippets/how-tos/slack/langgraph.mdx @@ -21,7 +21,7 @@ const auth0AI = new Auth0AI({ }); const withAccessTokenForConnection = (connection: string, scopes: string[]) => - auth0AI.withTokenForConnection({ + auth0AI.withTokenVault({ connection, scopes, accessToken: async (_, config) => { @@ -40,8 +40,8 @@ Wrap your tool using the Auth0 AI SDK to obtain an access token for the Slack AP ```typescript ./src/lib/tools/listChannels.ts wrap lines highlight={2-4,8,11,15,27-29} import { ErrorCode, WebClient } from "@slack/web-api"; -import { getAccessTokenForConnection } from "@auth0/ai-langchain"; -import { FederatedConnectionError } from "@auth0/ai/interrupts"; +import { getAccessTokenFromTokenVault } from "@auth0/ai-langchain"; +import { TokenVaultError } from "@auth0/ai/interrupts"; import { withSlack } from "@/lib/auth0-ai"; import { tool } from "@langchain/core/tools"; import { z } from "zod"; @@ -49,7 +49,7 @@ import { z } from "zod"; export const listChannels = withSlack( tool(async ({ date }) => { // Get the access token from Auth0 AI - const accessToken = getAccessTokenForConnection(); + const accessToken = getAccessTokenFromTokenVault(); // Slack SDK try { @@ -65,8 +65,8 @@ export const listChannels = withSlack( } catch (error) { if (error && typeof error === "object" && "code" in error) { if (error.code === ErrorCode.HTTPError) { - throw new FederatedConnectionError( - `Authorization required to access the Federated Connection` + throw new TokenVaultError( + `Authorization required to access the Token Vault connection` ); } } @@ -118,7 +118,7 @@ const stateGraph = new StateGraph(MessagesAnnotation) "tools", new ToolNode( [ - // A tool with federated connection access + // A tool with Token Vault access listChannels, // ... other tools ], @@ -297,18 +297,18 @@ export { auth as authHandler }; #### Client Side -On this example we utilize the `EnsureAPIAccessPopup` component to show a popup that allows the user to authenticate with Slack and grant access with the requested scopes. You'll first need to install the `@auth0/ai-components` package: +In this example, we utilize the `TokenVaultConsentPopup` component to show a pop-up that allows the user to authenticate with Slack and grant access with the requested scopes. You'll first need to install the `@auth0/ai-components` package: ```bash wrap lines -npx @auth0/ai-components add FederatedConnections +npx @auth0/ai-components add TokenVault ``` Then, you can integrate the authentication popup in your chat component, using the interruptions helper from the SDK: ```tsx ./src/components/chat.tsx wrap lines highlight={2-3,62-74} import { useStream } from "@langchain/langgraph-sdk/react"; -import { FederatedConnectionInterrupt } from "@auth0/ai/interrupts"; -import { EnsureAPIAccessPopup } from "@/components/auth0-ai/FederatedConnections/popup"; +import { TokenVaultInterrupt } from "@auth0/ai/interrupts"; +import { TokenVaultConsentPopup } from "@/components/auth0-ai/TokenVault/popup"; const useFocus = () => { const htmlElRef = useRef(null); @@ -367,9 +367,9 @@ export default function Chat() {
))} - {thread.interrupt && FederatedConnectionInterrupt.isInterrupt(thread.interrupt.value) ? ( + {thread.interrupt && TokenVaultInterrupt.isInterrupt(thread.interrupt.value) ? (
- thread.submit(null)} connectWidget={{ diff --git a/auth4genai/snippets/how-tos/slack/llamaindex-python.mdx b/auth4genai/snippets/how-tos/slack/llamaindex-python.mdx index fe9dd7b82..681ac5a8c 100644 --- a/auth4genai/snippets/how-tos/slack/llamaindex-python.mdx +++ b/auth4genai/snippets/how-tos/slack/llamaindex-python.mdx @@ -14,7 +14,7 @@ from flask import session auth0_ai = Auth0AI() -with_slack = auth0_ai.with_federated_connection( +with_slack = auth0_ai.with_token_vault( connection="sign-in-with-slack", scopes=["channels:read groups:read"], refresh_token=lambda *_args, **_kwargs:session["user"]["refresh_token"], @@ -32,12 +32,12 @@ Wrap your tool using the Auth0 AI SDK to obtain an access token for the Slack AP from slack_sdk import WebClient from slack_sdk.errors import SlackApiError from llama_index.core.tools import FunctionTool -from auth0_ai_llamaindex.federated_connections import get_access_token_for_connection, FederatedConnectionError +from auth0_ai_llamaindex.token_vault import get_access_token_from_token_vault, TokenVaultError from src.lib.auth0_ai import with_slack def list_slack_channels_tool_function(): # Get the access token from Auth0 AI - access_token = get_access_token_for_connection() + access_token = get_access_token_from_token_vault() # Slack SDK try: @@ -52,7 +52,7 @@ def list_slack_channels_tool_function(): return channel_names except SlackApiError as e: if e.response['error'] == 'not_authed': - raise FederatedConnectionError("Authorization required to access the Federated Connection API") + raise TokenVaultError("Authorization required to access the Token Vault API") raise ValueError(f"An error occurred: {e.response['error']}") @@ -77,7 +77,7 @@ system_prompt = f"""You are an assistant designed to answer random user's questi agent = OpenAIAgent.from_tools( tools=[ - # a tool with federated connection access + # a tool with Token Vault access list_slack_channels_tool # ... other tools ], @@ -95,14 +95,14 @@ Interrupts are a way for the system to pause execution and prompt the user to ta On the server side of your Flask application you will need to set up a route to handle the Chat API requests. This route will be responsible for forwarding the requests to the OpenAI API utilizing LlamaIndex's SDK, that has been initialized with Auth0 AI's protection enhancements for tools. -When `FederatedConnectionInterrupt` error ocurrs, the server side will signal the front-end about the level access restrictions, and the front-end should prompt the user to trigger a new authorization (or login) request with the necessary permissions. +When `TokenVaultInterrupt` error ocurrs, the server side will signal the front-end about the level access restrictions, and the front-end should prompt the user to trigger a new authorization (or login) request with the necessary permissions. ```python ./src/app.py wrap lines highlight={3-5,19-20} from dotenv import load_dotenv from flask import Flask, request, jsonify, session from auth0_ai_llamaindex.auth0_ai import Auth0AI -from auth0_ai_llamaindex.federated_connections import FederatedConnectionInterrupt +from auth0_ai_llamaindex.token_vault import TokenVaultInterrupt from src.lib.agent import agent load_dotenv() @@ -117,7 +117,7 @@ async def chat(): message = request.json.get("message") response = agent.achat(message) return jsonify({"response": str(response)}) - except FederatedConnectionInterrupt as e: + except TokenVaultInterrupt as e: return jsonify({"error": str(e.to_json())}), 403 except Exception as e: return jsonify({"error": str(e)}), 500 diff --git a/auth4genai/snippets/how-tos/slack/llamaindex.mdx b/auth4genai/snippets/how-tos/slack/llamaindex.mdx index 65095e0ec..26ec24fec 100644 --- a/auth4genai/snippets/how-tos/slack/llamaindex.mdx +++ b/auth4genai/snippets/how-tos/slack/llamaindex.mdx @@ -14,7 +14,7 @@ import { auth0 } from "@/lib/auth0"; const auth0AI = new Auth0AI(); -export const withSlack = auth0AI.withTokenForConnection({ +export const withSlack = auth0AI.withTokenVault({ connection: "sign-in-with-slack", scopes: ["channels:read", "groups:read"], refreshToken: async () => { @@ -38,8 +38,8 @@ Wrap your tool using the Auth0 AI SDK to obtain an access token for the GitHub A import { tool } from "llamaindex"; import { z } from "zod"; import { withSlack } from "@/lib/auth0-ai"; -import { getAccessTokenForConnection } from "@auth0/ai-llamaindex"; -import { FederatedConnectionError } from "@auth0/ai/interrupts"; +import { getAccessTokenFromTokenVault } from "@auth0/ai-llamaindex"; +import { TokenVaultError } from "@auth0/ai/interrupts"; import { ErrorCode, WebClient } from "@slack/web-api"; export const listChannels = () => @@ -47,7 +47,7 @@ export const listChannels = () => tool( async () => { // Get the access token from Auth0 AI - const accessToken = getAccessTokenForConnection(); + const accessToken = getAccessTokenFromTokenVault(); // Slack SDK try { @@ -67,8 +67,8 @@ export const listChannels = () => } catch (error) { if (error && typeof error === "object" && "code" in error) { if (error.code === ErrorCode.HTTPError) { - throw new FederatedConnectionError( - `Authorization required to access the Federated Connection` + throw new TokenVaultError( + `Authorization required to access the Token Vault connection` ); } } @@ -138,10 +138,10 @@ export async function POST(request: Request) { #### Client Side -On this example we utilize the `EnsureAPIAccessPopup` 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: +In this example, we utilize the `TokenVaultConsentPopup` component to show a pop-up 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: ```bash wrap lines -npx @auth0/ai-components add FederatedConnections +npx @auth0/ai-components add TokenVault ``` Then, you can integrate the authentication popup in your chat component, using the interruptions helper from the SDK: @@ -150,9 +150,9 @@ Then, you can integrate the authentication popup in your chat component, using t "use client"; import { generateId } from "ai"; -import { EnsureAPIAccessPopup } from "@/components/auth0-ai/FederatedConnections/popup"; +import { TokenVaultConsentPopup } from "@/components/auth0-ai/TokenVault/popup"; import { useInterruptions } from "@auth0/ai-vercel/react"; -import { FederatedConnectionInterrupt } from "@auth0/ai/interrupts"; +import { TokenVaultInterrupt } from "@auth0/ai/interrupts"; import { useChat } from "@ai-sdk/react"; export default function Chat() { @@ -175,8 +175,8 @@ export default function Chat() { {message.parts && message.parts.length > 0 && (
{toolInterrupt?.toolCall.id.includes(message.id) && - FederatedConnectionInterrupt.isInterrupt(toolInterrupt) && ( - {`const auth0AI = new Auth0AI(); -export const ${jsVariableName} = auth0AI.withTokenForConnection({ +export const ${jsVariableName} = auth0AI.withTokenVault({ connection: "${connectionName}", scopes: [${formatScopes(scopes)}, ...], refreshToken: getAuth0RefreshToken(), @@ -28,7 +28,7 @@ export const ${jsVariableName} = auth0AI.withTokenForConnection({ {`auth0_ai = Auth0AI() -${pythonVariableName} = auth0_ai.with_federated_connection( +${pythonVariableName} = auth0_ai.with_token_vault( connection="${connectionName}", scopes=[${formatScopes(scopes)}, ...], refresh_token=get_auth0_refresh_token, diff --git a/main/docs/secure/tokens/token-vault/configure-token-vault.mdx b/main/docs/secure/tokens/token-vault/configure-token-vault.mdx index 73c813e2e..e45887e48 100644 --- a/main/docs/secure/tokens/token-vault/configure-token-vault.mdx +++ b/main/docs/secure/tokens/token-vault/configure-token-vault.mdx @@ -218,4 +218,3 @@ Response: 204 No-Content ``` -