@auth-gate/core 0.14.0 → 0.15.1
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/dist/index.cjs +1387 -1275
- package/dist/index.d.cts +662 -632
- package/dist/index.d.ts +662 -632
- package/dist/index.mjs +1364 -1255
- package/package.json +3 -3
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
//#region src/types.d.ts
|
|
1
2
|
/**
|
|
2
3
|
* The authenticated user object returned after successful authentication.
|
|
3
4
|
*
|
|
@@ -9,18 +10,18 @@
|
|
|
9
10
|
* and `picture`, etc.
|
|
10
11
|
*/
|
|
11
12
|
interface AuthGateUser {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
13
|
+
/** Unique user identifier assigned by AuthGate. */
|
|
14
|
+
id: string;
|
|
15
|
+
/** User's email address. Present for email/OAuth flows, `null` for SMS-only users. */
|
|
16
|
+
email: string | null;
|
|
17
|
+
/** User's phone number in E.164 format. Present for SMS flows, `null` otherwise. */
|
|
18
|
+
phone: string | null;
|
|
19
|
+
/** User's display name from the OAuth provider or signup form. */
|
|
20
|
+
name: string | null;
|
|
21
|
+
/** URL to the user's profile picture from the OAuth provider. */
|
|
22
|
+
picture: string | null;
|
|
23
|
+
/** The authentication provider used (e.g. `"google"`, `"github"`, `"email"`, `"sms"`). */
|
|
24
|
+
provider: string;
|
|
24
25
|
}
|
|
25
26
|
/**
|
|
26
27
|
* Result of verifying a JWT token against the AuthGate API.
|
|
@@ -29,14 +30,14 @@ interface AuthGateUser {
|
|
|
29
30
|
* When `valid` is `false`, `error` describes why verification failed.
|
|
30
31
|
*/
|
|
31
32
|
interface TokenVerifyResult {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
33
|
+
/** Whether the token is valid and not expired. */
|
|
34
|
+
valid: boolean;
|
|
35
|
+
/** The authenticated user, present when `valid` is `true`. */
|
|
36
|
+
user?: AuthGateUser;
|
|
37
|
+
/** ISO 8601 timestamp when the token expires, present when `valid` is `true`. */
|
|
38
|
+
expiresAt?: string;
|
|
39
|
+
/** Human-readable error message, present when `valid` is `false`. */
|
|
40
|
+
error?: string;
|
|
40
41
|
}
|
|
41
42
|
/**
|
|
42
43
|
* Configuration for initializing an {@link AuthGateClient}.
|
|
@@ -52,54 +53,54 @@ interface TokenVerifyResult {
|
|
|
52
53
|
* ```
|
|
53
54
|
*/
|
|
54
55
|
interface AuthGateConfig {
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
56
|
+
/** Server-side API key for your AuthGate project. Found in the dashboard under API Key. */
|
|
57
|
+
apiKey: string;
|
|
58
|
+
/** Base URL of the AuthGate service (e.g. `"https://www.authgate.dev"`). */
|
|
59
|
+
baseUrl: string;
|
|
60
|
+
/**
|
|
61
|
+
* Name of the session cookie.
|
|
62
|
+
* @defaultValue `"__authgate"`
|
|
63
|
+
*/
|
|
64
|
+
cookieName?: string;
|
|
65
|
+
/**
|
|
66
|
+
* Session lifetime in seconds. Controls how long the encrypted session cookie
|
|
67
|
+
* and refresh token remain valid.
|
|
68
|
+
* @defaultValue `604800` (7 days)
|
|
69
|
+
*/
|
|
70
|
+
sessionMaxAge?: number;
|
|
71
|
+
/**
|
|
72
|
+
* Path where the OAuth callback handler is mounted.
|
|
73
|
+
* @defaultValue `"/api/auth/callback"`
|
|
74
|
+
*/
|
|
75
|
+
callbackPath?: string;
|
|
75
76
|
}
|
|
76
77
|
/**
|
|
77
78
|
* Internal payload structure stored inside the encrypted session cookie.
|
|
78
79
|
* Contains the user data plus issued-at and expiration timestamps.
|
|
79
80
|
*/
|
|
80
81
|
interface SessionPayload {
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
82
|
+
/** The authenticated user data. */
|
|
83
|
+
user: AuthGateUser;
|
|
84
|
+
/** Unix timestamp (seconds) when the session was created. */
|
|
85
|
+
iat: number;
|
|
86
|
+
/** Unix timestamp (seconds) when the session expires. */
|
|
87
|
+
exp: number;
|
|
87
88
|
}
|
|
88
89
|
/**
|
|
89
90
|
* Options for configuring HTTP cookies set by AuthGate.
|
|
90
91
|
* Maps directly to standard `Set-Cookie` attributes.
|
|
91
92
|
*/
|
|
92
93
|
interface CookieOptions {
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
94
|
+
/** Prevents client-side JavaScript from reading the cookie. */
|
|
95
|
+
httpOnly: boolean;
|
|
96
|
+
/** Only send the cookie over HTTPS connections. */
|
|
97
|
+
secure: boolean;
|
|
98
|
+
/** Controls when the cookie is sent with cross-site requests. */
|
|
99
|
+
sameSite: "lax" | "strict" | "none";
|
|
100
|
+
/** Cookie lifetime in seconds. */
|
|
101
|
+
maxAge: number;
|
|
102
|
+
/** URL path the cookie is valid for. */
|
|
103
|
+
path: string;
|
|
103
104
|
}
|
|
104
105
|
/**
|
|
105
106
|
* Supported OAuth provider identifiers.
|
|
@@ -114,36 +115,36 @@ type OAuthProvider = "google" | "github" | "discord" | "azure" | "apple";
|
|
|
114
115
|
* passing the `mfa_challenge` token and available `mfa_methods`.
|
|
115
116
|
*/
|
|
116
117
|
interface MfaChallengeResponse {
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
118
|
+
/** Always `true` — indicates MFA is required to complete authentication. */
|
|
119
|
+
mfa_required: true;
|
|
120
|
+
/** Opaque challenge token to pass to the MFA verify endpoint. */
|
|
121
|
+
mfa_challenge: string;
|
|
122
|
+
/** List of MFA methods the user has enrolled (e.g. `["totp", "sms"]`). */
|
|
123
|
+
mfa_methods: string[];
|
|
123
124
|
}
|
|
124
125
|
/**
|
|
125
126
|
* Current MFA enrollment status for a user.
|
|
126
127
|
* Returned by the `/api/proxy/mfa/status` endpoint.
|
|
127
128
|
*/
|
|
128
129
|
interface MfaStatus {
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
130
|
+
/** Whether the user has any MFA method enrolled. */
|
|
131
|
+
enrolled: boolean;
|
|
132
|
+
/** List of enrolled MFA methods (e.g. `["totp"]`, `["sms", "totp"]`). */
|
|
133
|
+
methods: string[];
|
|
134
|
+
/** Whether MFA is required by the project's policy. */
|
|
135
|
+
required: boolean;
|
|
135
136
|
}
|
|
136
137
|
/**
|
|
137
138
|
* Response from TOTP setup containing the secret and QR code.
|
|
138
139
|
* Returned by the `/api/proxy/mfa/totp/setup` endpoint.
|
|
139
140
|
*/
|
|
140
141
|
interface TotpSetupResponse {
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
142
|
+
/** Base32-encoded TOTP secret for manual entry. */
|
|
143
|
+
secret: string;
|
|
144
|
+
/** Data URL of the QR code image (PNG) for scanning with an authenticator app. */
|
|
145
|
+
qr_code: string;
|
|
146
|
+
/** `otpauth://` URI for the TOTP secret. */
|
|
147
|
+
uri: string;
|
|
147
148
|
}
|
|
148
149
|
/**
|
|
149
150
|
* Response from generating new MFA backup codes.
|
|
@@ -152,10 +153,11 @@ interface TotpSetupResponse {
|
|
|
152
153
|
* Each code can only be used once. Generating new codes invalidates all previous ones.
|
|
153
154
|
*/
|
|
154
155
|
interface BackupCodesResponse {
|
|
155
|
-
|
|
156
|
-
|
|
156
|
+
/** Array of single-use backup codes. Store these securely — they are shown only once. */
|
|
157
|
+
codes: string[];
|
|
157
158
|
}
|
|
158
|
-
|
|
159
|
+
//#endregion
|
|
160
|
+
//#region src/client.d.ts
|
|
159
161
|
/**
|
|
160
162
|
* Core client for interacting with the AuthGate authentication proxy.
|
|
161
163
|
*
|
|
@@ -174,437 +176,452 @@ interface BackupCodesResponse {
|
|
|
174
176
|
* ```
|
|
175
177
|
*/
|
|
176
178
|
declare class AuthGateClient {
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
179
|
+
private readonly config;
|
|
180
|
+
private encryptionKey;
|
|
181
|
+
private stateKey;
|
|
182
|
+
private keysReady;
|
|
183
|
+
/**
|
|
184
|
+
* @param config - Client configuration. See {@link AuthGateConfig}.
|
|
185
|
+
*/
|
|
186
|
+
constructor(config: AuthGateConfig);
|
|
187
|
+
private deriveKeys;
|
|
188
|
+
private getEncryptionKey;
|
|
189
|
+
private getStateKey;
|
|
190
|
+
/**
|
|
191
|
+
* Verify a JWT token against the AuthGate API.
|
|
192
|
+
*
|
|
193
|
+
* Makes a server-side `POST /api/v1/token/verify` call using your API key.
|
|
194
|
+
* Times out after 5 seconds.
|
|
195
|
+
*
|
|
196
|
+
* @param token - The JWT token string from the OAuth callback or email/SMS flow.
|
|
197
|
+
* @returns A {@link TokenVerifyResult} with the user data if valid.
|
|
198
|
+
* @throws {@link TokenVerificationError} if the request times out.
|
|
199
|
+
*/
|
|
200
|
+
verifyToken(token: string): Promise<TokenVerifyResult>;
|
|
201
|
+
/**
|
|
202
|
+
* Encrypt user data into a session cookie value.
|
|
203
|
+
*
|
|
204
|
+
* Uses AES-256-GCM with a key derived from your session secret.
|
|
205
|
+
* The returned string is safe to store in an httpOnly cookie.
|
|
206
|
+
*
|
|
207
|
+
* @param user - The authenticated user to store.
|
|
208
|
+
* @returns Base64url-encoded encrypted session string.
|
|
209
|
+
*/
|
|
210
|
+
encryptSession(user: AuthGateUser): Promise<string>;
|
|
211
|
+
/**
|
|
212
|
+
* Decrypt a session cookie and return the user if the session is valid.
|
|
213
|
+
*
|
|
214
|
+
* Returns `null` if the cookie is expired, tampered with, or encrypted
|
|
215
|
+
* with a different secret. All failure modes return `null` to prevent
|
|
216
|
+
* oracle attacks.
|
|
217
|
+
*
|
|
218
|
+
* @param cookieValue - The encrypted cookie string.
|
|
219
|
+
* @returns The user, or `null` if the session is invalid.
|
|
220
|
+
*/
|
|
221
|
+
decryptSession(cookieValue: string): Promise<AuthGateUser | null>;
|
|
222
|
+
/**
|
|
223
|
+
* Decrypt a session cookie and return the full payload (user + timestamps).
|
|
224
|
+
*
|
|
225
|
+
* Used internally by middleware to check `iat` for session revalidation.
|
|
226
|
+
*
|
|
227
|
+
* @param cookieValue - The encrypted cookie string.
|
|
228
|
+
* @returns The full session payload, or `null` if invalid.
|
|
229
|
+
* @internal
|
|
230
|
+
*/
|
|
231
|
+
decryptSessionPayload(cookieValue: string): Promise<SessionPayload | null>;
|
|
232
|
+
/**
|
|
233
|
+
* Create a signed OAuth state parameter and nonce for CSRF protection.
|
|
234
|
+
*
|
|
235
|
+
* Store the `nonce` in a short-lived httpOnly cookie and pass `state`
|
|
236
|
+
* as a query parameter in the OAuth authorization URL.
|
|
237
|
+
*
|
|
238
|
+
* @returns `{ state, nonce }` — the state string and its corresponding nonce.
|
|
239
|
+
*/
|
|
240
|
+
createState(): Promise<{
|
|
241
|
+
state: string;
|
|
242
|
+
nonce: string;
|
|
243
|
+
}>;
|
|
244
|
+
/**
|
|
245
|
+
* Verify an OAuth state parameter returned in the callback.
|
|
246
|
+
*
|
|
247
|
+
* @param state - The `state` query parameter from the callback.
|
|
248
|
+
* @param nonce - The nonce from the httpOnly cookie.
|
|
249
|
+
* @returns `true` if the state is valid and not expired.
|
|
250
|
+
*/
|
|
251
|
+
verifyState(state: string, nonce: string): Promise<boolean>;
|
|
252
|
+
/**
|
|
253
|
+
* Build the OAuth authorization URL for a given provider.
|
|
254
|
+
*
|
|
255
|
+
* @param provider - The OAuth provider (e.g. `"google"`, `"github"`).
|
|
256
|
+
* @param callbackUrl - Your app's callback URL where the user is redirected after auth.
|
|
257
|
+
* @param options - Optional parameters.
|
|
258
|
+
* @param options.linkTo - An existing user ID to link this OAuth account to.
|
|
259
|
+
* @returns The full authorization URL to redirect the user to.
|
|
260
|
+
* @throws {@link AuthGateError} if the provider is not in {@link SUPPORTED_PROVIDERS}.
|
|
261
|
+
*/
|
|
262
|
+
getOAuthUrl(provider: OAuthProvider, callbackUrl: string, options?: {
|
|
263
|
+
state?: string;
|
|
264
|
+
linkTo?: string;
|
|
265
|
+
locale?: string;
|
|
266
|
+
}): Promise<string>;
|
|
267
|
+
/**
|
|
268
|
+
* Register a new user with email and password.
|
|
269
|
+
*
|
|
270
|
+
* @param data - Signup data including email, password, optional name, and callback URL.
|
|
271
|
+
* @returns The raw `Response` from the AuthGate proxy.
|
|
272
|
+
*/
|
|
273
|
+
emailSignup(data: {
|
|
274
|
+
email: string;
|
|
275
|
+
password: string;
|
|
276
|
+
name?: string;
|
|
277
|
+
callbackUrl: string;
|
|
278
|
+
locale?: string;
|
|
279
|
+
}): Promise<Response>;
|
|
280
|
+
/**
|
|
281
|
+
* Sign in an existing user with email and password.
|
|
282
|
+
*
|
|
283
|
+
* The response may include `mfa_required: true` if the user has MFA enabled,
|
|
284
|
+
* in which case you should redirect to an MFA verification page.
|
|
285
|
+
*
|
|
286
|
+
* @param data - Sign-in data including email, password, and callback URL.
|
|
287
|
+
* @returns The raw `Response` from the AuthGate proxy.
|
|
288
|
+
*/
|
|
289
|
+
emailSignin(data: {
|
|
290
|
+
email: string;
|
|
291
|
+
password: string;
|
|
292
|
+
callbackUrl: string;
|
|
293
|
+
locale?: string;
|
|
294
|
+
}): Promise<Response>;
|
|
295
|
+
/**
|
|
296
|
+
* Send a password reset email to the user.
|
|
297
|
+
*
|
|
298
|
+
* @param data - The user's email and the URL to redirect to after clicking the reset link.
|
|
299
|
+
* @returns The raw `Response` from the AuthGate proxy.
|
|
300
|
+
*/
|
|
301
|
+
emailForgotPassword(data: {
|
|
302
|
+
email: string;
|
|
303
|
+
callbackUrl: string;
|
|
304
|
+
locale?: string;
|
|
305
|
+
}): Promise<Response>;
|
|
306
|
+
/**
|
|
307
|
+
* Confirm a password reset with the token from the reset email.
|
|
308
|
+
*
|
|
309
|
+
* @param data - The reset token and the new password.
|
|
310
|
+
* @returns The raw `Response` from the AuthGate proxy.
|
|
311
|
+
*/
|
|
312
|
+
emailResetPassword(data: {
|
|
313
|
+
token: string;
|
|
314
|
+
password: string;
|
|
315
|
+
locale?: string;
|
|
316
|
+
}): Promise<Response>;
|
|
317
|
+
/**
|
|
318
|
+
* Send a magic link email for passwordless authentication.
|
|
319
|
+
*
|
|
320
|
+
* @param data - The user's email and callback URL.
|
|
321
|
+
* @returns The raw `Response` from the AuthGate proxy.
|
|
322
|
+
*/
|
|
323
|
+
magicLinkSend(data: {
|
|
324
|
+
email: string;
|
|
325
|
+
callbackUrl: string;
|
|
326
|
+
locale?: string;
|
|
327
|
+
}): Promise<Response>;
|
|
328
|
+
/**
|
|
329
|
+
* Verify an email address using a one-time code.
|
|
330
|
+
*
|
|
331
|
+
* @param data - The user's email and the verification code.
|
|
332
|
+
* @returns The raw `Response` from the AuthGate proxy.
|
|
333
|
+
*/
|
|
334
|
+
emailVerifyCode(data: {
|
|
335
|
+
email: string;
|
|
336
|
+
code: string;
|
|
337
|
+
locale?: string;
|
|
338
|
+
}): Promise<Response>;
|
|
339
|
+
/**
|
|
340
|
+
* Send an SMS verification code to the user's phone number.
|
|
341
|
+
*
|
|
342
|
+
* @param data - The phone number (E.164 format) and callback URL.
|
|
343
|
+
* @returns The raw `Response` from the AuthGate proxy.
|
|
344
|
+
*/
|
|
345
|
+
smsSendCode(data: {
|
|
346
|
+
phone: string;
|
|
347
|
+
callbackUrl: string;
|
|
348
|
+
}): Promise<Response>;
|
|
349
|
+
/**
|
|
350
|
+
* Verify an SMS code and authenticate the user.
|
|
351
|
+
*
|
|
352
|
+
* @param data - The phone number, verification code, and callback URL.
|
|
353
|
+
* @returns The raw `Response` from the AuthGate proxy.
|
|
354
|
+
*/
|
|
355
|
+
smsVerifyCode(data: {
|
|
356
|
+
phone: string;
|
|
357
|
+
code: string;
|
|
358
|
+
callbackUrl: string;
|
|
359
|
+
}): Promise<Response>;
|
|
360
|
+
/**
|
|
361
|
+
* Exchange a refresh token for a new JWT.
|
|
362
|
+
*
|
|
363
|
+
* Refresh tokens are single-use: each call invalidates the token it was
|
|
364
|
+
* given, so callers must store the `refresh_token` it returns or their next
|
|
365
|
+
* refresh fails.
|
|
366
|
+
*
|
|
367
|
+
* @param refreshToken - The opaque refresh token.
|
|
368
|
+
* @returns A new JWT, its `expires_in` (seconds) and the rotated
|
|
369
|
+
* `refresh_token`, or `null` if the refresh token is invalid.
|
|
370
|
+
*/
|
|
371
|
+
refreshToken(refreshToken: string): Promise<{
|
|
372
|
+
token: string;
|
|
373
|
+
refresh_token?: string;
|
|
374
|
+
expires_in: number;
|
|
375
|
+
} | null>;
|
|
376
|
+
/**
|
|
377
|
+
* Exchange a single-use authorization code (delivered on the callback URL)
|
|
378
|
+
* for the JWT + refresh token. Codes are one-shot and expire after ~60s.
|
|
379
|
+
*
|
|
380
|
+
* @param code - The `code` query parameter from the callback redirect.
|
|
381
|
+
* @returns The tokens, or `null` if the code is invalid/expired/used.
|
|
382
|
+
*/
|
|
383
|
+
exchangeCode(code: string): Promise<{
|
|
384
|
+
token: string;
|
|
385
|
+
refresh_token?: string;
|
|
386
|
+
mfa_setup_required?: boolean;
|
|
387
|
+
} | null>;
|
|
388
|
+
/**
|
|
389
|
+
* Revoke a session by its refresh token.
|
|
390
|
+
*
|
|
391
|
+
* After revocation, the refresh token can no longer be used to obtain
|
|
392
|
+
* new JWTs. The user will need to re-authenticate.
|
|
393
|
+
*
|
|
394
|
+
* @param refreshToken - The opaque refresh token to revoke.
|
|
395
|
+
* @returns `true` if the session was revoked, `false` on failure.
|
|
396
|
+
*/
|
|
397
|
+
revokeSession(refreshToken: string): Promise<boolean>;
|
|
398
|
+
/**
|
|
399
|
+
* Verify an MFA code to complete authentication.
|
|
400
|
+
*
|
|
401
|
+
* Called after a sign-in response includes `mfa_required: true`.
|
|
402
|
+
*
|
|
403
|
+
* @param data - The MFA challenge token, verification code, and method.
|
|
404
|
+
* @returns The raw `Response` — includes a JWT on success.
|
|
405
|
+
*/
|
|
406
|
+
mfaVerify(data: {
|
|
407
|
+
challenge: string;
|
|
408
|
+
code: string;
|
|
409
|
+
method: "totp" | "sms" | "backup_code";
|
|
410
|
+
}): Promise<Response>;
|
|
411
|
+
/**
|
|
412
|
+
* Begin TOTP (authenticator app) setup for the authenticated user.
|
|
413
|
+
*
|
|
414
|
+
* Requires a valid JWT in the `Authorization: Bearer` header.
|
|
415
|
+
*
|
|
416
|
+
* @param token - The user's current JWT.
|
|
417
|
+
* @returns The raw `Response` with TOTP secret, QR code, and URI.
|
|
418
|
+
*/
|
|
419
|
+
mfaTotpSetup(token: string): Promise<Response>;
|
|
420
|
+
/**
|
|
421
|
+
* Confirm TOTP setup by verifying a code from the authenticator app.
|
|
422
|
+
*
|
|
423
|
+
* @param token - The user's current JWT.
|
|
424
|
+
* @param code - The 6-digit TOTP code from the authenticator app.
|
|
425
|
+
* @returns The raw `Response` — confirms enrollment on success.
|
|
426
|
+
*/
|
|
427
|
+
mfaTotpVerifySetup(token: string, code: string): Promise<Response>;
|
|
428
|
+
/**
|
|
429
|
+
* Disable TOTP for the authenticated user.
|
|
430
|
+
*
|
|
431
|
+
* @param token - The user's current JWT.
|
|
432
|
+
* @param code - A valid TOTP code to confirm the action.
|
|
433
|
+
* @returns The raw `Response`.
|
|
434
|
+
*/
|
|
435
|
+
mfaTotpDisable(token: string, code: string): Promise<Response>;
|
|
436
|
+
/**
|
|
437
|
+
* Enable SMS-based MFA for the authenticated user.
|
|
438
|
+
*
|
|
439
|
+
* Uses the phone number already associated with the user's account.
|
|
440
|
+
*
|
|
441
|
+
* @param token - The user's current JWT.
|
|
442
|
+
* @returns The raw `Response`.
|
|
443
|
+
*/
|
|
444
|
+
mfaSmsEnable(token: string): Promise<Response>;
|
|
445
|
+
/**
|
|
446
|
+
* Disable SMS-based MFA for the authenticated user.
|
|
447
|
+
*
|
|
448
|
+
* @param token - The user's current JWT.
|
|
449
|
+
* @returns The raw `Response`.
|
|
450
|
+
*/
|
|
451
|
+
mfaSmsDisable(token: string): Promise<Response>;
|
|
452
|
+
/**
|
|
453
|
+
* Generate a new set of single-use MFA backup codes.
|
|
454
|
+
*
|
|
455
|
+
* Generating new codes invalidates all previously issued backup codes.
|
|
456
|
+
*
|
|
457
|
+
* @param token - The user's current JWT.
|
|
458
|
+
* @returns The raw `Response` with an array of backup codes.
|
|
459
|
+
*/
|
|
460
|
+
mfaBackupCodesGenerate(token: string): Promise<Response>;
|
|
461
|
+
/**
|
|
462
|
+
* Get the current MFA enrollment status for the authenticated user.
|
|
463
|
+
*
|
|
464
|
+
* @param token - The user's current JWT.
|
|
465
|
+
* @returns The raw `Response` with {@link MfaStatus} data.
|
|
466
|
+
*/
|
|
467
|
+
mfaStatus(token: string): Promise<Response>;
|
|
468
|
+
/**
|
|
469
|
+
* Send an SMS code for MFA verification during the challenge flow.
|
|
470
|
+
*
|
|
471
|
+
* @param challenge - The MFA challenge token from the sign-in response.
|
|
472
|
+
* @returns The raw `Response`.
|
|
473
|
+
*/
|
|
474
|
+
mfaSmsSendCode(challenge: string): Promise<Response>;
|
|
475
|
+
/**
|
|
476
|
+
* Create a new organization.
|
|
477
|
+
*
|
|
478
|
+
* @param data - Organization creation data including name, slug, optional image URL, and metadata.
|
|
479
|
+
* @returns The raw `Response` from the AuthGate proxy.
|
|
480
|
+
*/
|
|
481
|
+
createOrg(data: {
|
|
482
|
+
name: string;
|
|
483
|
+
slug: string;
|
|
484
|
+
imageUrl?: string;
|
|
485
|
+
metadata?: Record<string, unknown>;
|
|
486
|
+
}): Promise<Response>;
|
|
487
|
+
/**
|
|
488
|
+
* List all organizations accessible to the current project.
|
|
489
|
+
*
|
|
490
|
+
* @returns The raw `Response` from the AuthGate proxy.
|
|
491
|
+
*/
|
|
492
|
+
listOrgs(): Promise<Response>;
|
|
493
|
+
/**
|
|
494
|
+
* Get a single organization by ID or slug.
|
|
495
|
+
*
|
|
496
|
+
* @param orgIdOrSlug - The organization ID or slug.
|
|
497
|
+
* @returns The raw `Response` from the AuthGate proxy.
|
|
498
|
+
*/
|
|
499
|
+
getOrg(orgIdOrSlug: string): Promise<Response>;
|
|
500
|
+
/**
|
|
501
|
+
* Update an organization's details.
|
|
502
|
+
*
|
|
503
|
+
* @param orgIdOrSlug - The organization ID or slug.
|
|
504
|
+
* @param data - Fields to update. All fields are optional.
|
|
505
|
+
* @returns The raw `Response` from the AuthGate proxy.
|
|
506
|
+
*/
|
|
507
|
+
updateOrg(orgIdOrSlug: string, data: {
|
|
508
|
+
name?: string;
|
|
509
|
+
slug?: string;
|
|
510
|
+
imageUrl?: string;
|
|
511
|
+
maxMembers?: number | null;
|
|
512
|
+
metadata?: Record<string, unknown>;
|
|
513
|
+
}): Promise<Response>;
|
|
514
|
+
/**
|
|
515
|
+
* Delete an organization.
|
|
516
|
+
*
|
|
517
|
+
* @param orgIdOrSlug - The organization ID or slug.
|
|
518
|
+
* @returns The raw `Response` from the AuthGate proxy.
|
|
519
|
+
*/
|
|
520
|
+
deleteOrg(orgIdOrSlug: string): Promise<Response>;
|
|
521
|
+
/**
|
|
522
|
+
* List all members of an organization.
|
|
523
|
+
*
|
|
524
|
+
* @param orgIdOrSlug - The organization ID or slug.
|
|
525
|
+
* @returns The raw `Response` from the AuthGate proxy.
|
|
526
|
+
*/
|
|
527
|
+
listOrgMembers(orgIdOrSlug: string): Promise<Response>;
|
|
528
|
+
/**
|
|
529
|
+
* Update a member's role within an organization.
|
|
530
|
+
*
|
|
531
|
+
* @param orgIdOrSlug - The organization ID or slug.
|
|
532
|
+
* @param memberId - The member's user ID.
|
|
533
|
+
* @param data - The new role to assign.
|
|
534
|
+
* @returns The raw `Response` from the AuthGate proxy.
|
|
535
|
+
*/
|
|
536
|
+
updateOrgMember(orgIdOrSlug: string, memberId: string, data: {
|
|
537
|
+
roleKey: string;
|
|
538
|
+
}): Promise<Response>;
|
|
539
|
+
/**
|
|
540
|
+
* Remove a member from an organization.
|
|
541
|
+
*
|
|
542
|
+
* @param orgIdOrSlug - The organization ID or slug.
|
|
543
|
+
* @param memberId - The member's user ID.
|
|
544
|
+
* @returns The raw `Response` from the AuthGate proxy.
|
|
545
|
+
*/
|
|
546
|
+
removeOrgMember(orgIdOrSlug: string, memberId: string): Promise<Response>;
|
|
547
|
+
/**
|
|
548
|
+
* Invite a user to an organization by email.
|
|
549
|
+
*
|
|
550
|
+
* @param orgIdOrSlug - The organization ID or slug.
|
|
551
|
+
* @param data - The invitee's email and optional role.
|
|
552
|
+
* @returns The raw `Response` from the AuthGate proxy.
|
|
553
|
+
*/
|
|
554
|
+
inviteToOrg(orgIdOrSlug: string, data: {
|
|
555
|
+
email: string;
|
|
556
|
+
roleKey?: string;
|
|
557
|
+
}): Promise<Response>;
|
|
558
|
+
/**
|
|
559
|
+
* List all pending invitations for an organization.
|
|
560
|
+
*
|
|
561
|
+
* @param orgIdOrSlug - The organization ID or slug.
|
|
562
|
+
* @returns The raw `Response` from the AuthGate proxy.
|
|
563
|
+
*/
|
|
564
|
+
listOrgInvitations(orgIdOrSlug: string): Promise<Response>;
|
|
565
|
+
/**
|
|
566
|
+
* Revoke a pending organization invitation.
|
|
567
|
+
*
|
|
568
|
+
* @param orgIdOrSlug - The organization ID or slug.
|
|
569
|
+
* @param invitationId - The invitation ID to revoke.
|
|
570
|
+
* @returns The raw `Response` from the AuthGate proxy.
|
|
571
|
+
*/
|
|
572
|
+
revokeOrgInvitation(orgIdOrSlug: string, invitationId: string): Promise<Response>;
|
|
573
|
+
/**
|
|
574
|
+
* Accept an organization invitation using a token.
|
|
575
|
+
*
|
|
576
|
+
* @param data - The invitation token received via email.
|
|
577
|
+
* @returns The raw `Response` from the AuthGate proxy.
|
|
578
|
+
*/
|
|
579
|
+
acceptOrgInvitation(data: {
|
|
580
|
+
token: string;
|
|
581
|
+
}): Promise<Response>;
|
|
582
|
+
/**
|
|
583
|
+
* Leave an organization as the current user.
|
|
584
|
+
*
|
|
585
|
+
* @param orgIdOrSlug - The organization ID or slug.
|
|
586
|
+
* @returns The raw `Response` from the AuthGate proxy.
|
|
587
|
+
*/
|
|
588
|
+
leaveOrg(orgIdOrSlug: string): Promise<Response>;
|
|
589
|
+
/** The name of the session cookie (default: `"__authgate"`). */
|
|
590
|
+
get cookieName(): string;
|
|
591
|
+
/** The name of the OAuth nonce cookie (`"__authgate_nonce"`). */
|
|
592
|
+
get nonceCookieName(): string;
|
|
593
|
+
/** The name of the refresh token cookie (`"__authgate_refresh"`). */
|
|
594
|
+
get refreshTokenCookieName(): string;
|
|
595
|
+
/** The callback path where OAuth redirects are handled (default: `"/api/auth/callback"`). */
|
|
596
|
+
get callbackPath(): string;
|
|
597
|
+
/** The AuthGate service base URL. */
|
|
598
|
+
get baseUrl(): string;
|
|
599
|
+
/** Session lifetime in seconds. */
|
|
600
|
+
get sessionMaxAge(): number;
|
|
601
|
+
/**
|
|
602
|
+
* Get cookie options for the session cookie.
|
|
603
|
+
*
|
|
604
|
+
* Returns `secure: true` in production, `httpOnly: true` always.
|
|
605
|
+
*/
|
|
606
|
+
getSessionCookieOptions(): CookieOptions;
|
|
607
|
+
/**
|
|
608
|
+
* Get cookie options for the OAuth nonce cookie.
|
|
609
|
+
*
|
|
610
|
+
* Short-lived (10 minutes) to match the state TTL.
|
|
611
|
+
*/
|
|
612
|
+
getNonceCookieOptions(): CookieOptions;
|
|
613
|
+
/**
|
|
614
|
+
* Validate the SDK configuration against the AuthGate server.
|
|
615
|
+
*
|
|
616
|
+
* Checks that the API key is valid and (optionally) that a callback URL
|
|
617
|
+
* is registered for the project. This is called automatically by framework
|
|
618
|
+
* factories (`createAuthGate`, `createAuthRoutes`) and logs errors to the
|
|
619
|
+
* console — it does NOT throw.
|
|
620
|
+
*
|
|
621
|
+
* @param callbackUrl - The full callback URL to check registration for.
|
|
622
|
+
* @internal
|
|
623
|
+
*/
|
|
624
|
+
validateConfig(callbackUrl?: string): Promise<void>;
|
|
608
625
|
}
|
|
609
626
|
/**
|
|
610
627
|
* Create an {@link AuthGateClient} instance.
|
|
@@ -615,7 +632,8 @@ declare class AuthGateClient {
|
|
|
615
632
|
* @returns A configured {@link AuthGateClient}.
|
|
616
633
|
*/
|
|
617
634
|
declare function createAuthGateClient(config: AuthGateConfig): AuthGateClient;
|
|
618
|
-
|
|
635
|
+
//#endregion
|
|
636
|
+
//#region src/constants.d.ts
|
|
619
637
|
/** Default name for the encrypted session cookie. */
|
|
620
638
|
declare const DEFAULT_COOKIE_NAME = "__authgate";
|
|
621
639
|
/** Cookie name used to store the OAuth CSRF nonce during the authorization flow. */
|
|
@@ -637,7 +655,8 @@ declare const STATE_TTL_MS = 600000;
|
|
|
637
655
|
* Configure provider credentials in the AuthGate dashboard under Providers.
|
|
638
656
|
*/
|
|
639
657
|
declare const SUPPORTED_PROVIDERS: OAuthProvider[];
|
|
640
|
-
|
|
658
|
+
//#endregion
|
|
659
|
+
//#region src/errors.d.ts
|
|
641
660
|
/**
|
|
642
661
|
* Base error class for all AuthGate errors.
|
|
643
662
|
*
|
|
@@ -656,7 +675,7 @@ declare const SUPPORTED_PROVIDERS: OAuthProvider[];
|
|
|
656
675
|
* ```
|
|
657
676
|
*/
|
|
658
677
|
declare class AuthGateError extends Error {
|
|
659
|
-
|
|
678
|
+
constructor(message: string);
|
|
660
679
|
}
|
|
661
680
|
/**
|
|
662
681
|
* Thrown when JWT token verification fails or times out.
|
|
@@ -665,7 +684,7 @@ declare class AuthGateError extends Error {
|
|
|
665
684
|
* AuthGate API is unreachable within the 5-second timeout.
|
|
666
685
|
*/
|
|
667
686
|
declare class TokenVerificationError extends AuthGateError {
|
|
668
|
-
|
|
687
|
+
constructor(message?: string);
|
|
669
688
|
}
|
|
670
689
|
/**
|
|
671
690
|
* Thrown when an encrypted session cookie cannot be decrypted.
|
|
@@ -674,7 +693,7 @@ declare class TokenVerificationError extends AuthGateError {
|
|
|
674
693
|
* tampered with, or the cookie format version is unsupported.
|
|
675
694
|
*/
|
|
676
695
|
declare class SessionDecryptionError extends AuthGateError {
|
|
677
|
-
|
|
696
|
+
constructor(message?: string);
|
|
678
697
|
}
|
|
679
698
|
/**
|
|
680
699
|
* Thrown when OAuth state verification fails.
|
|
@@ -683,7 +702,7 @@ declare class SessionDecryptionError extends AuthGateError {
|
|
|
683
702
|
* (older than 10 minutes), or a nonce mismatch.
|
|
684
703
|
*/
|
|
685
704
|
declare class InvalidStateError extends AuthGateError {
|
|
686
|
-
|
|
705
|
+
constructor(message?: string);
|
|
687
706
|
}
|
|
688
707
|
/**
|
|
689
708
|
* Thrown when the AuthGate SDK is initialized with invalid configuration.
|
|
@@ -692,9 +711,10 @@ declare class InvalidStateError extends AuthGateError {
|
|
|
692
711
|
* and how to fix it.
|
|
693
712
|
*/
|
|
694
713
|
declare class ConfigurationError extends AuthGateError {
|
|
695
|
-
|
|
714
|
+
constructor(message: string);
|
|
696
715
|
}
|
|
697
|
-
|
|
716
|
+
//#endregion
|
|
717
|
+
//#region src/project-config.d.ts
|
|
698
718
|
/**
|
|
699
719
|
* Connection details for the AuthGate API.
|
|
700
720
|
*
|
|
@@ -703,8 +723,8 @@ declare class ConfigurationError extends AuthGateError {
|
|
|
703
723
|
* auto-loads `.env` and `.env.local` before importing the config file.
|
|
704
724
|
*/
|
|
705
725
|
type AuthGateConnection = {
|
|
706
|
-
|
|
707
|
-
|
|
726
|
+
baseUrl?: string;
|
|
727
|
+
apiKey?: string;
|
|
708
728
|
};
|
|
709
729
|
/**
|
|
710
730
|
* Project-level config shape for `authgate.config.ts`.
|
|
@@ -717,31 +737,31 @@ type AuthGateConnection = {
|
|
|
717
737
|
* so you can reference `process.env` directly.
|
|
718
738
|
*/
|
|
719
739
|
interface AuthGateProjectConfig {
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
740
|
+
/**
|
|
741
|
+
* Connection details for the AuthGate API.
|
|
742
|
+
*
|
|
743
|
+
* If omitted, the CLI falls back to `AUTHGATE_URL` and `AUTHGATE_API_KEY`
|
|
744
|
+
* environment variables.
|
|
745
|
+
*/
|
|
746
|
+
connection?: AuthGateConnection;
|
|
747
|
+
/**
|
|
748
|
+
* Path to the RBAC config file (`authgate.rbac.ts`).
|
|
749
|
+
*
|
|
750
|
+
* Overrides auto-discovery. Useful in monorepos where the RBAC config
|
|
751
|
+
* lives in a different directory than the project root.
|
|
752
|
+
*
|
|
753
|
+
* @example `"./packages/api/authgate.rbac.ts"`
|
|
754
|
+
*/
|
|
755
|
+
rbacConfig?: string;
|
|
756
|
+
/**
|
|
757
|
+
* Path to the Billing config file (`authgate.billing.ts`).
|
|
758
|
+
*
|
|
759
|
+
* Overrides auto-discovery. Useful in monorepos where the billing config
|
|
760
|
+
* lives in a different directory than the project root.
|
|
761
|
+
*
|
|
762
|
+
* @example `"./packages/api/authgate.billing.ts"`
|
|
763
|
+
*/
|
|
764
|
+
billingConfig?: string;
|
|
745
765
|
}
|
|
746
766
|
/**
|
|
747
767
|
* Define your project-level AuthGate configuration.
|
|
@@ -797,90 +817,91 @@ interface AuthGateProjectConfig {
|
|
|
797
817
|
* ```
|
|
798
818
|
*/
|
|
799
819
|
declare function defineConfig(config: AuthGateProjectConfig): AuthGateProjectConfig;
|
|
800
|
-
|
|
820
|
+
//#endregion
|
|
821
|
+
//#region src/billing.d.ts
|
|
801
822
|
/** A product/plan in the billing catalog. */
|
|
802
823
|
interface BillingPlan {
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
824
|
+
id: string;
|
|
825
|
+
name: string;
|
|
826
|
+
description: string | null;
|
|
827
|
+
features: string[];
|
|
828
|
+
prices: BillingPrice[];
|
|
808
829
|
}
|
|
809
830
|
/** A price attached to a plan. */
|
|
810
831
|
interface BillingPrice {
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
832
|
+
id: string;
|
|
833
|
+
type: "recurring" | "metered" | "tiered";
|
|
834
|
+
amount: number | null;
|
|
835
|
+
currency: string;
|
|
836
|
+
interval: "daily" | "weekly" | "monthly" | "yearly";
|
|
837
|
+
intervalCount: number;
|
|
817
838
|
}
|
|
818
839
|
/** A single item within a subscription (price + product). */
|
|
819
840
|
interface BillingSubscriptionItem {
|
|
841
|
+
id: string;
|
|
842
|
+
quantity: number;
|
|
843
|
+
price: BillingPrice;
|
|
844
|
+
product: {
|
|
820
845
|
id: string;
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
name: string;
|
|
826
|
-
description: string | null;
|
|
827
|
-
features: string[];
|
|
828
|
-
};
|
|
846
|
+
name: string;
|
|
847
|
+
description: string | null;
|
|
848
|
+
features: string[];
|
|
849
|
+
};
|
|
829
850
|
}
|
|
830
851
|
/** An active subscription for an end user. */
|
|
831
852
|
interface BillingSubscription {
|
|
853
|
+
id: string;
|
|
854
|
+
status: "active" | "past_due" | "canceled" | "paused" | "trialing" | "unpaid";
|
|
855
|
+
/** Convenience: derived from the first subscription item's product. */
|
|
856
|
+
plan: {
|
|
832
857
|
id: string;
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
currentPeriodStart: string;
|
|
844
|
-
currentPeriodEnd: string;
|
|
845
|
-
cancelAtPeriodEnd: boolean;
|
|
846
|
-
trialEnd: string | null;
|
|
858
|
+
name: string;
|
|
859
|
+
} | null;
|
|
860
|
+
/** Convenience: derived from the first subscription item's price. */
|
|
861
|
+
price: BillingPrice | null;
|
|
862
|
+
/** The full list of subscription items returned by the API. */
|
|
863
|
+
items: BillingSubscriptionItem[];
|
|
864
|
+
currentPeriodStart: string;
|
|
865
|
+
currentPeriodEnd: string;
|
|
866
|
+
cancelAtPeriodEnd: boolean;
|
|
867
|
+
trialEnd: string | null;
|
|
847
868
|
}
|
|
848
869
|
/** Entitlement data for an end user — what plan they're on and what features they have. */
|
|
849
870
|
interface BillingEntitlement {
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
871
|
+
plan: string | null;
|
|
872
|
+
features: string[];
|
|
873
|
+
status: string | null;
|
|
874
|
+
currentPeriodEnd: string | null;
|
|
875
|
+
cancelAtPeriodEnd: boolean;
|
|
855
876
|
}
|
|
856
877
|
/** Typed entitlement detail for a boolean feature. */
|
|
857
878
|
interface BooleanEntitlementDetail {
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
879
|
+
type: "boolean";
|
|
880
|
+
feature: string;
|
|
881
|
+
allowed: boolean;
|
|
861
882
|
}
|
|
862
883
|
/** Typed entitlement detail for a metered feature. */
|
|
863
884
|
interface MeteredEntitlementDetail {
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
885
|
+
type: "metered";
|
|
886
|
+
feature: string;
|
|
887
|
+
allowed: boolean;
|
|
888
|
+
used: number;
|
|
889
|
+
limit: number;
|
|
890
|
+
remaining: number;
|
|
870
891
|
}
|
|
871
892
|
/** A single feature entitlement detail. */
|
|
872
893
|
type EntitlementDetail = BooleanEntitlementDetail | MeteredEntitlementDetail;
|
|
873
894
|
/** Extended entitlement data with typed feature details. */
|
|
874
895
|
interface BillingEntitlementV2 extends BillingEntitlement {
|
|
875
|
-
|
|
876
|
-
|
|
896
|
+
/** Typed feature details with metered usage info. */
|
|
897
|
+
featureDetails?: Record<string, EntitlementDetail>;
|
|
877
898
|
}
|
|
878
899
|
/** A single usage event to report. */
|
|
879
900
|
interface UsageEvent {
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
901
|
+
metric: string;
|
|
902
|
+
quantity: number;
|
|
903
|
+
idempotencyKey?: string;
|
|
904
|
+
timestamp?: string;
|
|
884
905
|
}
|
|
885
906
|
/**
|
|
886
907
|
* Check whether the user's entitlements include a specific plan.
|
|
@@ -906,52 +927,53 @@ declare function hasFeature(entitlements: BillingEntitlement | null | undefined,
|
|
|
906
927
|
* @returns The typed entitlement detail, or a denied boolean detail if not found.
|
|
907
928
|
*/
|
|
908
929
|
declare function checkFeature(entitlements: BillingEntitlementV2 | null | undefined, feature: string): EntitlementDetail;
|
|
909
|
-
|
|
930
|
+
//#endregion
|
|
931
|
+
//#region src/organizations.d.ts
|
|
910
932
|
/** An organization within a project. */
|
|
911
933
|
interface Organization {
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
934
|
+
id: string;
|
|
935
|
+
name: string;
|
|
936
|
+
slug: string;
|
|
937
|
+
imageUrl: string | null;
|
|
938
|
+
metadata: Record<string, unknown> | null;
|
|
939
|
+
createdAt: string;
|
|
918
940
|
}
|
|
919
941
|
/** A role definition with its permissions. */
|
|
920
942
|
interface OrgRole {
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
943
|
+
key: string;
|
|
944
|
+
name: string;
|
|
945
|
+
permissions: string[];
|
|
924
946
|
}
|
|
925
947
|
/** The current user's membership in an organization. */
|
|
926
948
|
interface OrgMembership {
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
949
|
+
id: string;
|
|
950
|
+
orgId: string;
|
|
951
|
+
role: OrgRole;
|
|
952
|
+
createdAt: string;
|
|
931
953
|
}
|
|
932
954
|
/** A member of an organization with user details. */
|
|
933
955
|
interface OrgMember {
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
956
|
+
id: string;
|
|
957
|
+
endUserId: string;
|
|
958
|
+
name: string | null;
|
|
959
|
+
email: string | null;
|
|
960
|
+
avatarUrl: string | null;
|
|
961
|
+
role: OrgRole;
|
|
962
|
+
createdAt: string;
|
|
941
963
|
}
|
|
942
964
|
/** An invitation to join an organization. */
|
|
943
965
|
interface OrgInvitation {
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
966
|
+
id: string;
|
|
967
|
+
email: string;
|
|
968
|
+
roleKey: string | null;
|
|
969
|
+
status: "pending" | "accepted" | "revoked" | "expired";
|
|
970
|
+
expiresAt: string;
|
|
971
|
+
createdAt: string;
|
|
950
972
|
}
|
|
951
973
|
/** An organization paired with the current user's membership. */
|
|
952
974
|
interface OrgWithMembership {
|
|
953
|
-
|
|
954
|
-
|
|
975
|
+
organization: Organization;
|
|
976
|
+
membership: OrgMembership;
|
|
955
977
|
}
|
|
956
978
|
/**
|
|
957
979
|
* Check whether a membership includes a specific permission.
|
|
@@ -991,10 +1013,18 @@ declare function hasAnyPermission(membership: OrgMembership | null | undefined,
|
|
|
991
1013
|
declare function hasAllPermissions(membership: OrgMembership | null | undefined, permissions: string[]): boolean;
|
|
992
1014
|
/** A user's project-level role assignment (no org required). */
|
|
993
1015
|
interface UserRoleAssignment {
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
1016
|
+
roleKey: string;
|
|
1017
|
+
roleName: string;
|
|
1018
|
+
permissions: string[];
|
|
1019
|
+
assignedAt: string;
|
|
1020
|
+
/**
|
|
1021
|
+
* Bumped whenever this user's effective permissions change.
|
|
1022
|
+
*
|
|
1023
|
+
* Optional so an older server that does not send it still parses. A client
|
|
1024
|
+
* caching permissions compares this to decide whether to refetch — see
|
|
1025
|
+
* AuthContextValue.permissions.
|
|
1026
|
+
*/
|
|
1027
|
+
permissionsEpoch?: number;
|
|
998
1028
|
}
|
|
999
1029
|
/**
|
|
1000
1030
|
* Merge permissions from a project-level role and an org-level role (union).
|
|
@@ -1006,5 +1036,5 @@ declare function mergePermissions(projectRole: UserRoleAssignment | null | undef
|
|
|
1006
1036
|
* Supports wildcard matching.
|
|
1007
1037
|
*/
|
|
1008
1038
|
declare function hasMergedPermission(projectRole: UserRoleAssignment | null | undefined, orgMembership: OrgMembership | null | undefined, permission: string): boolean;
|
|
1009
|
-
|
|
1010
|
-
export { AuthGateClient, type AuthGateConfig, type AuthGateConnection, AuthGateError, type AuthGateProjectConfig, type AuthGateUser, type BackupCodesResponse, type BillingEntitlement, type BillingEntitlementV2, type BillingPlan, type BillingPrice, type BillingSubscription, type BillingSubscriptionItem, type BooleanEntitlementDetail, ConfigurationError, type CookieOptions, DEFAULT_COOKIE_NAME, type EntitlementDetail, InvalidStateError, type MeteredEntitlementDetail, type MfaChallengeResponse, type MfaStatus, NONCE_COOKIE_NAME, type OAuthProvider, type OrgInvitation, type OrgMember, type OrgMembership, type OrgRole, type OrgWithMembership, type Organization, REFRESH_TOKEN_COOKIE_NAME, SESSION_MAX_AGE, STATE_TTL_MS, SUPPORTED_PROVIDERS, SessionDecryptionError, type SessionPayload, TokenVerificationError, type TokenVerifyResult, type TotpSetupResponse, type UsageEvent, type UserRoleAssignment, checkFeature, createAuthGateClient, defineConfig, hasAllPermissions, hasAnyPermission, hasFeature, hasMergedPermission, hasPermission, hasPlan, hasRole, mergePermissions };
|
|
1039
|
+
//#endregion
|
|
1040
|
+
export { AuthGateClient, type AuthGateConfig, type AuthGateConnection, AuthGateError, type AuthGateProjectConfig, type AuthGateUser, type BackupCodesResponse, type BillingEntitlement, type BillingEntitlementV2, type BillingPlan, type BillingPrice, type BillingSubscription, type BillingSubscriptionItem, type BooleanEntitlementDetail, ConfigurationError, type CookieOptions, DEFAULT_COOKIE_NAME, type EntitlementDetail, InvalidStateError, type MeteredEntitlementDetail, type MfaChallengeResponse, type MfaStatus, NONCE_COOKIE_NAME, type OAuthProvider, type OrgInvitation, type OrgMember, type OrgMembership, type OrgRole, type OrgWithMembership, type Organization, REFRESH_TOKEN_COOKIE_NAME, SESSION_MAX_AGE, STATE_TTL_MS, SUPPORTED_PROVIDERS, SessionDecryptionError, type SessionPayload, TokenVerificationError, type TokenVerifyResult, type TotpSetupResponse, type UsageEvent, type UserRoleAssignment, checkFeature, createAuthGateClient, defineConfig, hasAllPermissions, hasAnyPermission, hasFeature, hasMergedPermission, hasPermission, hasPlan, hasRole, mergePermissions };
|