chub-dev 0.1.0 → 0.1.2-beta.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.
- package/README.md +55 -0
- package/bin/chub-mcp +2 -0
- package/dist/airtable/docs/database/javascript/DOC.md +1437 -0
- package/dist/airtable/docs/database/python/DOC.md +1735 -0
- package/dist/amplitude/docs/analytics/javascript/DOC.md +1282 -0
- package/dist/amplitude/docs/analytics/python/DOC.md +1199 -0
- package/dist/anthropic/docs/claude-api/javascript/DOC.md +503 -0
- package/dist/anthropic/docs/claude-api/python/DOC.md +389 -0
- package/dist/asana/docs/tasks/DOC.md +1396 -0
- package/dist/assemblyai/docs/transcription/DOC.md +1043 -0
- package/dist/atlassian/docs/confluence/javascript/DOC.md +1347 -0
- package/dist/atlassian/docs/confluence/python/DOC.md +1604 -0
- package/dist/auth0/docs/identity/javascript/DOC.md +968 -0
- package/dist/auth0/docs/identity/python/DOC.md +1199 -0
- package/dist/aws/docs/s3/javascript/DOC.md +1773 -0
- package/dist/aws/docs/s3/python/DOC.md +1807 -0
- package/dist/binance/docs/trading/javascript/DOC.md +1315 -0
- package/dist/binance/docs/trading/python/DOC.md +1454 -0
- package/dist/braintree/docs/gateway/javascript/DOC.md +1278 -0
- package/dist/braintree/docs/gateway/python/DOC.md +1179 -0
- package/dist/chromadb/docs/embeddings-db/javascript/DOC.md +1263 -0
- package/dist/chromadb/docs/embeddings-db/python/DOC.md +1707 -0
- package/dist/clerk/docs/auth/javascript/DOC.md +1220 -0
- package/dist/clerk/docs/auth/python/DOC.md +274 -0
- package/dist/cloudflare/docs/workers/javascript/DOC.md +918 -0
- package/dist/cloudflare/docs/workers/python/DOC.md +994 -0
- package/dist/cockroachdb/docs/distributed-db/DOC.md +1500 -0
- package/dist/cohere/docs/llm/DOC.md +1335 -0
- package/dist/datadog/docs/monitoring/javascript/DOC.md +1740 -0
- package/dist/datadog/docs/monitoring/python/DOC.md +1815 -0
- package/dist/deepgram/docs/speech/javascript/DOC.md +885 -0
- package/dist/deepgram/docs/speech/python/DOC.md +685 -0
- package/dist/deepl/docs/translation/javascript/DOC.md +887 -0
- package/dist/deepl/docs/translation/python/DOC.md +944 -0
- package/dist/deepseek/docs/llm/DOC.md +1220 -0
- package/dist/directus/docs/headless-cms/javascript/DOC.md +1128 -0
- package/dist/directus/docs/headless-cms/python/DOC.md +1276 -0
- package/dist/discord/docs/bot/javascript/DOC.md +1090 -0
- package/dist/discord/docs/bot/python/DOC.md +1130 -0
- package/dist/elasticsearch/docs/search/DOC.md +1634 -0
- package/dist/elevenlabs/docs/text-to-speech/javascript/DOC.md +336 -0
- package/dist/elevenlabs/docs/text-to-speech/python/DOC.md +552 -0
- package/dist/firebase/docs/auth/DOC.md +1015 -0
- package/dist/gemini/docs/genai/javascript/DOC.md +691 -0
- package/dist/gemini/docs/genai/python/DOC.md +555 -0
- package/dist/github/docs/octokit/DOC.md +1560 -0
- package/dist/google/docs/bigquery/javascript/DOC.md +1688 -0
- package/dist/google/docs/bigquery/python/DOC.md +1503 -0
- package/dist/hubspot/docs/crm/javascript/DOC.md +1805 -0
- package/dist/hubspot/docs/crm/python/DOC.md +2033 -0
- package/dist/huggingface/docs/transformers/DOC.md +948 -0
- package/dist/intercom/docs/messaging/javascript/DOC.md +1844 -0
- package/dist/intercom/docs/messaging/python/DOC.md +1797 -0
- package/dist/jira/docs/issues/javascript/DOC.md +1420 -0
- package/dist/jira/docs/issues/python/DOC.md +1492 -0
- package/dist/kafka/docs/streaming/javascript/DOC.md +1671 -0
- package/dist/kafka/docs/streaming/python/DOC.md +1464 -0
- package/dist/landingai-ade/docs/api/DOC.md +620 -0
- package/dist/landingai-ade/docs/sdk/python/DOC.md +489 -0
- package/dist/landingai-ade/docs/sdk/typescript/DOC.md +542 -0
- package/dist/landingai-ade/skills/SKILL.md +489 -0
- package/dist/launchdarkly/docs/feature-flags/javascript/DOC.md +1191 -0
- package/dist/launchdarkly/docs/feature-flags/python/DOC.md +1671 -0
- package/dist/linear/docs/tracker/DOC.md +1554 -0
- package/dist/livekit/docs/realtime/javascript/DOC.md +303 -0
- package/dist/livekit/docs/realtime/python/DOC.md +163 -0
- package/dist/mailchimp/docs/marketing/DOC.md +1420 -0
- package/dist/meilisearch/docs/search/DOC.md +1241 -0
- package/dist/microsoft/docs/onedrive/javascript/DOC.md +1421 -0
- package/dist/microsoft/docs/onedrive/python/DOC.md +1549 -0
- package/dist/mongodb/docs/atlas/DOC.md +2041 -0
- package/dist/notion/docs/workspace-api/javascript/DOC.md +1435 -0
- package/dist/notion/docs/workspace-api/python/DOC.md +1400 -0
- package/dist/okta/docs/identity/javascript/DOC.md +1171 -0
- package/dist/okta/docs/identity/python/DOC.md +1401 -0
- package/dist/openai/docs/chat/javascript/DOC.md +407 -0
- package/dist/openai/docs/chat/python/DOC.md +568 -0
- package/dist/paypal/docs/checkout/DOC.md +278 -0
- package/dist/pinecone/docs/sdk/javascript/DOC.md +984 -0
- package/dist/pinecone/docs/sdk/python/DOC.md +1395 -0
- package/dist/plaid/docs/banking/javascript/DOC.md +1163 -0
- package/dist/plaid/docs/banking/python/DOC.md +1203 -0
- package/dist/playwright-community/skills/login-flows/SKILL.md +108 -0
- package/dist/postmark/docs/transactional-email/DOC.md +1168 -0
- package/dist/prisma/docs/orm/javascript/DOC.md +1419 -0
- package/dist/prisma/docs/orm/python/DOC.md +1317 -0
- package/dist/qdrant/docs/vector-search/javascript/DOC.md +1221 -0
- package/dist/qdrant/docs/vector-search/python/DOC.md +1653 -0
- package/dist/rabbitmq/docs/message-queue/javascript/DOC.md +1193 -0
- package/dist/rabbitmq/docs/message-queue/python/DOC.md +1243 -0
- package/dist/razorpay/docs/payments/javascript/DOC.md +1219 -0
- package/dist/razorpay/docs/payments/python/DOC.md +1330 -0
- package/dist/redis/docs/key-value/javascript/DOC.md +1851 -0
- package/dist/redis/docs/key-value/python/DOC.md +2054 -0
- package/dist/registry.json +2817 -0
- package/dist/replicate/docs/model-hosting/DOC.md +1318 -0
- package/dist/resend/docs/email/DOC.md +1271 -0
- package/dist/salesforce/docs/crm/javascript/DOC.md +1241 -0
- package/dist/salesforce/docs/crm/python/DOC.md +1183 -0
- package/dist/search-index.json +1 -0
- package/dist/sendgrid/docs/email-api/javascript/DOC.md +371 -0
- package/dist/sendgrid/docs/email-api/python/DOC.md +656 -0
- package/dist/sentry/docs/error-tracking/javascript/DOC.md +1073 -0
- package/dist/sentry/docs/error-tracking/python/DOC.md +1309 -0
- package/dist/shopify/docs/storefront/DOC.md +457 -0
- package/dist/slack/docs/workspace/javascript/DOC.md +933 -0
- package/dist/slack/docs/workspace/python/DOC.md +271 -0
- package/dist/square/docs/payments/javascript/DOC.md +1855 -0
- package/dist/square/docs/payments/python/DOC.md +1728 -0
- package/dist/stripe/docs/api/DOC.md +1727 -0
- package/dist/stripe/docs/payments/DOC.md +1726 -0
- package/dist/stytch/docs/auth/javascript/DOC.md +1813 -0
- package/dist/stytch/docs/auth/python/DOC.md +1962 -0
- package/dist/supabase/docs/client/DOC.md +1606 -0
- package/dist/twilio/docs/messaging/python/DOC.md +469 -0
- package/dist/twilio/docs/messaging/typescript/DOC.md +946 -0
- package/dist/vercel/docs/platform/DOC.md +1940 -0
- package/dist/weaviate/docs/vector-db/javascript/DOC.md +1268 -0
- package/dist/weaviate/docs/vector-db/python/DOC.md +1388 -0
- package/dist/zendesk/docs/support/javascript/DOC.md +2150 -0
- package/dist/zendesk/docs/support/python/DOC.md +2297 -0
- package/package.json +22 -6
- package/skills/get-api-docs/SKILL.md +84 -0
- package/src/commands/annotate.js +83 -0
- package/src/commands/build.js +12 -1
- package/src/commands/feedback.js +150 -0
- package/src/commands/get.js +83 -42
- package/src/commands/search.js +7 -0
- package/src/index.js +43 -17
- package/src/lib/analytics.js +90 -0
- package/src/lib/annotations.js +57 -0
- package/src/lib/bm25.js +170 -0
- package/src/lib/cache.js +69 -6
- package/src/lib/config.js +8 -3
- package/src/lib/identity.js +99 -0
- package/src/lib/registry.js +103 -20
- package/src/lib/telemetry.js +86 -0
- package/src/mcp/server.js +177 -0
- package/src/mcp/tools.js +251 -0
|
@@ -0,0 +1,968 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: identity
|
|
3
|
+
description: "Auth0 JavaScript/Node.js SDK for OAuth, OIDC, and identity management in server-side applications"
|
|
4
|
+
metadata:
|
|
5
|
+
languages: "javascript"
|
|
6
|
+
versions: "5.0.0"
|
|
7
|
+
updated-on: "2026-03-01"
|
|
8
|
+
source: maintainer
|
|
9
|
+
tags: "auth0,identity,oauth,oidc,authentication"
|
|
10
|
+
---
|
|
11
|
+
|
|
12
|
+
# Auth0 JavaScript/Node.js SDK Coding Guidelines
|
|
13
|
+
|
|
14
|
+
You are an Auth0 API expert. Help me with writing code using the Auth0 SDK for JavaScript/Node.js applications.
|
|
15
|
+
|
|
16
|
+
You can find the official SDK documentation here:
|
|
17
|
+
https://auth0.github.io/node-auth0/
|
|
18
|
+
|
|
19
|
+
## Golden Rule: Use the Correct Auth0 SDK
|
|
20
|
+
|
|
21
|
+
Always use the official Auth0 Node.js SDK for server-side authentication and user management operations. This is the standard library for all Auth0 Management API and Authentication API interactions.
|
|
22
|
+
|
|
23
|
+
- **Library Name:** Auth0 Node.js SDK
|
|
24
|
+
- **NPM Package:** `auth0`
|
|
25
|
+
- **Current Version:** 5.0.0
|
|
26
|
+
- **Minimum Node.js Version:** 20.19.0+ or 22.12.0+ or 24.0.0+
|
|
27
|
+
|
|
28
|
+
**Installation:**
|
|
29
|
+
|
|
30
|
+
```bash
|
|
31
|
+
npm install auth0
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
**Correct Usage:**
|
|
35
|
+
|
|
36
|
+
```javascript
|
|
37
|
+
import { ManagementClient, AuthenticationClient } from 'auth0';
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
**Incorrect:**
|
|
41
|
+
- Using `auth0-js` for server-side operations (this is for browser-based apps)
|
|
42
|
+
- Using unofficial or deprecated Auth0 packages
|
|
43
|
+
|
|
44
|
+
## Environment Variables
|
|
45
|
+
|
|
46
|
+
Set up your environment variables for Auth0:
|
|
47
|
+
|
|
48
|
+
```
|
|
49
|
+
AUTH0_DOMAIN=your-tenant.us.auth0.com
|
|
50
|
+
AUTH0_CLIENT_ID=your_client_id
|
|
51
|
+
AUTH0_CLIENT_SECRET=your_client_secret
|
|
52
|
+
AUTH0_MANAGEMENT_API_TOKEN=your_management_api_token
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
## Installation and Setup
|
|
56
|
+
|
|
57
|
+
Install the Auth0 SDK:
|
|
58
|
+
|
|
59
|
+
```bash
|
|
60
|
+
npm install auth0
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
For TypeScript projects, types are included in the package.
|
|
64
|
+
|
|
65
|
+
## Initialization
|
|
66
|
+
|
|
67
|
+
### ManagementClient Initialization
|
|
68
|
+
|
|
69
|
+
The ManagementClient is used for administrative operations like user management, role assignment, and configuration.
|
|
70
|
+
|
|
71
|
+
**Basic initialization with API token:**
|
|
72
|
+
|
|
73
|
+
```javascript
|
|
74
|
+
import { ManagementClient } from 'auth0';
|
|
75
|
+
|
|
76
|
+
const management = new ManagementClient({
|
|
77
|
+
domain: process.env.AUTH0_DOMAIN,
|
|
78
|
+
token: process.env.AUTH0_MANAGEMENT_API_TOKEN,
|
|
79
|
+
});
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
**Initialization with client credentials:**
|
|
83
|
+
|
|
84
|
+
```javascript
|
|
85
|
+
import { ManagementClient } from 'auth0';
|
|
86
|
+
|
|
87
|
+
const management = new ManagementClient({
|
|
88
|
+
domain: process.env.AUTH0_DOMAIN,
|
|
89
|
+
clientId: process.env.AUTH0_CLIENT_ID,
|
|
90
|
+
clientSecret: process.env.AUTH0_CLIENT_SECRET,
|
|
91
|
+
});
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
**Advanced configuration:**
|
|
95
|
+
|
|
96
|
+
```javascript
|
|
97
|
+
import { ManagementClient } from 'auth0';
|
|
98
|
+
|
|
99
|
+
const management = new ManagementClient({
|
|
100
|
+
domain: process.env.AUTH0_DOMAIN,
|
|
101
|
+
clientId: process.env.AUTH0_CLIENT_ID,
|
|
102
|
+
clientSecret: process.env.AUTH0_CLIENT_SECRET,
|
|
103
|
+
timeout: 60000, // 60 seconds
|
|
104
|
+
retry: {
|
|
105
|
+
enabled: true,
|
|
106
|
+
maxRetries: 2,
|
|
107
|
+
},
|
|
108
|
+
});
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
### AuthenticationClient Initialization
|
|
112
|
+
|
|
113
|
+
The AuthenticationClient handles user authentication operations like login, password reset, and token management.
|
|
114
|
+
|
|
115
|
+
**Basic initialization:**
|
|
116
|
+
|
|
117
|
+
```javascript
|
|
118
|
+
import { AuthenticationClient } from 'auth0';
|
|
119
|
+
|
|
120
|
+
const auth0 = new AuthenticationClient({
|
|
121
|
+
domain: process.env.AUTH0_DOMAIN,
|
|
122
|
+
clientId: process.env.AUTH0_CLIENT_ID,
|
|
123
|
+
});
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
**With client secret (for confidential clients):**
|
|
127
|
+
|
|
128
|
+
```javascript
|
|
129
|
+
import { AuthenticationClient } from 'auth0';
|
|
130
|
+
|
|
131
|
+
const auth0 = new AuthenticationClient({
|
|
132
|
+
domain: process.env.AUTH0_DOMAIN,
|
|
133
|
+
clientId: process.env.AUTH0_CLIENT_ID,
|
|
134
|
+
clientSecret: process.env.AUTH0_CLIENT_SECRET,
|
|
135
|
+
});
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
### UserInfoClient Initialization
|
|
139
|
+
|
|
140
|
+
For retrieving user profile information using access tokens:
|
|
141
|
+
|
|
142
|
+
```javascript
|
|
143
|
+
import { UserInfoClient } from 'auth0';
|
|
144
|
+
|
|
145
|
+
const userInfo = new UserInfoClient({
|
|
146
|
+
domain: process.env.AUTH0_DOMAIN,
|
|
147
|
+
});
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
## User Management
|
|
151
|
+
|
|
152
|
+
### Creating Users
|
|
153
|
+
|
|
154
|
+
```javascript
|
|
155
|
+
import { ManagementClient } from 'auth0';
|
|
156
|
+
|
|
157
|
+
const management = new ManagementClient({
|
|
158
|
+
domain: process.env.AUTH0_DOMAIN,
|
|
159
|
+
clientId: process.env.AUTH0_CLIENT_ID,
|
|
160
|
+
clientSecret: process.env.AUTH0_CLIENT_SECRET,
|
|
161
|
+
});
|
|
162
|
+
|
|
163
|
+
async function createUser() {
|
|
164
|
+
const newUser = await management.users.create({
|
|
165
|
+
email: 'user@example.com',
|
|
166
|
+
password: 'SecurePassword123!',
|
|
167
|
+
connection: 'Username-Password-Authentication',
|
|
168
|
+
email_verified: false,
|
|
169
|
+
user_metadata: {
|
|
170
|
+
plan: 'premium',
|
|
171
|
+
preferences: { theme: 'dark' },
|
|
172
|
+
},
|
|
173
|
+
app_metadata: {
|
|
174
|
+
role: 'user',
|
|
175
|
+
},
|
|
176
|
+
});
|
|
177
|
+
|
|
178
|
+
console.log('User created:', newUser.user_id);
|
|
179
|
+
return newUser;
|
|
180
|
+
}
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
### Getting User by ID
|
|
184
|
+
|
|
185
|
+
```javascript
|
|
186
|
+
async function getUser(userId) {
|
|
187
|
+
const user = await management.users.get({ id: userId });
|
|
188
|
+
console.log('User:', user);
|
|
189
|
+
return user;
|
|
190
|
+
}
|
|
191
|
+
```
|
|
192
|
+
|
|
193
|
+
### Getting User by Email
|
|
194
|
+
|
|
195
|
+
```javascript
|
|
196
|
+
async function getUserByEmail(email) {
|
|
197
|
+
const users = await management.usersByEmail.get({ email });
|
|
198
|
+
|
|
199
|
+
if (users.length > 0) {
|
|
200
|
+
console.log('User found:', users[0]);
|
|
201
|
+
return users[0];
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
return null;
|
|
205
|
+
}
|
|
206
|
+
```
|
|
207
|
+
|
|
208
|
+
### Updating User
|
|
209
|
+
|
|
210
|
+
```javascript
|
|
211
|
+
async function updateUser(userId, updates) {
|
|
212
|
+
const updatedUser = await management.users.update(
|
|
213
|
+
{ id: userId },
|
|
214
|
+
{
|
|
215
|
+
email: 'newemail@example.com',
|
|
216
|
+
user_metadata: {
|
|
217
|
+
plan: 'enterprise',
|
|
218
|
+
},
|
|
219
|
+
}
|
|
220
|
+
);
|
|
221
|
+
|
|
222
|
+
return updatedUser;
|
|
223
|
+
}
|
|
224
|
+
```
|
|
225
|
+
|
|
226
|
+
### Deleting User
|
|
227
|
+
|
|
228
|
+
```javascript
|
|
229
|
+
async function deleteUser(userId) {
|
|
230
|
+
await management.users.delete({ id: userId });
|
|
231
|
+
console.log('User deleted');
|
|
232
|
+
}
|
|
233
|
+
```
|
|
234
|
+
|
|
235
|
+
### Listing Users
|
|
236
|
+
|
|
237
|
+
```javascript
|
|
238
|
+
async function listUsers() {
|
|
239
|
+
const users = await management.users.getAll({
|
|
240
|
+
per_page: 50,
|
|
241
|
+
page: 0,
|
|
242
|
+
});
|
|
243
|
+
|
|
244
|
+
return users;
|
|
245
|
+
}
|
|
246
|
+
```
|
|
247
|
+
|
|
248
|
+
### Searching Users
|
|
249
|
+
|
|
250
|
+
```javascript
|
|
251
|
+
async function searchUsers(query) {
|
|
252
|
+
const users = await management.users.getAll({
|
|
253
|
+
q: `email:"*@example.com"`,
|
|
254
|
+
search_engine: 'v3',
|
|
255
|
+
});
|
|
256
|
+
|
|
257
|
+
return users;
|
|
258
|
+
}
|
|
259
|
+
```
|
|
260
|
+
|
|
261
|
+
## Authentication Operations
|
|
262
|
+
|
|
263
|
+
### Password Grant (Direct Login)
|
|
264
|
+
|
|
265
|
+
```javascript
|
|
266
|
+
import { AuthenticationClient } from 'auth0';
|
|
267
|
+
|
|
268
|
+
const auth0 = new AuthenticationClient({
|
|
269
|
+
domain: process.env.AUTH0_DOMAIN,
|
|
270
|
+
clientId: process.env.AUTH0_CLIENT_ID,
|
|
271
|
+
clientSecret: process.env.AUTH0_CLIENT_SECRET,
|
|
272
|
+
});
|
|
273
|
+
|
|
274
|
+
async function login(username, password) {
|
|
275
|
+
const response = await auth0.oauth.passwordGrant({
|
|
276
|
+
username,
|
|
277
|
+
password,
|
|
278
|
+
audience: 'https://api.example.com',
|
|
279
|
+
scope: 'openid profile email',
|
|
280
|
+
});
|
|
281
|
+
|
|
282
|
+
console.log('Access Token:', response.access_token);
|
|
283
|
+
console.log('ID Token:', response.id_token);
|
|
284
|
+
return response;
|
|
285
|
+
}
|
|
286
|
+
```
|
|
287
|
+
|
|
288
|
+
### Client Credentials Grant
|
|
289
|
+
|
|
290
|
+
```javascript
|
|
291
|
+
async function getClientCredentialsToken() {
|
|
292
|
+
const response = await auth0.oauth.clientCredentialsGrant({
|
|
293
|
+
audience: 'https://api.example.com',
|
|
294
|
+
});
|
|
295
|
+
|
|
296
|
+
console.log('Access Token:', response.access_token);
|
|
297
|
+
return response;
|
|
298
|
+
}
|
|
299
|
+
```
|
|
300
|
+
|
|
301
|
+
### Refresh Token
|
|
302
|
+
|
|
303
|
+
```javascript
|
|
304
|
+
async function refreshToken(refreshToken) {
|
|
305
|
+
const response = await auth0.oauth.refreshTokenGrant({
|
|
306
|
+
refresh_token: refreshToken,
|
|
307
|
+
});
|
|
308
|
+
|
|
309
|
+
console.log('New Access Token:', response.access_token);
|
|
310
|
+
return response;
|
|
311
|
+
}
|
|
312
|
+
```
|
|
313
|
+
|
|
314
|
+
### Password Reset
|
|
315
|
+
|
|
316
|
+
```javascript
|
|
317
|
+
async function requestPasswordReset(email) {
|
|
318
|
+
await auth0.database.changePassword({
|
|
319
|
+
email,
|
|
320
|
+
connection: 'Username-Password-Authentication',
|
|
321
|
+
});
|
|
322
|
+
|
|
323
|
+
console.log('Password reset email sent');
|
|
324
|
+
}
|
|
325
|
+
```
|
|
326
|
+
|
|
327
|
+
### User Signup
|
|
328
|
+
|
|
329
|
+
```javascript
|
|
330
|
+
async function signup(email, password) {
|
|
331
|
+
const user = await auth0.database.signUp({
|
|
332
|
+
email,
|
|
333
|
+
password,
|
|
334
|
+
connection: 'Username-Password-Authentication',
|
|
335
|
+
});
|
|
336
|
+
|
|
337
|
+
return user;
|
|
338
|
+
}
|
|
339
|
+
```
|
|
340
|
+
|
|
341
|
+
## Token Operations
|
|
342
|
+
|
|
343
|
+
### Getting User Info from Access Token
|
|
344
|
+
|
|
345
|
+
```javascript
|
|
346
|
+
import { UserInfoClient } from 'auth0';
|
|
347
|
+
|
|
348
|
+
const userInfo = new UserInfoClient({
|
|
349
|
+
domain: process.env.AUTH0_DOMAIN,
|
|
350
|
+
});
|
|
351
|
+
|
|
352
|
+
async function getUserProfile(accessToken) {
|
|
353
|
+
const profile = await userInfo.getUserInfo(accessToken);
|
|
354
|
+
|
|
355
|
+
console.log('User Profile:', profile);
|
|
356
|
+
return profile;
|
|
357
|
+
}
|
|
358
|
+
```
|
|
359
|
+
|
|
360
|
+
### Revoking Refresh Token
|
|
361
|
+
|
|
362
|
+
```javascript
|
|
363
|
+
async function revokeToken(token) {
|
|
364
|
+
await auth0.oauth.revokeRefreshToken({
|
|
365
|
+
token,
|
|
366
|
+
});
|
|
367
|
+
|
|
368
|
+
console.log('Token revoked');
|
|
369
|
+
}
|
|
370
|
+
```
|
|
371
|
+
|
|
372
|
+
## Role and Permission Management
|
|
373
|
+
|
|
374
|
+
### Assigning Roles to User
|
|
375
|
+
|
|
376
|
+
```javascript
|
|
377
|
+
async function assignRolesToUser(userId, roleIds) {
|
|
378
|
+
await management.users.assignRoles(
|
|
379
|
+
{ id: userId },
|
|
380
|
+
{ roles: roleIds }
|
|
381
|
+
);
|
|
382
|
+
|
|
383
|
+
console.log('Roles assigned');
|
|
384
|
+
}
|
|
385
|
+
```
|
|
386
|
+
|
|
387
|
+
### Getting User Roles
|
|
388
|
+
|
|
389
|
+
```javascript
|
|
390
|
+
async function getUserRoles(userId) {
|
|
391
|
+
const roles = await management.users.getRoles({ id: userId });
|
|
392
|
+
|
|
393
|
+
console.log('User Roles:', roles);
|
|
394
|
+
return roles;
|
|
395
|
+
}
|
|
396
|
+
```
|
|
397
|
+
|
|
398
|
+
### Removing Roles from User
|
|
399
|
+
|
|
400
|
+
```javascript
|
|
401
|
+
async function removeRolesFromUser(userId, roleIds) {
|
|
402
|
+
await management.users.removeRoles(
|
|
403
|
+
{ id: userId },
|
|
404
|
+
{ roles: roleIds }
|
|
405
|
+
);
|
|
406
|
+
|
|
407
|
+
console.log('Roles removed');
|
|
408
|
+
}
|
|
409
|
+
```
|
|
410
|
+
|
|
411
|
+
### Getting User Permissions
|
|
412
|
+
|
|
413
|
+
```javascript
|
|
414
|
+
async function getUserPermissions(userId) {
|
|
415
|
+
const permissions = await management.users.getPermissions({ id: userId });
|
|
416
|
+
|
|
417
|
+
console.log('User Permissions:', permissions);
|
|
418
|
+
return permissions;
|
|
419
|
+
}
|
|
420
|
+
```
|
|
421
|
+
|
|
422
|
+
### Assigning Permissions to User
|
|
423
|
+
|
|
424
|
+
```javascript
|
|
425
|
+
async function assignPermissionsToUser(userId, permissions) {
|
|
426
|
+
await management.users.assignPermissions(
|
|
427
|
+
{ id: userId },
|
|
428
|
+
{
|
|
429
|
+
permissions: [
|
|
430
|
+
{ permission_name: 'read:messages', resource_server_identifier: 'https://api.example.com' },
|
|
431
|
+
{ permission_name: 'write:messages', resource_server_identifier: 'https://api.example.com' },
|
|
432
|
+
]
|
|
433
|
+
}
|
|
434
|
+
);
|
|
435
|
+
|
|
436
|
+
console.log('Permissions assigned');
|
|
437
|
+
}
|
|
438
|
+
```
|
|
439
|
+
|
|
440
|
+
## Organization Management
|
|
441
|
+
|
|
442
|
+
### Creating an Organization
|
|
443
|
+
|
|
444
|
+
```javascript
|
|
445
|
+
async function createOrganization(name, displayName) {
|
|
446
|
+
const org = await management.organizations.create({
|
|
447
|
+
name,
|
|
448
|
+
display_name: displayName,
|
|
449
|
+
});
|
|
450
|
+
|
|
451
|
+
return org;
|
|
452
|
+
}
|
|
453
|
+
```
|
|
454
|
+
|
|
455
|
+
### Adding Members to Organization
|
|
456
|
+
|
|
457
|
+
```javascript
|
|
458
|
+
async function addMemberToOrganization(orgId, userId) {
|
|
459
|
+
await management.organizations.addMembers(
|
|
460
|
+
{ id: orgId },
|
|
461
|
+
{ members: [userId] }
|
|
462
|
+
);
|
|
463
|
+
|
|
464
|
+
console.log('Member added to organization');
|
|
465
|
+
}
|
|
466
|
+
```
|
|
467
|
+
|
|
468
|
+
### Getting Organization Members
|
|
469
|
+
|
|
470
|
+
```javascript
|
|
471
|
+
async function getOrganizationMembers(orgId) {
|
|
472
|
+
const members = await management.organizations.getMembers({ id: orgId });
|
|
473
|
+
|
|
474
|
+
return members;
|
|
475
|
+
}
|
|
476
|
+
```
|
|
477
|
+
|
|
478
|
+
### Assigning Roles to Organization Member
|
|
479
|
+
|
|
480
|
+
```javascript
|
|
481
|
+
async function assignOrgRoles(orgId, userId, roleIds) {
|
|
482
|
+
await management.organizations.addMemberRoles(
|
|
483
|
+
{ id: orgId, user_id: userId },
|
|
484
|
+
{ roles: roleIds }
|
|
485
|
+
);
|
|
486
|
+
|
|
487
|
+
console.log('Organization roles assigned');
|
|
488
|
+
}
|
|
489
|
+
```
|
|
490
|
+
|
|
491
|
+
## Client Application Management
|
|
492
|
+
|
|
493
|
+
### Getting All Clients
|
|
494
|
+
|
|
495
|
+
```javascript
|
|
496
|
+
async function getAllClients() {
|
|
497
|
+
const clients = await management.clients.getAll();
|
|
498
|
+
|
|
499
|
+
return clients;
|
|
500
|
+
}
|
|
501
|
+
```
|
|
502
|
+
|
|
503
|
+
### Creating a Client
|
|
504
|
+
|
|
505
|
+
```javascript
|
|
506
|
+
async function createClient(name, type) {
|
|
507
|
+
const client = await management.clients.create({
|
|
508
|
+
name,
|
|
509
|
+
app_type: type, // 'native', 'spa', 'regular_web', 'non_interactive'
|
|
510
|
+
callbacks: ['http://localhost:3000/callback'],
|
|
511
|
+
allowed_logout_urls: ['http://localhost:3000'],
|
|
512
|
+
});
|
|
513
|
+
|
|
514
|
+
return client;
|
|
515
|
+
}
|
|
516
|
+
```
|
|
517
|
+
|
|
518
|
+
### Updating a Client
|
|
519
|
+
|
|
520
|
+
```javascript
|
|
521
|
+
async function updateClient(clientId, updates) {
|
|
522
|
+
const client = await management.clients.update(
|
|
523
|
+
{ client_id: clientId },
|
|
524
|
+
updates
|
|
525
|
+
);
|
|
526
|
+
|
|
527
|
+
return client;
|
|
528
|
+
}
|
|
529
|
+
```
|
|
530
|
+
|
|
531
|
+
## Connection Management
|
|
532
|
+
|
|
533
|
+
### Getting All Connections
|
|
534
|
+
|
|
535
|
+
```javascript
|
|
536
|
+
async function getAllConnections() {
|
|
537
|
+
const connections = await management.connections.getAll();
|
|
538
|
+
|
|
539
|
+
return connections;
|
|
540
|
+
}
|
|
541
|
+
```
|
|
542
|
+
|
|
543
|
+
### Creating a Database Connection
|
|
544
|
+
|
|
545
|
+
```javascript
|
|
546
|
+
async function createDatabaseConnection(name) {
|
|
547
|
+
const connection = await management.connections.create({
|
|
548
|
+
name,
|
|
549
|
+
strategy: 'auth0',
|
|
550
|
+
enabled_clients: [process.env.AUTH0_CLIENT_ID],
|
|
551
|
+
});
|
|
552
|
+
|
|
553
|
+
return connection;
|
|
554
|
+
}
|
|
555
|
+
```
|
|
556
|
+
|
|
557
|
+
### Getting Connection by ID
|
|
558
|
+
|
|
559
|
+
```javascript
|
|
560
|
+
async function getConnection(connectionId) {
|
|
561
|
+
const connection = await management.connections.get({ id: connectionId });
|
|
562
|
+
|
|
563
|
+
return connection;
|
|
564
|
+
}
|
|
565
|
+
```
|
|
566
|
+
|
|
567
|
+
## Email Templates and Verification
|
|
568
|
+
|
|
569
|
+
### Sending Email Verification
|
|
570
|
+
|
|
571
|
+
```javascript
|
|
572
|
+
async function sendVerificationEmail(userId) {
|
|
573
|
+
await management.jobs.verifyEmail({
|
|
574
|
+
user_id: userId,
|
|
575
|
+
});
|
|
576
|
+
|
|
577
|
+
console.log('Verification email sent');
|
|
578
|
+
}
|
|
579
|
+
```
|
|
580
|
+
|
|
581
|
+
### Creating Email Verification Ticket
|
|
582
|
+
|
|
583
|
+
```javascript
|
|
584
|
+
async function createEmailVerificationTicket(userId) {
|
|
585
|
+
const ticket = await management.tickets.verifyEmail({
|
|
586
|
+
user_id: userId,
|
|
587
|
+
result_url: 'https://example.com/verified',
|
|
588
|
+
});
|
|
589
|
+
|
|
590
|
+
console.log('Verification URL:', ticket.ticket);
|
|
591
|
+
return ticket;
|
|
592
|
+
}
|
|
593
|
+
```
|
|
594
|
+
|
|
595
|
+
### Creating Password Change Ticket
|
|
596
|
+
|
|
597
|
+
```javascript
|
|
598
|
+
async function createPasswordChangeTicket(userId) {
|
|
599
|
+
const ticket = await management.tickets.changePassword({
|
|
600
|
+
user_id: userId,
|
|
601
|
+
result_url: 'https://example.com/password-changed',
|
|
602
|
+
});
|
|
603
|
+
|
|
604
|
+
console.log('Password change URL:', ticket.ticket);
|
|
605
|
+
return ticket;
|
|
606
|
+
}
|
|
607
|
+
```
|
|
608
|
+
|
|
609
|
+
## Pagination
|
|
610
|
+
|
|
611
|
+
### Manual Pagination
|
|
612
|
+
|
|
613
|
+
```javascript
|
|
614
|
+
async function getAllUsersPaginated() {
|
|
615
|
+
let page = 0;
|
|
616
|
+
const perPage = 50;
|
|
617
|
+
let allUsers = [];
|
|
618
|
+
let hasMore = true;
|
|
619
|
+
|
|
620
|
+
while (hasMore) {
|
|
621
|
+
const users = await management.users.getAll({
|
|
622
|
+
page,
|
|
623
|
+
per_page: perPage,
|
|
624
|
+
});
|
|
625
|
+
|
|
626
|
+
allUsers = allUsers.concat(users);
|
|
627
|
+
hasMore = users.length === perPage;
|
|
628
|
+
page++;
|
|
629
|
+
}
|
|
630
|
+
|
|
631
|
+
return allUsers;
|
|
632
|
+
}
|
|
633
|
+
```
|
|
634
|
+
|
|
635
|
+
### Using Pagination Iterator
|
|
636
|
+
|
|
637
|
+
```javascript
|
|
638
|
+
async function iterateAllUsers() {
|
|
639
|
+
const users = [];
|
|
640
|
+
|
|
641
|
+
for await (const user of management.users.getAll()) {
|
|
642
|
+
users.push(user);
|
|
643
|
+
}
|
|
644
|
+
|
|
645
|
+
return users;
|
|
646
|
+
}
|
|
647
|
+
```
|
|
648
|
+
|
|
649
|
+
## Error Handling
|
|
650
|
+
|
|
651
|
+
The SDK provides comprehensive error handling with ManagementError and AuthenticationError types.
|
|
652
|
+
|
|
653
|
+
```javascript
|
|
654
|
+
import { ManagementClient, ManagementError } from 'auth0';
|
|
655
|
+
|
|
656
|
+
const management = new ManagementClient({
|
|
657
|
+
domain: process.env.AUTH0_DOMAIN,
|
|
658
|
+
clientId: process.env.AUTH0_CLIENT_ID,
|
|
659
|
+
clientSecret: process.env.AUTH0_CLIENT_SECRET,
|
|
660
|
+
});
|
|
661
|
+
|
|
662
|
+
async function handleErrors() {
|
|
663
|
+
try {
|
|
664
|
+
const user = await management.users.get({ id: 'invalid-id' });
|
|
665
|
+
} catch (err) {
|
|
666
|
+
if (err instanceof ManagementError) {
|
|
667
|
+
console.log('Status Code:', err.statusCode); // 404
|
|
668
|
+
console.log('Error Message:', err.message);
|
|
669
|
+
console.log('Error Body:', err.body);
|
|
670
|
+
console.log('Raw Response:', err.rawResponse);
|
|
671
|
+
} else {
|
|
672
|
+
throw err;
|
|
673
|
+
}
|
|
674
|
+
}
|
|
675
|
+
}
|
|
676
|
+
```
|
|
677
|
+
|
|
678
|
+
### Common Error Status Codes
|
|
679
|
+
|
|
680
|
+
| Status Code | Error Type | Description |
|
|
681
|
+
|-------------|------------|-------------|
|
|
682
|
+
| 400 | Bad Request | Invalid request parameters |
|
|
683
|
+
| 401 | Unauthorized | Invalid or missing credentials |
|
|
684
|
+
| 403 | Forbidden | Insufficient permissions |
|
|
685
|
+
| 404 | Not Found | Resource not found |
|
|
686
|
+
| 409 | Conflict | Resource already exists |
|
|
687
|
+
| 429 | Too Many Requests | Rate limit exceeded |
|
|
688
|
+
| 500 | Internal Server Error | Server error |
|
|
689
|
+
|
|
690
|
+
## Advanced Configuration
|
|
691
|
+
|
|
692
|
+
### Custom Timeout
|
|
693
|
+
|
|
694
|
+
```javascript
|
|
695
|
+
const management = new ManagementClient({
|
|
696
|
+
domain: process.env.AUTH0_DOMAIN,
|
|
697
|
+
token: process.env.AUTH0_MANAGEMENT_API_TOKEN,
|
|
698
|
+
timeout: 30000, // 30 seconds
|
|
699
|
+
});
|
|
700
|
+
```
|
|
701
|
+
|
|
702
|
+
### Retry Configuration
|
|
703
|
+
|
|
704
|
+
```javascript
|
|
705
|
+
const management = new ManagementClient({
|
|
706
|
+
domain: process.env.AUTH0_DOMAIN,
|
|
707
|
+
token: process.env.AUTH0_MANAGEMENT_API_TOKEN,
|
|
708
|
+
retry: {
|
|
709
|
+
enabled: true,
|
|
710
|
+
maxRetries: 3,
|
|
711
|
+
},
|
|
712
|
+
});
|
|
713
|
+
```
|
|
714
|
+
|
|
715
|
+
### Custom Headers
|
|
716
|
+
|
|
717
|
+
```javascript
|
|
718
|
+
async function makeRequestWithCustomHeaders() {
|
|
719
|
+
const users = await management.users.getAll({}, {
|
|
720
|
+
headers: {
|
|
721
|
+
'X-Custom-Header': 'custom-value',
|
|
722
|
+
},
|
|
723
|
+
});
|
|
724
|
+
|
|
725
|
+
return users;
|
|
726
|
+
}
|
|
727
|
+
```
|
|
728
|
+
|
|
729
|
+
### Abort Signal (Request Cancellation)
|
|
730
|
+
|
|
731
|
+
```javascript
|
|
732
|
+
async function cancelableRequest() {
|
|
733
|
+
const controller = new AbortController();
|
|
734
|
+
|
|
735
|
+
// Cancel after 5 seconds
|
|
736
|
+
setTimeout(() => controller.abort(), 5000);
|
|
737
|
+
|
|
738
|
+
try {
|
|
739
|
+
const users = await management.users.getAll({}, {
|
|
740
|
+
signal: controller.signal,
|
|
741
|
+
});
|
|
742
|
+
|
|
743
|
+
return users;
|
|
744
|
+
} catch (err) {
|
|
745
|
+
if (err.name === 'AbortError') {
|
|
746
|
+
console.log('Request was cancelled');
|
|
747
|
+
}
|
|
748
|
+
throw err;
|
|
749
|
+
}
|
|
750
|
+
}
|
|
751
|
+
```
|
|
752
|
+
|
|
753
|
+
## Logs and Monitoring
|
|
754
|
+
|
|
755
|
+
### Getting Logs
|
|
756
|
+
|
|
757
|
+
```javascript
|
|
758
|
+
async function getLogs() {
|
|
759
|
+
const logs = await management.logs.getAll({
|
|
760
|
+
per_page: 100,
|
|
761
|
+
page: 0,
|
|
762
|
+
});
|
|
763
|
+
|
|
764
|
+
return logs;
|
|
765
|
+
}
|
|
766
|
+
```
|
|
767
|
+
|
|
768
|
+
### Filtering Logs by Type
|
|
769
|
+
|
|
770
|
+
```javascript
|
|
771
|
+
async function getLoginLogs() {
|
|
772
|
+
const logs = await management.logs.getAll({
|
|
773
|
+
q: 'type:s', // 's' = successful login
|
|
774
|
+
per_page: 100,
|
|
775
|
+
});
|
|
776
|
+
|
|
777
|
+
return logs;
|
|
778
|
+
}
|
|
779
|
+
```
|
|
780
|
+
|
|
781
|
+
### Getting Log by ID
|
|
782
|
+
|
|
783
|
+
```javascript
|
|
784
|
+
async function getLogById(logId) {
|
|
785
|
+
const log = await management.logs.get({ id: logId });
|
|
786
|
+
|
|
787
|
+
return log;
|
|
788
|
+
}
|
|
789
|
+
```
|
|
790
|
+
|
|
791
|
+
## Guardian (MFA) Management
|
|
792
|
+
|
|
793
|
+
### Getting Guardian Enrollments
|
|
794
|
+
|
|
795
|
+
```javascript
|
|
796
|
+
async function getUserMFAEnrollments(userId) {
|
|
797
|
+
const enrollments = await management.users.getGuardianEnrollments({ id: userId });
|
|
798
|
+
|
|
799
|
+
return enrollments;
|
|
800
|
+
}
|
|
801
|
+
```
|
|
802
|
+
|
|
803
|
+
### Deleting Guardian Enrollment
|
|
804
|
+
|
|
805
|
+
```javascript
|
|
806
|
+
async function deleteMFAEnrollment(userId, enrollmentId) {
|
|
807
|
+
await management.guardian.deleteEnrollment({ id: enrollmentId });
|
|
808
|
+
|
|
809
|
+
console.log('MFA enrollment deleted');
|
|
810
|
+
}
|
|
811
|
+
```
|
|
812
|
+
|
|
813
|
+
## Runtime Compatibility
|
|
814
|
+
|
|
815
|
+
The Auth0 Node.js SDK v5 is compatible with:
|
|
816
|
+
|
|
817
|
+
- Node.js 20.19.0+
|
|
818
|
+
- Node.js 22.12.0+
|
|
819
|
+
- Node.js 24.0.0+
|
|
820
|
+
- Vercel Edge Functions
|
|
821
|
+
- Cloudflare Workers
|
|
822
|
+
- Deno
|
|
823
|
+
- Bun
|
|
824
|
+
- React Native
|
|
825
|
+
|
|
826
|
+
## Legacy Support
|
|
827
|
+
|
|
828
|
+
If you're migrating from v4.x, use the legacy exports:
|
|
829
|
+
|
|
830
|
+
```javascript
|
|
831
|
+
import { ManagementClient } from 'auth0/legacy';
|
|
832
|
+
|
|
833
|
+
// Old v4.x configuration format
|
|
834
|
+
const management = new ManagementClient({
|
|
835
|
+
domain: 'tenant.auth0.com',
|
|
836
|
+
clientId: 'CLIENT_ID',
|
|
837
|
+
clientSecret: 'CLIENT_SECRET',
|
|
838
|
+
});
|
|
839
|
+
```
|
|
840
|
+
|
|
841
|
+
## Complete Example: User Registration and Login Flow
|
|
842
|
+
|
|
843
|
+
```javascript
|
|
844
|
+
import { ManagementClient, AuthenticationClient } from 'auth0';
|
|
845
|
+
|
|
846
|
+
const management = new ManagementClient({
|
|
847
|
+
domain: process.env.AUTH0_DOMAIN,
|
|
848
|
+
clientId: process.env.AUTH0_CLIENT_ID,
|
|
849
|
+
clientSecret: process.env.AUTH0_CLIENT_SECRET,
|
|
850
|
+
});
|
|
851
|
+
|
|
852
|
+
const auth0 = new AuthenticationClient({
|
|
853
|
+
domain: process.env.AUTH0_DOMAIN,
|
|
854
|
+
clientId: process.env.AUTH0_CLIENT_ID,
|
|
855
|
+
clientSecret: process.env.AUTH0_CLIENT_SECRET,
|
|
856
|
+
});
|
|
857
|
+
|
|
858
|
+
async function registerAndLogin() {
|
|
859
|
+
// 1. Create a new user
|
|
860
|
+
const newUser = await management.users.create({
|
|
861
|
+
email: 'john.doe@example.com',
|
|
862
|
+
password: 'SecurePassword123!',
|
|
863
|
+
connection: 'Username-Password-Authentication',
|
|
864
|
+
user_metadata: {
|
|
865
|
+
firstName: 'John',
|
|
866
|
+
lastName: 'Doe',
|
|
867
|
+
},
|
|
868
|
+
});
|
|
869
|
+
|
|
870
|
+
console.log('User created:', newUser.user_id);
|
|
871
|
+
|
|
872
|
+
// 2. Send verification email
|
|
873
|
+
await management.jobs.verifyEmail({
|
|
874
|
+
user_id: newUser.user_id,
|
|
875
|
+
});
|
|
876
|
+
|
|
877
|
+
console.log('Verification email sent');
|
|
878
|
+
|
|
879
|
+
// 3. Login user (after email verification)
|
|
880
|
+
const loginResponse = await auth0.oauth.passwordGrant({
|
|
881
|
+
username: 'john.doe@example.com',
|
|
882
|
+
password: 'SecurePassword123!',
|
|
883
|
+
audience: 'https://api.example.com',
|
|
884
|
+
scope: 'openid profile email',
|
|
885
|
+
});
|
|
886
|
+
|
|
887
|
+
console.log('Access Token:', loginResponse.access_token);
|
|
888
|
+
|
|
889
|
+
// 4. Get user profile
|
|
890
|
+
const userInfo = new UserInfoClient({
|
|
891
|
+
domain: process.env.AUTH0_DOMAIN,
|
|
892
|
+
});
|
|
893
|
+
|
|
894
|
+
const profile = await userInfo.getUserInfo(loginResponse.access_token);
|
|
895
|
+
console.log('User Profile:', profile);
|
|
896
|
+
|
|
897
|
+
return {
|
|
898
|
+
user: newUser,
|
|
899
|
+
tokens: loginResponse,
|
|
900
|
+
profile,
|
|
901
|
+
};
|
|
902
|
+
}
|
|
903
|
+
```
|
|
904
|
+
|
|
905
|
+
## Important Notes
|
|
906
|
+
|
|
907
|
+
### Security Best Practices
|
|
908
|
+
|
|
909
|
+
1. **Never expose client secrets** - Keep client secrets secure on the server side only
|
|
910
|
+
2. **Use environment variables** - Store credentials in environment variables, not in code
|
|
911
|
+
3. **Validate tokens** - Always validate tokens on the server side
|
|
912
|
+
4. **Use HTTPS** - Always use HTTPS in production
|
|
913
|
+
5. **Implement rate limiting** - Protect against brute force attacks
|
|
914
|
+
6. **Rotate credentials** - Regularly rotate API tokens and client secrets
|
|
915
|
+
|
|
916
|
+
### Management API Token
|
|
917
|
+
|
|
918
|
+
- Management API tokens expire after 24 hours
|
|
919
|
+
- Use client credentials grant for long-running applications
|
|
920
|
+
- Cache tokens and refresh before expiration
|
|
921
|
+
|
|
922
|
+
### Rate Limits
|
|
923
|
+
|
|
924
|
+
Auth0 enforces rate limits on API requests. Handle 429 errors gracefully:
|
|
925
|
+
|
|
926
|
+
```javascript
|
|
927
|
+
async function retryWithBackoff(fn, maxRetries = 3) {
|
|
928
|
+
for (let i = 0; i < maxRetries; i++) {
|
|
929
|
+
try {
|
|
930
|
+
return await fn();
|
|
931
|
+
} catch (err) {
|
|
932
|
+
if (err.statusCode === 429 && i < maxRetries - 1) {
|
|
933
|
+
const waitTime = Math.pow(2, i) * 1000;
|
|
934
|
+
await new Promise(resolve => setTimeout(resolve, waitTime));
|
|
935
|
+
continue;
|
|
936
|
+
}
|
|
937
|
+
throw err;
|
|
938
|
+
}
|
|
939
|
+
}
|
|
940
|
+
}
|
|
941
|
+
```
|
|
942
|
+
|
|
943
|
+
### User Search Syntax
|
|
944
|
+
|
|
945
|
+
Use Lucene query syntax for user searches:
|
|
946
|
+
|
|
947
|
+
```javascript
|
|
948
|
+
// Search by email domain
|
|
949
|
+
q: 'email:"*@example.com"'
|
|
950
|
+
|
|
951
|
+
// Search by metadata
|
|
952
|
+
q: 'user_metadata.plan:"premium"'
|
|
953
|
+
|
|
954
|
+
// Search by multiple fields
|
|
955
|
+
q: 'email:"*@example.com" AND user_metadata.plan:"premium"'
|
|
956
|
+
|
|
957
|
+
// Search by created date
|
|
958
|
+
q: 'created_at:[2024-01-01 TO 2024-12-31]'
|
|
959
|
+
```
|
|
960
|
+
|
|
961
|
+
## Useful Links
|
|
962
|
+
|
|
963
|
+
- Official Documentation: https://auth0.com/docs
|
|
964
|
+
- SDK Reference: https://auth0.github.io/node-auth0/
|
|
965
|
+
- GitHub Repository: https://github.com/auth0/node-auth0
|
|
966
|
+
- Community Forum: https://community.auth0.com/
|
|
967
|
+
- Auth0 Dashboard: https://manage.auth0.com/
|
|
968
|
+
- API Rate Limits: https://auth0.com/docs/troubleshoot/customer-support/operational-policies/rate-limit-policy
|