Skip to content

Commit 83b8bb3

Browse files
committed
feat: begin auth0-ai sdk renaming updates, python references
1 parent 82b90bc commit 83b8bb3

File tree

14 files changed

+96
-88
lines changed

14 files changed

+96
-88
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: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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/snippets/get-started/langchain-fastapi-py/async-auth.mdx

Lines changed: 18 additions & 10 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>=TODO_NEW_VERSION_HERE" "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:
@@ -145,10 +153,10 @@ Now, create a file `app/agents/tools/shop_online.py` and add the following code:
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>=TODO_NEW_VERSION_HERE" 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: 20 additions & 20 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>=TODO_NEW_VERSION_HERE" "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,7 +254,7 @@ 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(
260260
"Authorization required to access the Federated Connection API"
@@ -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>

auth4genai/snippets/how-tos/github/langgraph-python.mdx

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ from auth0_ai_langchain.auth0_ai import Auth0AI
1313

1414
auth0_ai = Auth0AI()
1515

16-
with_github = auth0_ai.with_federated_connection(
16+
with_github = auth0_ai.with_token_vault(
1717
connection="github",
1818
scopes=["repo"]
1919
# Optional: By default, the SDK will expect the refresh token from
@@ -32,15 +32,15 @@ from github import Github
3232
from github.GithubException import BadCredentialsException
3333
from pydantic import BaseModel
3434
from langchain_core.tools import StructuredTool
35-
from auth0_ai_langchain.federated_connections import get_access_token_for_connection, FederatedConnectionError
35+
from auth0_ai_langchain.token_vault import get_access_token_from_token_vault, TokenVaultError
3636
from src.lib.auth0_ai import with_github
3737

3838
class EmptySchema(BaseModel):
3939
pass
4040

4141
def list_repositories_tool_function(date: datetime):
4242
# Get the access token from Auth0 AI
43-
access_token = get_access_token_for_connection()
43+
access_token = get_access_token_from_token_vault()
4444

4545
# GitHub SDK
4646
try:
@@ -50,7 +50,7 @@ def list_repositories_tool_function(date: datetime):
5050
repo_names = [repo.name for repo in repos]
5151
return repo_names
5252
except BadCredentialsException:
53-
raise FederatedConnectionError("Authorization required to access the Federated Connection API")
53+
raise TokenVaultError("Authorization required to access the Token Vault API")
5454

5555
list_github_repositories_tool = with_github(StructuredTool(
5656
name="list_github_repositories",
@@ -167,18 +167,18 @@ You can check different authentication options for Next.js with Auth0 at the [of
167167

168168
#### Client Side
169169

170-
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:
170+
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:
171171

172172
```bash wrap lines
173-
npx @auth0/ai-components add FederatedConnections
173+
npx @auth0/ai-components add TokenVault
174174
```
175175

176176
Then, you can integrate the authentication popup in your chat component, using the interruptions helper from the SDK:
177177

178178
```tsx ./src/components/chat.tsx wrap lines highlight={2-3,62-74}
179179
import { useStream } from "@langchain/langgraph-sdk/react";
180-
import { FederatedConnectionInterrupt } from "@auth0/ai/interrupts";
181-
import { EnsureAPIAccessPopup } from "@/components/auth0-ai/FederatedConnections/popup";
180+
import { TokenVaultInterrupt } from "@auth0/ai/interrupts";
181+
import { TokenVaultConsentPopup } from "@/components/auth0-ai/TokenVault/popup";
182182

183183
const useFocus = () => {
184184
const htmlElRef = useRef<HTMLInputElement>(null);
@@ -237,9 +237,9 @@ export default function Chat() {
237237
</div>
238238
))}
239239

240-
{thread.interrupt && FederatedConnectionInterrupt.isInterrupt(thread.interrupt.value) ? (
240+
{thread.interrupt && TokenVaultInterrupt.isInterrupt(thread.interrupt.value) ? (
241241
<div key={thread.interrupt.ns?.join("")}>
242-
<EnsureAPIAccessPopup
242+
<TokenVaultConsentPopup
243243
interrupt={thread.interrupt.value}
244244
onFinish={() => thread.submit(null)}
245245
connectWidget={{

auth4genai/snippets/how-tos/github/llamaindex-python.mdx

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ from flask import session
1414

1515
auth0_ai = Auth0AI()
1616

17-
with_github = auth0_ai.with_federated_connection(
17+
with_github = auth0_ai.with_token_vault(
1818
connection="github",
1919
scopes=["repo"],
2020
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
3232
from github import Github
3333
from github.GithubException import BadCredentialsException
3434
from llama_index.core.tools import FunctionTool
35-
from auth0_ai_llamaindex.federated_connections import get_access_token_for_connection, FederatedConnectionError
35+
from auth0_ai_llamaindex.token_vault import get_access_token_from_token_vault, TokenVaultError
3636
from src.lib.auth0_ai import with_github
3737

3838
def list_github_repositories_tool_function():
3939
# Get the access token from Auth0 AI
40-
access_token = get_access_token_for_connection()
40+
access_token = get_access_token_from_token_vault()
4141

4242
# GitHub SDK
4343
try:
@@ -47,7 +47,7 @@ def list_github_repositories_tool_function():
4747
repo_names = [repo.name for repo in repos]
4848
return repo_names
4949
except BadCredentialsException:
50-
raise FederatedConnectionError("Authorization required to access the Federated Connection")
50+
raise TokenVaultError("Authorization required to access the Token Vault API")
5151

5252
list_github_repositories_tool = with_github(FunctionTool.from_defaults(
5353
name="list_github_repositories",
@@ -88,14 +88,14 @@ Interrupts are a way for the system to pause execution and prompt the user to ta
8888

8989
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.
9090

91-
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.
91+
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.
9292

9393

9494
```python ./src/app.py wrap lines highlight={3-5,19-20}
9595
from dotenv import load_dotenv
9696
from flask import Flask, request, jsonify, session
9797
from auth0_ai_llamaindex.auth0_ai import Auth0AI
98-
from auth0_ai_llamaindex.federated_connections import FederatedConnectionInterrupt
98+
from auth0_ai_llamaindex.token_vault import TokenVaultInterrupt
9999
from src.lib.agent import agent
100100

101101
load_dotenv()
@@ -110,7 +110,7 @@ async def chat():
110110
message = request.json.get("message")
111111
response = agent.achat(message)
112112
return jsonify({"response": str(response)})
113-
except FederatedConnectionInterrupt as e:
113+
except TokenVaultInterrupt as e:
114114
return jsonify({"error": str(e.to_json())}), 403
115115
except Exception as e:
116116
return jsonify({"error": str(e)}), 500

0 commit comments

Comments
 (0)