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
* feat(vercel-react-spa-js): add markdown formatting
* fix: various inconsistencies with twin sample in `auth0-ai-js`
* fix: formatting
* fix: get rid of `any`
Copy file name to clipboardExpand all lines: call-apis-on-users-behalf/others-api/vercel-react-spa-js/README.md
+39-36Lines changed: 39 additions & 36 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -10,7 +10,7 @@ The flow works by having the client send its access token to a First Party API,
10
10
11
11
## Features
12
12
13
-
The following example app demonstrates using a SPA chatbot application, a backend API (and a linked Resource Server Client), and Token Vault to access a Third Party API (Google Calendar API).
13
+
The following example app demonstrates using a SPA chatbot application, a backend API (and a linked Custom API Client), and Token Vault to access a Third Party API (Google Calendar API).
14
14
15
15
This template leverages a modern stack for building a React SPA application with a Hono API.
16
16
@@ -51,7 +51,7 @@ You will need the following prerequisites to run this app:
51
51
52
52
### 1. Auth0 Configuration
53
53
54
-
1. Create an Auth0 Application:
54
+
1. Create an Auth0 SPA Application:
55
55
- Go to your [Auth0 Dashboard](https://manage.auth0.com/)
56
56
- Create a new **Single Page Application**
57
57
- Configure the following settings:
@@ -64,59 +64,62 @@ You will need the following prerequisites to run this app:
64
64
2. Create an Auth0 API (representing your back-end API):
65
65
- In your Auth0 Dashboard, go to APIs
66
66
- Create a new API with an identifier (audience)
67
-
-Enable "Allow Offline Access" in Access Settings
67
+
-Make sure to "Allow Offline Access" in Access Settings
68
68
- Note down the API identifier for your environment variables
69
69
70
70
3. Create a Custom API Client (for Token Vault Token Exchange):
71
-
- The Custom API Client 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).
72
-
- Setup steps:
73
-
- Go to the API you created in Step #2 and click the **Add Application** button in the right top corner and create the application
74
-
- In the application settings, ensure that the `Token Vault` grant type is enabled under the Advanced Settings
75
-
- Note down the <code>client id</code> and <code>client secret</code> for your environment variables
71
+
- This is a special application that allows your API to perform token exchanges
72
+
- In your Auth0 Dashboard, on the configuration page of your API, click the "Add Application" button in the header and create the Custom API Client
73
+
- Ensure that the `Token Vault` grant type is enabled under the Advanced Settings
74
+
- Note down the "Client ID" and "Client Secret" of this newly created Custom API Client
75
+
- Now your Custom API will be able to use Token Vault, to exchange an access token for an external API access token (e.g., Google Calendar API)
76
76
77
77
4. Grant access to My Account API from your application:
78
-
- When a call to Token Vault fails due to the user not having a connected account (or lacking some permissions), this demo triggers a Connect Account flow for this user. This flow leverages Auth0's [My Account API](https://auth0.com/docs/manage-users/my-account-api), and as such, your application will need to have access to it in order to enable this flow.
79
-
- In order to grant access, use the [Application Access to APIs](https://auth0.com/docs/get-started/applications/application-access-to-apis-client-grants) feature, by creating a client grant for user flows.
80
-
- In your Auth0 Dashboard, go to APIs, and open the Settings for "Auth0 My Account API".
81
-
- On the Settings tab, make sure to enable the "Allow Skipping User Consent" toggle.
82
-
- On the Applications tab, authorize your SPA application, ensuring that the `create:me:connected_accounts` permission at least is selected.
78
+
- When a call to Token Vault fails due to the user not having a connected account (or lacking some permissions), this demo triggers a Connect Account flow for this user. This flow leverages Auth0's [My Account API](https://auth0.com/docs/manage-users/my-account-api), and as such, your application will need to have access to it in order to enable this flow.
79
+
- In order to grant access, use the [Application Access to APIs](https://auth0.com/docs/get-started/applications/application-access-to-apis-client-grants) feature, by creating a client grant for user flows.
80
+
- In your Auth0 Dashboard, go to APIs, and open the Settings for "Auth0 My Account API".
81
+
- On the Settings tab, make sure to enable the "Allow Skipping User Consent" toggle.
82
+
- On the Applications tab, authorize your application, ensuring that the `create:me:connected_accounts` permission at least is selected.
83
83
84
84
5. Define a Multi-Resource Refresh Token policy for your SPA Application:
85
-
- After your SPA Application has been granted access to the My Account API, you will also need to leverage the [Multi-Resource Refresh Token](https://auth0.com/docs/secure/tokens/refresh-tokens/multi-resource-refresh-token) feature, where the refresh token delivered to your SPA will allow it to obtain an access token to call My Account API.
86
-
- This will require defining a new [refresh token policy](https://auth0.com/docs/secure/tokens/refresh-tokens/multi-resource-refresh-token/configure-and-implement-multi-resource-refresh-token) for your SPA Application where the `audience` is `https://<your auth0 domain>/me/` and the `scope` should include at least the `"create:me:connected_accounts"` scope.
87
-
- Setup steps:
88
-
- In your Auth0 Dashboard, go to Applications, and open the Settings for your SPA application created at step 1.
89
-
- Under the "Multi-Resource Refresh Token" section, click "Edit Configuration".
90
-
- Enable MRRT for "Auth0 My Account API".
91
-
92
-
6. Configure a Social Connection for Google in Auth0:
93
-
- Make sure to enable the "Use for Connected Accounts with Token Vault" toggle
94
-
- Make sure to enable `Offline Access` and all `Calendar` scopes from the Permissions options
95
-
- On the Applications tab, make sure to enable the connection for your SPA Application created in Step 1 and the Custom API Client created in Step 3
96
-
- Test the connection in Auth0 "Try Connection" screen and make sure connection is working & configured correctly
85
+
- After your SPA Application has been granted access to the My Account API, you will also need to leverage the [Multi-Resource Refresh Token](https://auth0.com/docs/secure/tokens/refresh-tokens/multi-resource-refresh-token) feature, where the refresh token delivered to your SPA will allow it to obtain an access token to call My Account API.
86
+
- This will require defining a new [refresh token policy](https://auth0.com/docs/secure/tokens/refresh-tokens/multi-resource-refresh-token/configure-and-implement-multi-resource-refresh-token) for your SPA Application where the `audience` is `https://<your auth0 domain>/me/` and the `scope` should include at least the `"create:me:connected_accounts"` scope.
87
+
- Setup steps:
88
+
- In your Auth0 Dashboard, go to Applications, and open the Settings for your SPA application created at step 1.
89
+
- Under the "Multi-Resource Refresh Token" section, click "Edit Configuration".
90
+
- Enable MRRT for "Auth0 My Account API".
91
+
92
+
6. Configure a Social Connection for Google in Auth0
93
+
- Make sure to enable the "Use for Connected Accounts with Token Vault" toggle
94
+
- Make sure to enable `Offline Access` and all `Calendar` scopes from the Permissions options
95
+
- On the Applications tab, make sure to enable the connection for your SPA Application created in Step 1
96
+
- Test the connection in Auth0 "Try Connection" screen and make sure the connection is working & configured correctly
97
97
98
98
### 2. Environment Variables
99
99
100
100
#### Client (.env)
101
-
Copy `.env.example` to `.env` and fill in your Auth0 configuration:
101
+
From the `./client` directory, copy `.env.example` to `.env` and fill in your Auth0 configuration using details from your SPA Application:
102
102
103
103
```bash
104
+
# Auth0 Configuration
104
105
VITE_AUTH0_DOMAIN=your-auth0-domain.auth0.com
105
106
VITE_AUTH0_CLIENT_ID=your-spa-client-id
106
107
VITE_AUTH0_AUDIENCE=your-api-identifier
108
+
109
+
# Server Configuration
107
110
VITE_SERVER_URL=http://localhost:3000
108
111
```
109
112
110
113
#### Server (.env)
111
-
Copy `.env.example` to `.env` and fill in your Auth0 configuration:
114
+
From the `./server` directory, copy `.env.example` to `.env` and fill in your Auth0 configuration using details from API and Custom API Client:
112
115
113
116
```bash
114
117
# Auth0 Configuration
115
118
AUTH0_DOMAIN=your-auth0-domain.auth0.com
116
119
AUTH0_AUDIENCE=your-api-identifier
117
120
118
-
# Custom API CLient Configuration (for Token Vault token exchange)
119
-
# These credentials belong to a special "resource_server" client that can perform token exchanges
121
+
# Custom API Client Configuration (for Token Vault token exchange)
122
+
# These credentials belong to Custom API client that can perform token exchanges
0 commit comments