You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: auth4genai/intro/call-others-apis-on-users-behalf.mdx
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,6 @@
1
1
---
2
2
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."
Copy file name to clipboardExpand all lines: auth4genai/intro/token-vault.mdx
+3-3Lines changed: 3 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -49,9 +49,9 @@ By using Token Vault, you can:
49
49
The process of using Token Vault involves the following key steps:
50
50
51
51
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.
@@ -46,7 +46,7 @@ Integrate the Auth0 AI SDK into your application to secure your async AI agent w
46
46
47
47
#### Configure the Auth0 AI SDK
48
48
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.
50
50
51
51
Create a file at `app/core/auth0_ai.py` and instantiate a new Auth0 AI SDK client:
# In practice, the process that is awaiting the user confirmation
87
94
# could crash or timeout before the user approves the request.
88
95
on_authorization_request="block",
96
+
89
97
)
90
98
```
91
99
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:
93
101
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.
95
103
- Auth0 sends the user a mobile push notification. The AI agent polls the `/token` endpoint for a user response.
96
104
- The mobile application retrieves the `bindingMessage` containing the consent details, in this case, the details of the product to purchase.
97
105
- The user responds to the request:
@@ -138,17 +146,17 @@ async def api_route(
138
146
139
147
#### Create a tool to call your API
140
148
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.
142
150
143
151
Now, create a file `app/agents/tools/shop_online.py` and add the following code:
@@ -451,4 +451,4 @@ That's it! You successfully integrated third-party API access using Token Vault
451
451
### View a complete example
452
452
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).
0 commit comments