configure-auth0-token-vault 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/README.md +292 -0
  2. package/package.json +27 -0
  3. package/src/index.js +1182 -0
package/README.md ADDED
@@ -0,0 +1,292 @@
1
+ # Auth0 Token Vault Setup CLI
2
+
3
+ An interactive CLI tool to configure Auth0 Token Vault for your applications. This script automates the setup process for storing and managing external identity provider tokens securely with Auth0.
4
+
5
+ ## What is Token Vault?
6
+
7
+ Token Vault is an Auth0 feature that securely stores access and refresh tokens from external identity providers (like Google, GitHub, Microsoft, etc.) after users authenticate. This allows your application to:
8
+
9
+ - Store external provider tokens securely in Auth0
10
+ - Retrieve tokens on behalf of users without re-authentication
11
+ - Exchange Auth0 tokens for external provider tokens
12
+ - Manage multiple linked accounts per user
13
+
14
+ ## Features
15
+
16
+ - 🚀 Interactive setup wizard
17
+ - 🔐 Automatic configuration of applications, connections, and APIs
18
+ - 📦 Support for multiple Token Vault patterns
19
+ - ✅ Idempotent - safe to run multiple times
20
+ - 🐛 Debug mode for troubleshooting
21
+ - 📝 Detailed usage instructions after setup
22
+
23
+ ## Prerequisites
24
+
25
+ ### 1. Node.js
26
+
27
+ - **Node.js** 18 or higher
28
+
29
+ ### 2. Auth0 CLI
30
+
31
+ Install and configure the Auth0 CLI:
32
+
33
+ ```bash
34
+ brew tap auth0/auth0-cli && brew install auth0
35
+ ```
36
+
37
+ ### 3. Auth0 Tenant
38
+
39
+ - An **Auth0 tenant** with admin access
40
+
41
+ ### 4. Social or Enterprise Connection
42
+
43
+ You must configure at least one social or enterprise connection before running this script.
44
+
45
+ **To create a connection:**
46
+
47
+ 1. Go to the [Auth0 Dashboard](https://manage.auth0.com/)
48
+ 2. Navigate to **Authentication → Social**
49
+ 3. Click **Create Connection**
50
+ 4. Select your identity provider (e.g., Google, GitHub, Microsoft)
51
+ 5. Configure the connection settings
52
+ 6. **Important:** Set the connection purpose to one of:
53
+ - **Connected Accounts for Token Vault** - If this connection will only be used for linking accounts
54
+ - **Authentication and Connected Accounts for Token Vault** - If this connection will be used for both user login and account linking
55
+
56
+ **Supported providers:**
57
+
58
+ - Google, GitHub, LinkedIn, Microsoft, Facebook, Twitter
59
+ - Dropbox, Box, Salesforce, Fitbit, Slack, Spotify, Stripe
60
+ - Custom OAuth2 or OIDC connections
61
+
62
+ > **Note:** The connection must support Token Vault. Most social and enterprise OAuth2/OIDC connections are compatible.
63
+
64
+ ## Usage
65
+
66
+ Run the interactive setup:
67
+
68
+ ```bash
69
+ npx configure-auth0-token-vault
70
+ ```
71
+
72
+ Or with debug logging:
73
+
74
+ ```bash
75
+ DEBUG=true npx configure-auth0-token-vault
76
+ # or
77
+ npx configure-auth0-token-vault -- --debug
78
+ ```
79
+
80
+ ### Supported Application Types
81
+
82
+ Token Vault requires **confidential clients** that can securely store client secrets. This script supports:
83
+
84
+ - ✅ **Regular Web Applications** - Web apps with a secure backend server
85
+ - ✅ **Machine to Machine** - Backend services, APIs, and worker applications
86
+
87
+ ❌ **Not supported:** Single Page Applications (SPAs) and Native apps are public clients and cannot use Token Vault directly. If you need Token Vault functionality in an SPA or mobile app, you must proxy requests through a backend API.
88
+
89
+ ## Token Vault Flavors
90
+
91
+ The script supports four Token Vault configurations:
92
+
93
+ ### 1. Connected Accounts
94
+
95
+ **Use case:** Allow users to link and manage multiple external accounts through your application UI.
96
+
97
+ **What it configures:**
98
+
99
+ - My Account API activation
100
+ - Client grants for Connected Accounts scopes
101
+ - Multi-Resource Refresh Token (MRRT) policies
102
+ - Connection settings
103
+
104
+ **Example:** A social media dashboard where users link their Twitter, Facebook, and Instagram accounts.
105
+
106
+ ### 2. Refresh Token Exchange
107
+
108
+ **Use case:** Backend services that need to retrieve external provider tokens using Auth0 refresh tokens, without active user sessions.
109
+
110
+ **What it configures:**
111
+
112
+ - Everything from Connected Accounts
113
+ - Usage instructions for token exchange endpoint
114
+
115
+ **Example:** A scheduled job that posts to users' social media accounts on their behalf.
116
+
117
+ **Token Exchange:**
118
+
119
+ ```bash
120
+ POST https://{your-domain}/oauth/token
121
+ Content-Type: application/json
122
+
123
+ {
124
+ "grant_type": "urn:auth0:params:oauth:grant-type:token-exchange:federated-connection-access-token",
125
+ "subject_token": "<auth0_refresh_token>",
126
+ "subject_token_type": "urn:ietf:params:oauth:token-type:refresh_token",
127
+ "requested_token_type": "http://auth0.com/oauth/token-type/federated-connection-access-token",
128
+ "connection": "google-oauth2",
129
+ "client_id": "<your_client_id>",
130
+ "client_secret": "<your_client_secret>"
131
+ }
132
+ ```
133
+
134
+ ### 3. Access Token Exchange
135
+
136
+ **Use case:** Backend APIs that exchange Auth0 access tokens for external provider tokens when handling user requests.
137
+
138
+ **What it configures:**
139
+
140
+ - Everything from Connected Accounts
141
+ - Optional Custom API Client creation
142
+ - Usage instructions for access token exchange
143
+
144
+ **Example:** An API endpoint that reads a user's Google Calendar events when they make a request.
145
+
146
+ **Token Exchange:**
147
+
148
+ ```bash
149
+ POST https://{your-domain}/oauth/token
150
+ Content-Type: application/json
151
+
152
+ {
153
+ "grant_type": "urn:auth0:params:oauth:grant-type:token-exchange:federated-connection-access-token",
154
+ "subject_token": "<auth0_access_token>",
155
+ "subject_token_type": "urn:ietf:params:oauth:token-type:access_token",
156
+ "requested_token_type": "http://auth0.com/oauth/token-type/federated-connection-access-token",
157
+ "connection": "google-oauth2",
158
+ "client_id": "<custom_api_client_id>",
159
+ "client_secret": "<custom_api_client_secret>"
160
+ }
161
+ ```
162
+
163
+ ### 4. Privileged Worker Token Exchange
164
+
165
+ **Use case:** Machine-to-machine applications that need to retrieve external provider tokens for specific users without active sessions.
166
+
167
+ **What it configures:**
168
+
169
+ - Everything from Connected Accounts
170
+ - Private Key JWT authentication setup
171
+ - Usage instructions for JWT bearer token exchange
172
+
173
+ **Example:** A background worker that syncs data from users' Dropbox accounts to your system.
174
+
175
+ **Token Exchange:**
176
+
177
+ ```bash
178
+ POST https://{your-domain}/oauth/token
179
+ Content-Type: application/json
180
+
181
+ {
182
+ "grant_type": "urn:auth0:params:oauth:grant-type:token-exchange:federated-connection-access-token",
183
+ "subject_token": "<signed_jwt>",
184
+ "subject_token_type": "urn:ietf:params:oauth:token-type:jwt",
185
+ "requested_token_type": "http://auth0.com/oauth/token-type/federated-connection-access-token",
186
+ "connection": "google-oauth2",
187
+ "client_id": "<worker_client_id>",
188
+ "client_assertion_type": "urn:ietf:params:oauth:client-assertion-type:jwt-bearer",
189
+ "client_assertion": "<client_jwt>"
190
+ }
191
+ ```
192
+
193
+ ## What Gets Configured
194
+
195
+ The script automatically configures:
196
+
197
+ ### Application Settings
198
+
199
+ - ✅ Token Vault grant type (`urn:auth0:params:oauth:grant-type:token-exchange:federated-connection-access-token`)
200
+ - ✅ First-party application status
201
+ - ✅ OIDC conformance
202
+ - ✅ Confidential client authentication
203
+ - ✅ Required grant types (authorization_code, refresh_token)
204
+
205
+ ### Connections
206
+
207
+ - ✅ Connected Accounts activation
208
+ - ✅ Application enablement
209
+
210
+ ### My Account API
211
+
212
+ - ✅ API creation/activation
213
+ - ✅ Connected Accounts scopes
214
+ - ✅ Access policy configuration (`require_client_grant`)
215
+
216
+ ### Client Grants
217
+
218
+ - ✅ User-type client grant with Connected Accounts scopes:
219
+ - `create:me:connected_accounts`
220
+ - `read:me:connected_accounts`
221
+ - `delete:me:connected_accounts`
222
+
223
+ ### Multi-Resource Refresh Token (MRRT)
224
+
225
+ - ✅ MRRT policies for My Account API
226
+
227
+ ## Supported Connections
228
+
229
+ The script works with these identity providers:
230
+
231
+ - Google (`google-oauth2`)
232
+ - GitHub (`github`)
233
+ - LinkedIn (`linkedin`)
234
+ - Microsoft (`microsoft`)
235
+ - Facebook (`facebook`)
236
+ - Twitter (`twitter`)
237
+ - Dropbox (`dropbox`)
238
+ - Box (`box`)
239
+ - Salesforce (`salesforce`)
240
+ - Fitbit (`fitbit`)
241
+ - Slack (`slack`)
242
+ - Spotify (`spotify`)
243
+ - Stripe (`stripe-connect`)
244
+ - Custom OAuth2 (`oauth2`)
245
+ - Custom OIDC (`oidc`)
246
+
247
+ ## Troubleshooting
248
+
249
+ ### My Account API Not Found
250
+
251
+ If the script can't create the My Account API automatically, you'll need to activate it manually:
252
+
253
+ 1. Go to **Auth0 Dashboard → Applications → APIs**
254
+ 2. Look for the **My Account API** banner
255
+ 3. Click **Activate**
256
+ 4. Run the script again
257
+
258
+ ### Authentication Issues
259
+
260
+ If you see "insufficient scopes" errors:
261
+
262
+ ```bash
263
+ auth0 login --scopes "read:clients,update:clients,create:clients,read:resource_servers,create:resource_servers,update:resource_servers,read:client_grants,create:client_grants,update:client_grants,read:connections,update:connections"
264
+ ```
265
+
266
+ ### Debug Mode
267
+
268
+ Enable debug logging to see detailed API calls:
269
+
270
+ ```bash
271
+ DEBUG=true npm start
272
+ ```
273
+
274
+ ## Security Considerations
275
+
276
+ - **Confidential clients only:** Token Vault requires confidential clients (Regular Web Applications or Machine-to-Machine). Public clients like SPAs or Native apps cannot use Token Vault directly without a backend proxy.
277
+ - **Never commit credentials:** The script displays client secrets - store them securely
278
+ - **Refresh token rotation:** The script does NOT enable refresh token rotation (as Token Vault doesn't support it)
279
+ - **MFA policy:** Token Vault requires MFA policy to NOT be "Always"
280
+
281
+ ## Resources
282
+
283
+ - [Token Vault Documentation](https://auth0.com/docs/secure/tokens/token-vault)
284
+ - [Connected Accounts](https://auth0.com/docs/secure/call-apis-on-users-behalf/token-vault/connected-accounts-for-token-vault)
285
+ - [Refresh Token Exchange](https://auth0.com/docs/secure/call-apis-on-users-behalf/token-vault/refresh-token-exchange-with-token-vault)
286
+ - [Access Token Exchange](https://auth0.com/docs/secure/call-apis-on-users-behalf/token-vault/access-token-exchange-with-token-vault)
287
+ - [Privileged Worker](https://auth0.com/docs/secure/call-apis-on-users-behalf/token-vault/privileged-worker-token-exchange-with-token-vault)
288
+ - [Auth0 CLI Documentation](https://github.com/auth0/auth0-cli)
289
+
290
+ ## License
291
+
292
+ MIT
package/package.json ADDED
@@ -0,0 +1,27 @@
1
+ {
2
+ "name": "configure-auth0-token-vault",
3
+ "version": "1.0.0",
4
+ "description": "CLI tool to setup Auth0 Token Vault Connected Accounts prerequisites",
5
+ "type": "module",
6
+ "bin": {
7
+ "configure-auth0-token-vault": "./src/index.js"
8
+ },
9
+ "scripts": {
10
+ "start": "node src/index.js"
11
+ },
12
+ "keywords": [
13
+ "auth0",
14
+ "token-vault",
15
+ "connected-accounts",
16
+ "cli"
17
+ ],
18
+ "license": "MIT",
19
+ "engines": {
20
+ "node": ">=18"
21
+ },
22
+ "dependencies": {
23
+ "@clack/prompts": "^0.9.0",
24
+ "execa": "^9.5.0",
25
+ "picocolors": "^1.1.0"
26
+ }
27
+ }