+ Allowed Web Origins: {createAuth0ApplicationStep.allowedWebOrigins}
+
+ )}
+
+ To learn more about Auth0 applications, read{" "}
+
+ Applications
+
+ .
+
+ );
+ }
+ // Conditionally add steps
+ if (refreshTokenGrantStep) {
+ steps.push(
+
+ Enable the Refresh Token Grant for your{" "}
+ {refreshTokenGrantStep.applicationName}. Go to{" "}
+
+ Applications > [Your Application] > Settings > Advanced >
+ Grant Types
+ {" "}
+ and enable the Refresh Token grant type.
+
+ );
+ }
+
+ if (createAuth0ApiStep) {
+ steps.push(
+
+
+
In your Auth0 Dashboard, go to Applications > APIs
+
Create a new API with an identifier (audience)
+
Once API is created, go to the APIs Settings > Access Settings and enable Allow Offline Access
+
Note down the API identifier for your environment variables
+
+ To learn more about Auth0 APIs, read{" "}
+
+ APIs
+
+ .
+
+ );
+ }
+
+ if (createResourceServerClientStep) {
+ steps.push(
+
+ This is a special client that allows your API server to perform token
+ exchanges using{" "}
+
+ access tokens
+ {" "}
+ instead of{" "}
+
+ refresh tokens
+
+ . This client enables Token Vault to exchange an access token for an
+ external API access token (e.g., Google Calendar API).
+
+
+ Create this client programmatically via the Auth0 Management API:
+
+
+ {`curl -L 'https://{tenant}.auth0.com/api/v2/clients' \\
+-H 'Content-Type: application/json' \\
+-H 'Accept: application/json' \\
+-H 'Authorization: Bearer {MANAGEMENT_API_TOKEN}' \\
+-d '{
+ "name": "Calendar API Resource Server Client",
+ "app_type": "resource_server",
+ "grant_types": ["urn:auth0:params:oauth:grant-type:token-exchange:federated-connection-access-token"],
+ "resource_server_identifier": "YOUR_API_IDENTIFIER"
+}'`}
+
+
+
+
+ Note that your MANAGEMENT_API_TOKEN above must have the{" "}
+ create:clients scope in order to create a new client.
+ One way you can create a new token with this access is by doing the
+ following:
+
+
+ Navigate to Applications > APIs > Auth0 Management API > API Explorer
+ tab in your tenant
+
+
Hit the Create & Authorize Test Application button
+
+ Copy the jwt access token shown and provide it as the{" "}
+ MANAGEMENT_API_TOKEN
+
+
+
+
+ Note down the client_id and client_secret{" "}
+ returned from the curl response for your environment variables after running curl
+ successfully.
+
+
+
+ );
+ }
+
+ if (tokenExchangeGrantStep) {
+ steps.push(
+
+ Enable the Token Exchange Grant for your{" "}
+ {tokenExchangeGrantStep.applicationName}. Go to{" "}
+
+ Applications > [Your Application] > Settings > Advanced >
+ Grant Types
+ {" "}
+ and enable the Token Exchange grant type.
+
+ );
+ }
+
+ // Always include these final steps
+ steps.push(
+
+ Set up a Google developer account that allows for third-party API calls
+ following the{" "}
+
+ Google Sign-in and Authorization
+ {" "}
+ instructions.
+
+ );
+
+ steps.push(
+
+ Set up an{" "}
+
+ OpenAI account and API key
+
+ .
+
+ );
+
return (
<>
Prerequisites
Before getting started, make sure you have completed the following steps:
-
-
- To continue with this quickstart, you need an{" "}
-
- Auth0 account
- {" "}
- and a Developer Tenant.
-
-
-
- Create and configure an Auth0 Application
- {" "}
- with the following properties:
-
-
- Type: Regular Web
-
-
- Allowed Callback URLs: {callbackUrl}
-
-
- Allowed Logout URLs: {logoutUrl}
-
-
- To learn more about Auth0 applications, read{" "}
-
- Applications
-
- .
-
-
- Enable the Token Exchange Grant for your Auth0 Application. Go to{" "}
-
- Applications > [Your Application] > Settings > Advanced
- > Grant Types
- {" "}
- and enable the Token Exchange grant type.
-
-
-
- Set up a Google developer account that allows for third-party API
- calls following the{" "}
- Google Sign-in and Authorization{" "}
- instructions.
-
-
-
- Set up an{" "}
-
- OpenAI account and API key
-
- .
-
-
+ {steps}
>
);
};
diff --git a/auth4genai/snippets/get-started/react-spa-vercel-ai/call-others-api.mdx b/auth4genai/snippets/get-started/react-spa-vercel-ai/call-others-api.mdx
new file mode 100644
index 0000000..99a9664
--- /dev/null
+++ b/auth4genai/snippets/get-started/react-spa-vercel-ai/call-others-api.mdx
@@ -0,0 +1,557 @@
+import { Prerequisites } from "/snippets/get-started/prerequisites/call-others-api.jsx";
+
+
+
+### Prepare React SPA + Hono API
+
+**Recommended**: To use this example, clone the [Auth0 AI JS](https://github.com/auth0-lab/auth0-ai-js.git) repository:
+
+```bash wrap lines
+git clone https://github.com/auth0-lab/auth0-ai-js.git
+cd auth0-ai-js/examples/calling-apis/spa-with-backend-api/react-hono-ai-sdk
+```
+
+### Install dependencies
+
+In the root directory of your project, note some of the following dependencies:
+
+**Client dependencies:**
+
+- `@auth0/auth0-spa-js`: Auth0 SPA SDK for client-side authentication
+- `@auth0/ai-vercel`: [Auth0 AI SDK for Vercel AI](https://github.com/auth0-lab/auth0-ai-js/tree/main/packages/ai-vercel) built for GenAI applications
+- `ai`: Core [Vercel AI SDK](https://sdk.vercel.ai/docs) module
+
+**Server dependencies:**
+
+- `@hono/node-server`: Node.js server adapter for Hono
+- `hono`: Lightweight web framework
+- `ai`: Core [Vercel AI SDK](https://sdk.vercel.ai/docs) module
+- `@ai-sdk/openai`: [OpenAI](https://sdk.vercel.ai/providers/ai-sdk-providers/openai) provider
+- `googleapis`: Node.js client for Google APIs
+- `jose`: JavaScript Object Signing and Encryption library for JWT verification
+
+```bash wrap lines
+# Install all client & server dependencies from the root directory of the project.
+npm install
+```
+
+### Update the environment files
+
+#### Client (.env)
+
+```bash .env wrap lines
+VITE_AUTH0_DOMAIN=your-auth0-domain
+VITE_AUTH0_CLIENT_ID=your-spa-client-id
+VITE_AUTH0_AUDIENCE=your-api-identifier
+VITE_API_URL=http://localhost:3001
+```
+
+#### Server (.env)
+
+```bash .env wrap lines
+AUTH0_DOMAIN=your-auth0-domain
+AUTH0_AUDIENCE=your-api-identifier
+AUTH0_CLIENT_ID=your-resource-server-client-id
+AUTH0_CLIENT_SECRET=your-resource-server-client-secret
+OPENAI_API_KEY=your-openai-api-key
+PORT=3001
+```
+
+### Configure the SPA for step-up authorization
+
+Unlike the Next.js example which uses refresh tokens, this React SPA approach uses **access tokens** for token exchange with Token Vault. The SPA handles step-up authorization using Auth0 SPA SDK's `loginWithPopup()` method to display the consent screen, and allow the user to grant additional permissions.
+
+Create `client/src/components/FederatedConnectionPopup.tsx`:
+
+```tsx client/src/components/FederatedConnectionPopup.tsx wrap lines
+import { getAuth0Client } from "../lib/auth0";
+import { Button } from "./ui/button";
+import { Card, CardContent, CardHeader, CardTitle } from "./ui/card";
+
+import type { Auth0InterruptionUI } from "@auth0/ai-vercel/react";
+interface FederatedConnectionPopupProps {
+ interrupt: Auth0InterruptionUI;
+}
+
+export function FederatedConnectionPopup({
+ interrupt,
+}: FederatedConnectionPopupProps) {
+ const [isLoading, setIsLoading] = useState(false);
+
+ const { connection, requiredScopes, resume } = interrupt;
+
+ // Use Auth0 SPA SDK to request additional connection/scopes
+ const startFederatedLogin = useCallback(async () => {
+ try {
+ setIsLoading(true);
+
+ // Filter out empty scopes
+ const validScopes = requiredScopes.filter(
+ (scope: string) => scope && scope.trim() !== ""
+ );
+
+ const auth0Client = getAuth0Client();
+
+ // Use getTokenWithPopup for step-up authorization to request additional scopes
+ await auth0Client.getTokenWithPopup({
+ authorizationParams: {
+ prompt: "consent", // Required for Google Calendar scopes
+ connection: connection, // e.g., "google-oauth2"
+ connection_scope: validScopes.join(" "), // Google-specific scopes
+ access_type: "offline",
+ },
+ });
+
+ // The Auth0 client should automatically use the new token, but we should trigger
+ // a refresh to ensure the latest token is cached.
+ await auth0Client.getTokenSilently();
+
+ setIsLoading(false);
+
+ // Resume the interrupted tool after successful authorization
+ if (typeof resume === "function") {
+ resume();
+ }
+ } catch (error) {
+ setIsLoading(false);
+
+ if (typeof resume === "function") {
+ resume();
+ }
+ }
+ }, [connection, requiredScopes, resume]);
+
+ if (isLoading) {
+ return (
+
+
+
+
+
+ Connecting to {connection.replace("-", " ")}...
+
+ );
+}
+```
+
+### Key differences from Next.js approach
+
+This React SPA implementation differs from the Next.js example in a few important ways:
+
+1. **Token Vault Access Token Exchange**: Instead of using refresh tokens, this approach exchanges the SPA's access token for a third-party access token
+2. **Client-Side Authorization**: Client Login and Step-up authorization is all handled client-side using `@auth0/auth0-spa-js`
+3. **Resource Server Client**: Requires a special Resource Server Client configured for token exchange with Token Vault
+4. **Interrupt Handling**: Tool access errors and Step-up authorization are handled via interrupts in the React client with popup-based re-authorization
+
+### Test your application
+
+1. Start the client & server using Turbo: `npm run dev`
+2. Navigate to `http://localhost:5173`
+3. Log in with Google and ask your AI agent about your calendar
+
+The application will automatically prompt for additional calendar permissions when needed using Auth0's step-up authorization flow.
+
+That's it! You've successfully integrated federated connections with access tokens into your React SPA + Vercel AI application.
+
+Explore [the example app on GitHub](https://github.com/auth0-lab/auth0-ai-js/tree/main/examples/calling-apis/spa-with-backend-api/react-hono-ai-sdk).