-
Notifications
You must be signed in to change notification settings - Fork 13
feat: auth0-ai sdk Token Vault + CIBA renaming updates #105
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -1,6 +1,6 @@ | ||||||
--- | ||||||
title: Call Other's APIs on User's Behalf | ||||||
description: "[Token Vault](/intro/token-vault) lets your AI agent call external APIs on the user's behalf. We provide SDKs for Python, JavaScript, and popular AI frameworks like LangChain, LlamaIndex, Genkit, and Vercel AI, making it easy and straightforward to get access tokens for your federated connections." | ||||||
description: "[Token Vault](/intro/token-vault) lets your AI agent call external APIs on the user's behalf. We provide SDKs for Python, JavaScript, and popular AI frameworks like LangChain, LlamaIndex, Genkit, and Vercel AI, making it easy and straightforward to get access tokens for your third-party connections." | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
--- | ||||||
|
||||||
## Web applications with backend for frontend | ||||||
|
@@ -135,4 +135,4 @@ To begin using Auth0 Token Vault with your AI agents, refer to the following res | |||||
icon="key" | ||||||
horizontal | ||||||
/> | ||||||
</Columns> | ||||||
</Columns> |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -47,9 +47,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 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 for a third-party 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. | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
4. **API call:** With the third-party access token, your AI agent can make authorized calls to the third-party API on the user's behalf. | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
||||||
## Supported integrations | ||||||
|
||||||
|
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
@@ -13,7 +13,7 @@ import { AccountAndAppSteps } from "/snippets/get-started/prerequisites/account- | |||||||||
<Tab | ||||||||||
title="Use sample app (recommended)" | ||||||||||
> | ||||||||||
|
||||||||||
### Clone sample app | ||||||||||
Clone this sample app from the [Auth0 AI samples](https://github.com/auth0-samples/auth0-ai-samples) repository: | ||||||||||
|
||||||||||
|
@@ -134,7 +134,7 @@ Make sure you have [uv](https://docs.astral.sh/uv/) installed and run the follow | |||||||||
```bash wrap lines | ||||||||||
cd backend | ||||||||||
uv sync | ||||||||||
uv add "auth0-ai-langchain>=1.0.0b3" "langgraph>=0.5.4" langchain-openai "langgraph-cli[inmem]" google-api-python-client --prerelease=allow | ||||||||||
uv add "auth0-ai-langchain>=TODO_NEW_VERSION_HERE" "langgraph>=0.5.4" langchain-openai "langgraph-cli[inmem]>=0.3.6" google-api-python-client --prerelease=allow | ||||||||||
``` | ||||||||||
|
||||||||||
### Update your environment file | ||||||||||
|
@@ -191,7 +191,7 @@ auth0_ai = Auth0AI( | |||||||||
) | ||||||||||
) | ||||||||||
|
||||||||||
with_calendar_access = auth0_ai.with_federated_connection( | ||||||||||
with_calendar_access = auth0_ai.with_token_vault( | ||||||||||
connection="google-oauth2", | ||||||||||
scopes=["https://www.googleapis.com/auth/calendar.events"], | ||||||||||
) | ||||||||||
|
@@ -243,8 +243,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 | ||||||||||
|
@@ -253,10 +253,10 @@ from app.core.auth0_ai import with_calendar_access | |||||||||
|
||||||||||
async def list_upcoming_events_fn(): | ||||||||||
"""List upcoming events from the user's Google Calendar""" | ||||||||||
google_access_token = get_access_token_for_connection() | ||||||||||
google_access_token = get_access_token_from_token_vault() | ||||||||||
if not google_access_token: | ||||||||||
raise ValueError( | ||||||||||
"Authorization required to access the Federated Connection API" | ||||||||||
"Authorization required to access the Token Vault connection API" | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would it be clearer like this?
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||
) | ||||||||||
|
||||||||||
calendar_service = build( | ||||||||||
|
@@ -328,18 +328,18 @@ To implement, install the Auth0 AI Components for React SDK to get the required | |||||||||
```bash wrap lines | ||||||||||
cd frontend | ||||||||||
npm install @auth0/ai @langchain/langgraph-sdk | ||||||||||
npx @auth0/ai-components add FederatedConnections | ||||||||||
npx @auth0/ai-components add TokenVault | ||||||||||
``` | ||||||||||
|
||||||||||
Add a new file, `src/components/auth0-ai/FederatedConnections/FederatedConnectionInterruptHandler.tsx`, with the following code: | ||||||||||
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?: { | ||||||||||
|
@@ -348,21 +348,21 @@ interface FederatedConnectionInterruptHandlerProps { | |||||||||
}; | ||||||||||
} | ||||||||||
|
||||||||||
export function FederatedConnectionInterruptHandler({ | ||||||||||
export function TokenVaultInterruptHandler({ | ||||||||||
interrupt, | ||||||||||
onFinish, | ||||||||||
auth, | ||||||||||
}: FederatedConnectionInterruptHandlerProps) { | ||||||||||
}: TokenVaultInterruptHandlerProps) { | ||||||||||
if ( | ||||||||||
!interrupt || | ||||||||||
!FederatedConnectionInterrupt.isInterrupt(interrupt.value) | ||||||||||
!TokenVaultInterrupt.isInterrupt(interrupt.value) | ||||||||||
) { | ||||||||||
return null; | ||||||||||
} | ||||||||||
|
||||||||||
return ( | ||||||||||
<div key={interrupt.ns?.join("")} className="whitespace-pre-wrap"> | ||||||||||
<EnsureAPIAccess | ||||||||||
<TokenVaultConsent | ||||||||||
mode="popup" | ||||||||||
interrupt={interrupt.value} | ||||||||||
onFinish={onFinish} | ||||||||||
|
@@ -378,11 +378,11 @@ export function FederatedConnectionInterruptHandler({ | |||||||||
} | ||||||||||
``` | ||||||||||
|
||||||||||
Now, update your chat window code to include the `FederatedConnectionInterruptHandler` component, for example: | ||||||||||
Now, update your chat window code to include the `TokenVaultInterruptHandler` component, for example: | ||||||||||
|
||||||||||
```tsx src/components/chat-window.tsx wrap lines highlight={2,3,25-50} | ||||||||||
//... | ||||||||||
import { FederatedConnectionInterruptHandler } from '@/components/auth0-ai/FederatedConnections/FederatedConnectionInterruptHandler'; | ||||||||||
import { TokenVaultInterruptHandler } from '@/components/auth0-ai/TokenVault/TokenVaultInterruptHandler'; | ||||||||||
import { getLoginUrl } from "@/lib/use-auth"; | ||||||||||
|
||||||||||
//... existing code | ||||||||||
|
@@ -407,7 +407,7 @@ export function ChatWindow(props: { | |||||||||
/> | ||||||||||
<div className="flex flex-col max-w-[768px] mx-auto pb-12 w-full"> | ||||||||||
{!!chat.interrupt?.value && ( | ||||||||||
<FederatedConnectionInterruptHandler | ||||||||||
<TokenVaultInterruptHandler | ||||||||||
auth={{ | ||||||||||
authorizePath: getLoginUrl(), | ||||||||||
returnTo: new URL( | ||||||||||
|
@@ -450,4 +450,4 @@ That's it! You successfully integrated third-party API access using Token Vault | |||||||||
### View a complete example | ||||||||||
Want to see how it all comes together? Explore or clone the fully implemented sample application on [GitHub](https://github.com/auth0-samples/auth0-ai-samples/tree/main/call-apis-on-users-behalf/others-api/langchain-fastapi-py). | ||||||||||
</Tab> | ||||||||||
</Tabs> | ||||||||||
</Tabs> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
in https://auth0.com/docs/secure/tokens/token-vault, we use the terminology "external provider" instead of "third-party connection". Should we align? (probably more a question for docs partners)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"... making it easy to get access tokens to connect with external applications."
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i could definitely use some copy/content/batch suggestion help here. rebased PR again w/ the latest today 😄