Skip to content

Commit e0545f7

Browse files
priley86lrzhou25pmalouin
authored
feat: auth0-ai sdk Token Vault + CIBA renaming updates (#105)
* feat: begin auth0-ai sdk renaming updates, python references * feat: adds JS Token Vault + CIBA renaming updates * Apply suggestions from code review Co-authored-by: lrzhou25 <[email protected]> Co-authored-by: Patrick Malouin <[email protected]> * fix: delete unused files * fix: revert changes to top-level token-vault docs * fix: revert learn-more snippet language with this change * fix: updated releases version references --------- Co-authored-by: lrzhou25 <[email protected]> Co-authored-by: Patrick Malouin <[email protected]>
1 parent 9b4003e commit e0545f7

39 files changed

+366
-359
lines changed

auth4genai/how-tos/get-github-issues-python.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ Create a function that will return the access token for Github.
3939

4040
```python wrap lines
4141
async def get_token_from_token_vault():
42-
return await auth0.get_access_token_for_connection(
42+
return await auth0.get_access_token_from_token_vault(
4343
options = {
4444
"connection" : "github",
4545
"scope" : "openid profile email offline_access"})

auth4genai/integrations/github.mdx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ To configure the Token Vault for your GitHub connection, you can use the followi
8383
```tsx wrap lines
8484
const auth0AI = new Auth0AI();
8585

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

99-
with_github_connection = auth0_ai.with_federated_connection(
99+
with_github_connection = auth0_ai.with_token_vault(
100100
connection="github",
101101
# scopes are not supported for GitHub yet. Set required scopes when creating the accompanying GitHub app
102102
scopes=[],

auth4genai/integrations/google.mdx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ To configure the Token Vault for your Google connection, you can use the followi
163163
```tsx wrap lines
164164
const auth0AI = new Auth0AI();
165165

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

178-
with_google_connection = auth0_ai.with_federated_connection(
178+
with_google_connection = auth0_ai.with_token_vault(
179179
connection="google-oauth2",
180180
scopes=["https://www.googleapis.com/auth/calendar.freebusy", ...],
181181
refresh_token=get_auth0_refresh_token,

auth4genai/integrations/slack.mdx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ To configure the Token Vault for your GitHub connection, you can use the followi
8484
```tsx wrap lines
8585
const auth0AI = new Auth0AI();
8686

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

99-
with_slack_connection = auth0_ai.with_federated_connection(
99+
with_slack_connection = auth0_ai.with_token_vault(
100100
connection="sign-in-with-slack",
101101
scopes=["channels:read", ...],
102102
refresh_token=get_auth0_refresh_token,

auth4genai/intro/call-others-apis-on-users-behalf.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
title: Call Other's APIs on User's Behalf
3-
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."
3+
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."
44
---
55

66
## Applications with refresh tokens

auth4genai/intro/token-vault.mdx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,9 @@ By using Token Vault, you can:
4949
The process of using Token Vault involves the following key steps:
5050

5151
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.
52-
2. **Secure token storage:** Auth0 receives the federated access and refresh tokens from the external provider and stores them securely within Token Vault.
53-
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.
54-
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.
52+
2. **Secure token storage:** Auth0 receives access and refresh tokens from the external provider and stores them securely within Token Vault.
53+
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.
54+
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.
5555

5656
## Supported integrations
5757

auth4genai/sdks/javascript-sdk.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ This library helps to set up the React components that can be used in AI applica
6363
- Tools for getting access tokens for supported social and enterprise identity providers
6464

6565
```bash wrap lines
66-
npx @auth0/ai-components add FederatedConnections
66+
npx @auth0/ai-components add TokenVault
6767
```
6868

6969
### [Redis Store for Auth0 AI](https://github.com/auth0-lab/auth0-ai-js/tree/main/packages/ai-redis)

auth4genai/snippets/get-started/langchain-fastapi-py/async-auth.mdx

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ Make sure you have [uv](https://docs.astral.sh/uv/) installed and run the follow
3333
```bash wrap lines
3434
cd backend
3535
uv sync
36-
uv add "auth0-ai-langchain>=1.0.0b3" "langgraph>=0.5.4" langchain-openai "langgraph-cli[inmem]" --prerelease=allow
36+
uv add "auth0-ai-langchain>=1.0.0b4" "langgraph>=0.5.4" langchain-openai "langgraph-cli[inmem]>=0.3.6" --prerelease=allow
3737
```
3838

3939
### Update the environment file
@@ -46,7 +46,7 @@ Integrate the Auth0 AI SDK into your application to secure your async AI agent w
4646

4747
#### Configure the Auth0 AI SDK
4848

49-
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.
49+
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.
5050

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

@@ -67,8 +67,9 @@ auth0_ai = Auth0AI(
6767
)
6868
)
6969

70-
with_async_user_confirmation = auth0_ai.with_async_user_confirmation(
70+
with_async_authorization = auth0_ai.with_async_authorization(
7171
audience=settings.SHOP_API_AUDIENCE,
72+
# param: scopes
7273
# add any scopes you want to use with your API
7374
scopes=["openid", "product:buy"],
7475
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(
7778
.get("_credentials")
7879
.get("user")
7980
.get("sub"),
81+
# param: requested_expiry
82+
# Note: Setting a requested expiry greater than 300 (seconds) will force email verification
83+
# instead of using the push notification flow.
84+
# requested_expiry=301,
85+
86+
# param: on_authorization_request
8087
# When this flag is set to `block`, the execution of the tool awaits
8188
# until the user approves or rejects the request.
8289
#
@@ -86,12 +93,13 @@ with_async_user_confirmation = auth0_ai.with_async_user_confirmation(
8693
# In practice, the process that is awaiting the user confirmation
8794
# could crash or timeout before the user approves the request.
8895
on_authorization_request="block",
96+
8997
)
9098
```
9199

92-
This will intercept the tool call to initiate a CIBA request:
100+
This will intercept the tool call to initiate an Async Authorization request:
93101

94-
- The CIBA request includes the user ID that will approve the request.
102+
- The Async Authorization request includes the user ID that will approve the request.
95103
- Auth0 sends the user a mobile push notification. The AI agent polls the `/token` endpoint for a user response.
96104
- The mobile application retrieves the `bindingMessage` containing the consent details, in this case, the details of the product to purchase.
97105
- The user responds to the request:
@@ -138,17 +146,17 @@ async def api_route(
138146

139147
#### Create a tool to call your API
140148

141-
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.
149+
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.
142150

143151
Now, create a file `app/agents/tools/shop_online.py` and add the following code:
144152

145153
```python app/agents/tools/shop_online.py wrap lines
146154
import httpx
147155
from langchain_core.tools import StructuredTool
148-
from auth0_ai_langchain.ciba import get_ciba_credentials
156+
from auth0_ai_langchain.async_authorization import get_async_authorization_credentials
149157
from pydantic import BaseModel
150158

151-
from app.core.auth0_ai import with_async_user_confirmation
159+
from app.core.auth0_ai import with_async_authorization
152160
from app.core.config import settings
153161

154162

@@ -166,10 +174,10 @@ async def shop_online_fn(product: str, quantity: int):
166174
# No API set, mock a response
167175
return f"Ordered {quantity} {product}"
168176

169-
credentials = get_ciba_credentials()
177+
credentials = get_async_authorization_credentials()
170178

171179
if not credentials:
172-
raise ValueError("CIBA credentials not found")
180+
raise ValueError("Async Authorization credentials not found")
173181

174182
headers = {
175183
"Authorization": f"Bearer {credentials['access_token']}",
@@ -201,7 +209,7 @@ async def shop_online_fn(product: str, quantity: int):
201209
}
202210

203211

204-
shop_online = with_async_user_confirmation(
212+
shop_online = with_async_authorization(
205213
StructuredTool(
206214
name="shop_online",
207215
description="Tool to buy products online.",

auth4genai/snippets/get-started/langchain-fastapi-py/auth-for-rag.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ Make sure you have [uv](https://docs.astral.sh/uv/) installed and run the follow
3434
```bash wrap lines
3535
cd backend
3636
uv sync
37-
uv add "auth0-ai-langchain>=1.0.0b3" openfga-sdk langgraph langchain-openai "langgraph-cli[inmem]" --prerelease=allow
37+
uv add "auth0-ai-langchain>=1.0.0b4" openfga-sdk langgraph langchain-openai "langgraph-cli[inmem]" --prerelease=allow
3838
```
3939

4040
### Update the environment file

auth4genai/snippets/get-started/langchain-fastapi-py/call-others-api.mdx

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import { DownloadQuickstartButton } from "/snippets/download-quickstart/Download
1515
<Tab
1616
title="Use sample app (recommended)"
1717
>
18-
18+
1919
### Download sample app
2020
Start by downloading and extracting the sample app. Then open in your preferred IDE.
2121
<DownloadQuickstartButton
@@ -135,7 +135,7 @@ Make sure you have [uv](https://docs.astral.sh/uv/) installed and run the follow
135135
```bash wrap lines
136136
cd backend
137137
uv sync
138-
uv add "auth0-ai-langchain>=1.0.0b3" "langgraph>=0.5.4" langchain-openai "langgraph-cli[inmem]" google-api-python-client --prerelease=allow
138+
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
139139
```
140140

141141
### Update your environment file
@@ -192,7 +192,7 @@ auth0_ai = Auth0AI(
192192
)
193193
)
194194

195-
with_calendar_access = auth0_ai.with_federated_connection(
195+
with_calendar_access = auth0_ai.with_token_vault(
196196
connection="google-oauth2",
197197
scopes=["https://www.googleapis.com/auth/calendar.events"],
198198
)
@@ -244,8 +244,8 @@ from langchain_core.tools import StructuredTool
244244
from google.oauth2.credentials import Credentials
245245
from googleapiclient.discovery import build
246246
from pydantic import BaseModel
247-
from auth0_ai_langchain.federated_connections import (
248-
get_access_token_for_connection,
247+
from auth0_ai_langchain.token_vault import (
248+
get_access_token_from_token_vault,
249249
)
250250
import datetime
251251
import json
@@ -254,10 +254,10 @@ from app.core.auth0_ai import with_calendar_access
254254

255255
async def list_upcoming_events_fn():
256256
"""List upcoming events from the user's Google Calendar"""
257-
google_access_token = get_access_token_for_connection()
257+
google_access_token = get_access_token_from_token_vault()
258258
if not google_access_token:
259259
raise ValueError(
260-
"Authorization required to access the Federated Connection API"
260+
"Authorization required to access the Google Calendar API"
261261
)
262262

263263
calendar_service = build(
@@ -329,18 +329,18 @@ To implement, install the Auth0 AI Components for React SDK to get the required
329329
```bash wrap lines
330330
cd frontend
331331
npm install @auth0/ai @langchain/langgraph-sdk
332-
npx @auth0/ai-components add FederatedConnections
332+
npx @auth0/ai-components add TokenVault
333333
```
334334

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

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

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

343-
interface FederatedConnectionInterruptHandlerProps {
343+
interface TokenVaultInterruptHandlerProps {
344344
interrupt: Interrupt | undefined | null;
345345
onFinish: () => void;
346346
auth?: {
@@ -349,21 +349,21 @@ interface FederatedConnectionInterruptHandlerProps {
349349
};
350350
}
351351

352-
export function FederatedConnectionInterruptHandler({
352+
export function TokenVaultInterruptHandler({
353353
interrupt,
354354
onFinish,
355355
auth,
356-
}: FederatedConnectionInterruptHandlerProps) {
356+
}: TokenVaultInterruptHandlerProps) {
357357
if (
358358
!interrupt ||
359-
!FederatedConnectionInterrupt.isInterrupt(interrupt.value)
359+
!TokenVaultInterrupt.isInterrupt(interrupt.value)
360360
) {
361361
return null;
362362
}
363363

364364
return (
365365
<div key={interrupt.ns?.join("")} className="whitespace-pre-wrap">
366-
<EnsureAPIAccess
366+
<TokenVaultConsent
367367
mode="popup"
368368
interrupt={interrupt.value}
369369
onFinish={onFinish}
@@ -379,11 +379,11 @@ export function FederatedConnectionInterruptHandler({
379379
}
380380
```
381381

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

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

389389
//... existing code
@@ -408,7 +408,7 @@ export function ChatWindow(props: {
408408
/>
409409
<div className="flex flex-col max-w-[768px] mx-auto pb-12 w-full">
410410
{!!chat.interrupt?.value && (
411-
<FederatedConnectionInterruptHandler
411+
<TokenVaultInterruptHandler
412412
auth={{
413413
authorizePath: getLoginUrl(),
414414
returnTo: new URL(
@@ -451,4 +451,4 @@ That's it! You successfully integrated third-party API access using Token Vault
451451
### View a complete example
452452
Want to see how it all comes together? Explore or clone the fully implemented sample application on [GitHub](https://github.com/auth0-samples/auth0-ai-samples/tree/main/call-apis-on-users-behalf/others-api/langchain-fastapi-py).
453453
</Tab>
454-
</Tabs>
454+
</Tabs>

0 commit comments

Comments
 (0)