Skip to content

Commit 91b8428

Browse files
committed
feat: begin auth0-ai sdk renaming updates, python references
1 parent 2e1b70f commit 91b8428

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
@@ -162,7 +162,7 @@ To configure the Token Vault for your Google connection, you can use the followi
162162
```python wrap lines
163163
auth0_ai = Auth0AI()
164164

165-
with_google_connection = auth0_ai.with_federated_connection(
165+
with_google_connection = auth0_ai.with_token_vault(
166166
connection="google-oauth2",
167167
scopes=["https://www.googleapis.com/auth/calendar.freebusy", ...],
168168
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
@@ -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" "langgraph>=0.5.4" langchain-openai "langgraph-cli[inmem]" --prerelease=allow
37+
uv add "auth0-ai-langchain>=TODO_NEW_VERSION_HERE" "langgraph>=0.5.4" langchain-openai "langgraph-cli[inmem]>=0.3.6" --prerelease=allow
3838
```
3939

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

4848
#### Configure the Auth0 AI SDK
4949

50-
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.
50+
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.
5151

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

@@ -68,8 +68,9 @@ auth0_ai = Auth0AI(
6868
)
6969
)
7070

71-
with_async_user_confirmation = auth0_ai.with_async_user_confirmation(
71+
with_async_authorization = auth0_ai.with_async_authorization(
7272
audience=settings.SHOP_API_AUDIENCE,
73+
# param: scopes
7374
# add any scopes you want to use with your API
7475
scopes=["openid", "product:buy"],
7576
binding_message=lambda product, quantity: f"Do you want to buy {quantity} {product}",
@@ -78,6 +79,12 @@ with_async_user_confirmation = auth0_ai.with_async_user_confirmation(
7879
.get("_credentials")
7980
.get("user")
8081
.get("sub"),
82+
# param: requested_expiry
83+
# Note: Setting a requested expiry greater than 300 (seconds) will force email verification
84+
# instead of using the push notification flow.
85+
# requested_expiry=301,
86+
87+
# param: on_authorization_request
8188
# When this flag is set to `block`, the execution of the tool awaits
8289
# until the user approves or rejects the request.
8390
#
@@ -87,12 +94,13 @@ with_async_user_confirmation = auth0_ai.with_async_user_confirmation(
8794
# In practice, the process that is awaiting the user confirmation
8895
# could crash or timeout before the user approves the request.
8996
on_authorization_request="block",
97+
9098
)
9199
```
92100

93-
This will intercept the tool call to initiate a CIBA request:
101+
This will intercept the tool call to initiate an Async Authorization request:
94102

95-
- The CIBA request includes the user ID that will approve the request.
103+
- The Async Authorization request includes the user ID that will approve the request.
96104
- Auth0 sends the user a mobile push notification. The AI agent polls the `/token` endpoint for a user response.
97105
- The mobile application retrieves the `bindingMessage` containing the consent details, in this case, the details of the product to purchase.
98106
- The user responds to the request:
@@ -146,10 +154,10 @@ Now, create a file `app/agents/tools/shop_online.py` and add the following code:
146154
```python app/agents/tools/shop_online.py wrap lines
147155
import httpx
148156
from langchain_core.tools import StructuredTool
149-
from auth0_ai_langchain.ciba import get_ciba_credentials
157+
from auth0_ai_langchain.async_authorization import get_async_authorization_credentials
150158
from pydantic import BaseModel
151159

152-
from app.core.auth0_ai import with_async_user_confirmation
160+
from app.core.auth0_ai import with_async_authorization
153161
from app.core.config import settings
154162

155163

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

170-
credentials = get_ciba_credentials()
178+
credentials = get_async_authorization_credentials()
171179

172180
if not credentials:
173-
raise ValueError("CIBA credentials not found")
181+
raise ValueError("Async Authorization credentials not found")
174182

175183
headers = {
176184
"Authorization": f"Bearer {credentials['access_token']}",
@@ -202,7 +210,7 @@ async def shop_online_fn(product: str, quantity: int):
202210
}
203211

204212

205-
shop_online = with_async_user_confirmation(
213+
shop_online = with_async_authorization(
206214
StructuredTool(
207215
name="shop_online",
208216
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
@@ -35,7 +35,7 @@ Make sure you have [uv](https://docs.astral.sh/uv/) installed and run the follow
3535
```bash wrap lines
3636
cd backend
3737
uv sync
38-
uv add "auth0-ai-langchain>=1.0.0b3" openfga-sdk langgraph langchain-openai "langgraph-cli[inmem]" --prerelease=allow
38+
uv add "auth0-ai-langchain>=TODO_NEW_VERSION_HERE" openfga-sdk langgraph langchain-openai "langgraph-cli[inmem]" --prerelease=allow
3939
```
4040

4141
### 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
@@ -13,7 +13,7 @@ import { AccountAndAppSteps } from "/snippets/get-started/prerequisites/account-
1313
<Tab
1414
title="Use sample app (recommended)"
1515
>
16-
16+
1717
### Clone sample app
1818
Clone this sample app from the [Auth0 AI samples](https://github.com/auth0-samples/auth0-ai-samples) repository:
1919

@@ -134,7 +134,7 @@ Make sure you have [uv](https://docs.astral.sh/uv/) installed and run the follow
134134
```bash wrap lines
135135
cd backend
136136
uv sync
137-
uv add "auth0-ai-langchain>=1.0.0b3" "langgraph>=0.5.4" langchain-openai "langgraph-cli[inmem]" google-api-python-client --prerelease=allow
137+
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
138138
```
139139

140140
### Update your environment file
@@ -191,7 +191,7 @@ auth0_ai = Auth0AI(
191191
)
192192
)
193193

194-
with_calendar_access = auth0_ai.with_federated_connection(
194+
with_calendar_access = auth0_ai.with_token_vault(
195195
connection="google-oauth2",
196196
scopes=["https://www.googleapis.com/auth/calendar.events"],
197197
)
@@ -243,8 +243,8 @@ from langchain_core.tools import StructuredTool
243243
from google.oauth2.credentials import Credentials
244244
from googleapiclient.discovery import build
245245
from pydantic import BaseModel
246-
from auth0_ai_langchain.federated_connections import (
247-
get_access_token_for_connection,
246+
from auth0_ai_langchain.token_vault import (
247+
get_access_token_from_token_vault,
248248
)
249249
import datetime
250250
import json
@@ -253,7 +253,7 @@ from app.core.auth0_ai import with_calendar_access
253253

254254
async def list_upcoming_events_fn():
255255
"""List upcoming events from the user's Google Calendar"""
256-
google_access_token = get_access_token_for_connection()
256+
google_access_token = get_access_token_from_token_vault()
257257
if not google_access_token:
258258
raise ValueError(
259259
"Authorization required to access the Federated Connection API"
@@ -328,18 +328,18 @@ To implement, install the Auth0 AI Components for React SDK to get the required
328328
```bash wrap lines
329329
cd frontend
330330
npm install @auth0/ai @langchain/langgraph-sdk
331-
npx @auth0/ai-components add FederatedConnections
331+
npx @auth0/ai-components add TokenVault
332332
```
333333

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

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

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

342-
interface FederatedConnectionInterruptHandlerProps {
342+
interface TokenVaultInterruptHandlerProps {
343343
interrupt: Interrupt | undefined | null;
344344
onFinish: () => void;
345345
auth?: {
@@ -348,21 +348,21 @@ interface FederatedConnectionInterruptHandlerProps {
348348
};
349349
}
350350

351-
export function FederatedConnectionInterruptHandler({
351+
export function TokenVaultInterruptHandler({
352352
interrupt,
353353
onFinish,
354354
auth,
355-
}: FederatedConnectionInterruptHandlerProps) {
355+
}: TokenVaultInterruptHandlerProps) {
356356
if (
357357
!interrupt ||
358-
!FederatedConnectionInterrupt.isInterrupt(interrupt.value)
358+
!TokenVaultInterrupt.isInterrupt(interrupt.value)
359359
) {
360360
return null;
361361
}
362362

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

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

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

388388
//... existing code
@@ -407,7 +407,7 @@ export function ChatWindow(props: {
407407
/>
408408
<div className="flex flex-col max-w-[768px] mx-auto pb-12 w-full">
409409
{!!chat.interrupt?.value && (
410-
<FederatedConnectionInterruptHandler
410+
<TokenVaultInterruptHandler
411411
auth={{
412412
authorizePath: getLoginUrl(),
413413
returnTo: new URL(
@@ -450,4 +450,4 @@ That's it! You successfully integrated third-party API access using Token Vault
450450
### View a complete example
451451
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).
452452
</Tab>
453-
</Tabs>
453+
</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)