@technomoron/api-server-base 1.1.13 → 2.0.0-beta.2
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/cjs/api-server-base.cjs +181 -74
- package/dist/cjs/api-server-base.d.ts +66 -29
- package/dist/cjs/auth-api/auth-module.d.ts +96 -0
- package/dist/cjs/auth-api/auth-module.js +1032 -0
- package/dist/cjs/auth-api/compat-auth-storage.d.ts +55 -0
- package/dist/cjs/auth-api/compat-auth-storage.js +116 -0
- package/dist/cjs/auth-api/mem-auth-store.d.ts +66 -0
- package/dist/cjs/auth-api/mem-auth-store.js +135 -0
- package/dist/cjs/{auth-module.d.ts → auth-api/module.d.ts} +7 -7
- package/dist/cjs/{auth-module.cjs → auth-api/module.js} +1 -1
- package/dist/cjs/auth-api/sql-auth-store.d.ts +75 -0
- package/dist/cjs/auth-api/sql-auth-store.js +166 -0
- package/dist/cjs/auth-api/storage.d.ts +36 -0
- package/dist/cjs/{auth-storage.cjs → auth-api/storage.js} +2 -2
- package/dist/cjs/auth-api/types.d.ts +29 -0
- package/dist/cjs/auth-api/types.js +2 -0
- package/dist/cjs/index.cjs +41 -7
- package/dist/cjs/index.d.ts +29 -5
- package/dist/cjs/oauth/base.d.ts +10 -0
- package/dist/cjs/oauth/base.js +6 -0
- package/dist/cjs/oauth/memory.d.ts +16 -0
- package/dist/cjs/oauth/memory.js +99 -0
- package/dist/cjs/oauth/models.d.ts +45 -0
- package/dist/cjs/oauth/models.js +58 -0
- package/dist/cjs/oauth/sequelize.d.ts +68 -0
- package/dist/cjs/oauth/sequelize.js +210 -0
- package/dist/cjs/oauth/types.d.ts +50 -0
- package/dist/cjs/oauth/types.js +3 -0
- package/dist/cjs/passkey/base.d.ts +15 -0
- package/dist/cjs/passkey/base.js +6 -0
- package/dist/cjs/passkey/memory.d.ts +26 -0
- package/dist/cjs/passkey/memory.js +82 -0
- package/dist/cjs/passkey/models.d.ts +25 -0
- package/dist/cjs/passkey/models.js +115 -0
- package/dist/cjs/passkey/sequelize.d.ts +54 -0
- package/dist/cjs/passkey/sequelize.js +211 -0
- package/dist/cjs/passkey/service.d.ts +17 -0
- package/dist/cjs/passkey/service.js +221 -0
- package/dist/cjs/passkey/types.d.ts +75 -0
- package/dist/cjs/passkey/types.js +2 -0
- package/dist/cjs/token/base.d.ts +38 -0
- package/dist/cjs/token/base.js +114 -0
- package/dist/cjs/token/memory.d.ts +19 -0
- package/dist/cjs/token/memory.js +149 -0
- package/dist/cjs/token/sequelize.d.ts +58 -0
- package/dist/cjs/token/sequelize.js +404 -0
- package/dist/cjs/token/types.d.ts +27 -0
- package/dist/cjs/token/types.js +2 -0
- package/dist/cjs/user/base.d.ts +26 -0
- package/dist/cjs/user/base.js +45 -0
- package/dist/cjs/user/memory.d.ts +35 -0
- package/dist/cjs/user/memory.js +173 -0
- package/dist/cjs/user/sequelize.d.ts +41 -0
- package/dist/cjs/user/sequelize.js +182 -0
- package/dist/cjs/user/types.d.ts +11 -0
- package/dist/cjs/user/types.js +2 -0
- package/dist/esm/api-server-base.d.ts +66 -29
- package/dist/esm/api-server-base.js +179 -72
- package/dist/esm/auth-api/auth-module.d.ts +96 -0
- package/dist/esm/auth-api/auth-module.js +1030 -0
- package/dist/esm/auth-api/compat-auth-storage.d.ts +55 -0
- package/dist/esm/auth-api/compat-auth-storage.js +112 -0
- package/dist/esm/auth-api/mem-auth-store.d.ts +66 -0
- package/dist/esm/auth-api/mem-auth-store.js +131 -0
- package/dist/esm/{auth-module.d.ts → auth-api/module.d.ts} +7 -7
- package/dist/esm/{auth-module.js → auth-api/module.js} +1 -1
- package/dist/esm/auth-api/sql-auth-store.d.ts +75 -0
- package/dist/esm/auth-api/sql-auth-store.js +162 -0
- package/dist/esm/auth-api/storage.d.ts +36 -0
- package/dist/esm/{auth-storage.js → auth-api/storage.js} +2 -2
- package/dist/esm/auth-api/types.d.ts +29 -0
- package/dist/esm/auth-api/types.js +1 -0
- package/dist/esm/index.d.ts +29 -5
- package/dist/esm/index.js +19 -2
- package/dist/esm/oauth/base.d.ts +10 -0
- package/dist/esm/oauth/base.js +2 -0
- package/dist/esm/oauth/memory.d.ts +16 -0
- package/dist/esm/oauth/memory.js +92 -0
- package/dist/esm/oauth/models.d.ts +45 -0
- package/dist/esm/oauth/models.js +51 -0
- package/dist/esm/oauth/sequelize.d.ts +68 -0
- package/dist/esm/oauth/sequelize.js +199 -0
- package/dist/esm/oauth/types.d.ts +50 -0
- package/dist/esm/oauth/types.js +2 -0
- package/dist/esm/passkey/base.d.ts +15 -0
- package/dist/esm/passkey/base.js +2 -0
- package/dist/esm/passkey/memory.d.ts +26 -0
- package/dist/esm/passkey/memory.js +78 -0
- package/dist/esm/passkey/models.d.ts +25 -0
- package/dist/esm/passkey/models.js +108 -0
- package/dist/esm/passkey/sequelize.d.ts +54 -0
- package/dist/esm/passkey/sequelize.js +207 -0
- package/dist/esm/passkey/service.d.ts +17 -0
- package/dist/esm/passkey/service.js +217 -0
- package/dist/esm/passkey/types.d.ts +75 -0
- package/dist/esm/passkey/types.js +1 -0
- package/dist/esm/token/base.d.ts +38 -0
- package/dist/esm/token/base.js +107 -0
- package/dist/esm/token/memory.d.ts +19 -0
- package/dist/esm/token/memory.js +145 -0
- package/dist/esm/token/sequelize.d.ts +58 -0
- package/dist/esm/token/sequelize.js +400 -0
- package/dist/esm/token/types.d.ts +27 -0
- package/dist/esm/token/types.js +1 -0
- package/dist/esm/user/base.d.ts +26 -0
- package/dist/esm/user/base.js +38 -0
- package/dist/esm/user/memory.d.ts +35 -0
- package/dist/esm/user/memory.js +169 -0
- package/dist/esm/user/sequelize.d.ts +41 -0
- package/dist/esm/user/sequelize.js +176 -0
- package/dist/esm/user/types.d.ts +11 -0
- package/dist/esm/user/types.js +1 -0
- package/package.json +11 -3
- package/dist/cjs/auth-storage.d.ts +0 -133
- package/dist/esm/auth-storage.d.ts +0 -133
|
@@ -4,13 +4,34 @@
|
|
|
4
4
|
* This source code is licensed under the MIT license found in the
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
|
+
import { randomUUID } from 'node:crypto';
|
|
7
8
|
import cookieParser from 'cookie-parser';
|
|
8
9
|
import cors from 'cors';
|
|
9
10
|
import express from 'express';
|
|
10
|
-
import jwt from 'jsonwebtoken';
|
|
11
11
|
import multer from 'multer';
|
|
12
|
-
import { nullAuthModule } from './auth-module.js';
|
|
13
|
-
import { nullAuthStorage } from './auth-storage.js';
|
|
12
|
+
import { nullAuthModule } from './auth-api/module.js';
|
|
13
|
+
import { nullAuthStorage } from './auth-api/storage.js';
|
|
14
|
+
import { TokenStore } from './token/base.js';
|
|
15
|
+
class JwtHelperStore extends TokenStore {
|
|
16
|
+
async save() {
|
|
17
|
+
throw new Error('Token store is not configured');
|
|
18
|
+
}
|
|
19
|
+
async get() {
|
|
20
|
+
throw new Error('Token store is not configured');
|
|
21
|
+
}
|
|
22
|
+
async delete() {
|
|
23
|
+
throw new Error('Token store is not configured');
|
|
24
|
+
}
|
|
25
|
+
async update() {
|
|
26
|
+
throw new Error('Token store is not configured');
|
|
27
|
+
}
|
|
28
|
+
async list() {
|
|
29
|
+
return [];
|
|
30
|
+
}
|
|
31
|
+
async close() {
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
14
35
|
export { ApiModule } from './api-module.js';
|
|
15
36
|
function guess_exception_text(error, defMsg = 'Unknown Error') {
|
|
16
37
|
const msg = [];
|
|
@@ -324,18 +345,36 @@ function fillConfig(config) {
|
|
|
324
345
|
hydrateGetBody: config.hydrateGetBody ?? true,
|
|
325
346
|
validateTokens: config.validateTokens ?? false,
|
|
326
347
|
apiVersion: config.apiVersion ?? '',
|
|
327
|
-
minClientVersion: config.minClientVersion ?? ''
|
|
348
|
+
minClientVersion: config.minClientVersion ?? '',
|
|
349
|
+
tokenStore: config.tokenStore,
|
|
350
|
+
authStores: config.authStores
|
|
328
351
|
};
|
|
329
352
|
}
|
|
330
353
|
export class ApiServer {
|
|
331
354
|
constructor(config = {}) {
|
|
332
355
|
this.currReq = null;
|
|
333
356
|
this.apiNotFoundHandler = null;
|
|
357
|
+
this.tokenStoreAdapter = null;
|
|
358
|
+
this.userStoreAdapter = null;
|
|
359
|
+
this.passkeyServiceAdapter = null;
|
|
360
|
+
this.oauthStoreAdapter = null;
|
|
361
|
+
this.canImpersonateAdapter = null;
|
|
334
362
|
this.config = fillConfig(config);
|
|
335
363
|
this.apiBasePath = this.normalizeApiBasePath(this.config.apiBasePath);
|
|
336
364
|
this.startedAt = Date.now();
|
|
337
365
|
this.storageAdapter = nullAuthStorage;
|
|
338
366
|
this.moduleAdapter = nullAuthModule;
|
|
367
|
+
this.jwtHelper = new JwtHelperStore();
|
|
368
|
+
this.tokenStoreAdapter = this.config.tokenStore ?? null;
|
|
369
|
+
if (this.config.authStores) {
|
|
370
|
+
const { userStore, tokenStore, passkeyService, oauthStore, canImpersonate } = this.config.authStores;
|
|
371
|
+
this.userStoreAdapter = userStore;
|
|
372
|
+
this.tokenStoreAdapter = tokenStore;
|
|
373
|
+
this.passkeyServiceAdapter = passkeyService ?? null;
|
|
374
|
+
this.oauthStoreAdapter = oauthStore ?? null;
|
|
375
|
+
this.canImpersonateAdapter = canImpersonate ?? null;
|
|
376
|
+
this.storageAdapter = this;
|
|
377
|
+
}
|
|
339
378
|
this.app = express();
|
|
340
379
|
if (config.uploadPath) {
|
|
341
380
|
const upload = multer({ dest: config.uploadPath });
|
|
@@ -372,72 +411,143 @@ export class ApiServer {
|
|
|
372
411
|
getAuthModule() {
|
|
373
412
|
return this.moduleAdapter;
|
|
374
413
|
}
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
return {
|
|
381
|
-
success: true,
|
|
382
|
-
token
|
|
383
|
-
};
|
|
414
|
+
setTokenStore(store) {
|
|
415
|
+
this.tokenStoreAdapter = store;
|
|
416
|
+
// If using direct stores, expose self as the auth storage.
|
|
417
|
+
if (this.userStoreAdapter) {
|
|
418
|
+
this.storageAdapter = this;
|
|
384
419
|
}
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
420
|
+
return this;
|
|
421
|
+
}
|
|
422
|
+
getTokenStore() {
|
|
423
|
+
return this.tokenStoreAdapter;
|
|
424
|
+
}
|
|
425
|
+
ensureUserStore() {
|
|
426
|
+
if (!this.userStoreAdapter) {
|
|
427
|
+
throw new Error('User store is not configured');
|
|
390
428
|
}
|
|
429
|
+
return this.userStoreAdapter;
|
|
391
430
|
}
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
const data = jwt.verify(token, secret, options);
|
|
396
|
-
return {
|
|
397
|
-
success: true,
|
|
398
|
-
data
|
|
399
|
-
};
|
|
431
|
+
ensureTokenStore() {
|
|
432
|
+
if (!this.tokenStoreAdapter) {
|
|
433
|
+
throw new Error('Token store is not configured');
|
|
400
434
|
}
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
error: 'Token expired'
|
|
407
|
-
};
|
|
408
|
-
}
|
|
409
|
-
else {
|
|
410
|
-
return {
|
|
411
|
-
success: false,
|
|
412
|
-
expired: false,
|
|
413
|
-
error: error instanceof Error ? error.message : String(error)
|
|
414
|
-
};
|
|
415
|
-
}
|
|
435
|
+
return this.tokenStoreAdapter;
|
|
436
|
+
}
|
|
437
|
+
ensurePasskeyService() {
|
|
438
|
+
if (!this.passkeyServiceAdapter) {
|
|
439
|
+
throw new Error('Passkey service is not configured');
|
|
416
440
|
}
|
|
441
|
+
return this.passkeyServiceAdapter;
|
|
417
442
|
}
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
const data = jwt.decode(token, options);
|
|
422
|
-
// jwt.decode returns null for invalid tokens rather than throwing
|
|
423
|
-
if (data === null) {
|
|
424
|
-
return {
|
|
425
|
-
success: false,
|
|
426
|
-
error: 'Invalid token format'
|
|
427
|
-
};
|
|
428
|
-
}
|
|
429
|
-
return {
|
|
430
|
-
success: true,
|
|
431
|
-
data
|
|
432
|
-
};
|
|
443
|
+
ensureOAuthStore() {
|
|
444
|
+
if (!this.oauthStoreAdapter) {
|
|
445
|
+
throw new Error('OAuth store is not configured');
|
|
433
446
|
}
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
447
|
+
return this.oauthStoreAdapter;
|
|
448
|
+
}
|
|
449
|
+
// AuthStorage-compatible helpers (used by AuthModule)
|
|
450
|
+
async getUser(identifier) {
|
|
451
|
+
return this.userStoreAdapter ? this.userStoreAdapter.findUser(identifier) : null;
|
|
452
|
+
}
|
|
453
|
+
getUserPasswordHash(user) {
|
|
454
|
+
return this.ensureUserStore().getPasswordHash(user) ?? '';
|
|
455
|
+
}
|
|
456
|
+
getUserId(user) {
|
|
457
|
+
return this.ensureUserStore().getUserId(user);
|
|
458
|
+
}
|
|
459
|
+
filterUser(user) {
|
|
460
|
+
return this.ensureUserStore().toPublic(user);
|
|
461
|
+
}
|
|
462
|
+
async verifyPassword(password, hash) {
|
|
463
|
+
return this.ensureUserStore().verifyPassword(password, hash);
|
|
464
|
+
}
|
|
465
|
+
async storeToken(data) {
|
|
466
|
+
if (this.tokenStoreAdapter) {
|
|
467
|
+
return this.tokenStoreAdapter.save(data);
|
|
440
468
|
}
|
|
469
|
+
if (typeof this.storageAdapter.storeToken === 'function') {
|
|
470
|
+
return this.storageAdapter.storeToken(data);
|
|
471
|
+
}
|
|
472
|
+
throw new Error('Token store is not configured');
|
|
473
|
+
}
|
|
474
|
+
async getToken(query, opts) {
|
|
475
|
+
const normalized = {
|
|
476
|
+
...query,
|
|
477
|
+
userId: query.userId !== undefined && query.userId !== null ? String(query.userId) : undefined,
|
|
478
|
+
ruid: query.ruid !== undefined && query.ruid !== null ? String(query.ruid) : undefined
|
|
479
|
+
};
|
|
480
|
+
if (this.tokenStoreAdapter) {
|
|
481
|
+
return this.tokenStoreAdapter.get(normalized, opts);
|
|
482
|
+
}
|
|
483
|
+
if (typeof this.storageAdapter.getToken === 'function') {
|
|
484
|
+
return this.storageAdapter.getToken(normalized, opts);
|
|
485
|
+
}
|
|
486
|
+
return null;
|
|
487
|
+
}
|
|
488
|
+
async deleteToken(query) {
|
|
489
|
+
const normalized = {
|
|
490
|
+
...query,
|
|
491
|
+
userId: query.userId !== undefined && query.userId !== null ? String(query.userId) : undefined,
|
|
492
|
+
ruid: query.ruid !== undefined && query.ruid !== null ? String(query.ruid) : undefined
|
|
493
|
+
};
|
|
494
|
+
if (this.tokenStoreAdapter) {
|
|
495
|
+
return this.tokenStoreAdapter.delete(normalized);
|
|
496
|
+
}
|
|
497
|
+
if (typeof this.storageAdapter.deleteToken === 'function') {
|
|
498
|
+
return this.storageAdapter.deleteToken(normalized);
|
|
499
|
+
}
|
|
500
|
+
return 0;
|
|
501
|
+
}
|
|
502
|
+
async createPasskeyChallenge(params) {
|
|
503
|
+
return this.ensurePasskeyService().createChallenge(params);
|
|
504
|
+
}
|
|
505
|
+
async verifyPasskeyResponse(params) {
|
|
506
|
+
return this.ensurePasskeyService().verifyResponse(params);
|
|
507
|
+
}
|
|
508
|
+
async getClient(clientId) {
|
|
509
|
+
return this.oauthStoreAdapter ? this.oauthStoreAdapter.getClient(clientId) : null;
|
|
510
|
+
}
|
|
511
|
+
async verifyClientSecret(client, clientSecret) {
|
|
512
|
+
return this.ensureOAuthStore().verifyClientSecret(client.clientId, clientSecret);
|
|
513
|
+
}
|
|
514
|
+
async createAuthCode(request) {
|
|
515
|
+
const expiresAt = new Date(Date.now() + (request.expiresInSeconds ?? 300) * 1000);
|
|
516
|
+
const code = request.code ?? randomUUID();
|
|
517
|
+
await this.ensureOAuthStore().createAuthCode({ ...request, code, expiresAt });
|
|
518
|
+
return {
|
|
519
|
+
code,
|
|
520
|
+
clientId: request.clientId,
|
|
521
|
+
userId: request.userId,
|
|
522
|
+
redirectUri: request.redirectUri,
|
|
523
|
+
scope: request.scope ?? [],
|
|
524
|
+
codeChallenge: request.codeChallenge,
|
|
525
|
+
codeChallengeMethod: request.codeChallengeMethod,
|
|
526
|
+
expiresAt,
|
|
527
|
+
metadata: request.metadata
|
|
528
|
+
};
|
|
529
|
+
}
|
|
530
|
+
async consumeAuthCode(code, clientId) {
|
|
531
|
+
const consumed = await this.ensureOAuthStore().consumeAuthCode(code);
|
|
532
|
+
if (!consumed || consumed.clientId !== clientId) {
|
|
533
|
+
return null;
|
|
534
|
+
}
|
|
535
|
+
return consumed;
|
|
536
|
+
}
|
|
537
|
+
async canImpersonate(params) {
|
|
538
|
+
if (this.canImpersonateAdapter) {
|
|
539
|
+
return !!(await this.canImpersonateAdapter(params));
|
|
540
|
+
}
|
|
541
|
+
return params.realUserId === params.effectiveUserId;
|
|
542
|
+
}
|
|
543
|
+
jwtSign(payload, secret, expiresInSeconds, options) {
|
|
544
|
+
return (this.tokenStoreAdapter ?? this.jwtHelper).jwtSign(payload, secret, expiresInSeconds, options);
|
|
545
|
+
}
|
|
546
|
+
jwtVerify(token, secret, options) {
|
|
547
|
+
return (this.tokenStoreAdapter ?? this.jwtHelper).jwtVerify(token, secret, options);
|
|
548
|
+
}
|
|
549
|
+
jwtDecode(token, options) {
|
|
550
|
+
return (this.tokenStoreAdapter ?? this.jwtHelper).jwtDecode(token, options);
|
|
441
551
|
}
|
|
442
552
|
async getApiKey(token) {
|
|
443
553
|
void token;
|
|
@@ -455,16 +565,13 @@ export class ApiServer {
|
|
|
455
565
|
return this.storageAdapter.verifyPassword(params.password, hash);
|
|
456
566
|
}
|
|
457
567
|
async updateToken(updates) {
|
|
458
|
-
if (
|
|
459
|
-
return
|
|
568
|
+
if (this.tokenStoreAdapter) {
|
|
569
|
+
return this.tokenStoreAdapter.update(updates);
|
|
460
570
|
}
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
clientId: updates.clientId,
|
|
466
|
-
scope: updates.scope
|
|
467
|
-
});
|
|
571
|
+
if (typeof this.storageAdapter.updateToken === 'function') {
|
|
572
|
+
return this.storageAdapter.updateToken(updates);
|
|
573
|
+
}
|
|
574
|
+
return false;
|
|
468
575
|
}
|
|
469
576
|
guessExceptionText(error, defMsg = 'Unkown Error') {
|
|
470
577
|
return guess_exception_text(error, defMsg);
|
|
@@ -678,7 +785,7 @@ export class ApiServer {
|
|
|
678
785
|
return this.config.validateTokens || authType === 'strict';
|
|
679
786
|
}
|
|
680
787
|
async assertStoredAccessToken(apiReq, token, tokenData) {
|
|
681
|
-
const userId = this.extractTokenUserId(tokenData);
|
|
788
|
+
const userId = String(this.extractTokenUserId(tokenData));
|
|
682
789
|
const stored = await this.storageAdapter.getToken({
|
|
683
790
|
accessToken: token,
|
|
684
791
|
userId
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import { type ApiRequest, type ApiRoute, type ApiServer } from '../api-server-base.js';
|
|
2
|
+
import { BaseAuthModule, type AuthProviderModule } from './module.js';
|
|
3
|
+
import type { AuthIdentifier, AuthStorage } from './types.js';
|
|
4
|
+
import type { OAuthCallbackParams, OAuthCallbackResult, OAuthStartParams, OAuthStartResult } from '../oauth/types.js';
|
|
5
|
+
import type { TokenPair, Token } from '../token/types.js';
|
|
6
|
+
interface CanImpersonateContext<UserEntity> {
|
|
7
|
+
apiReq: ApiRequest;
|
|
8
|
+
realUser: UserEntity;
|
|
9
|
+
realUserId: AuthIdentifier;
|
|
10
|
+
targetUser: UserEntity;
|
|
11
|
+
effectiveUserId: AuthIdentifier;
|
|
12
|
+
}
|
|
13
|
+
interface AuthModuleOptions<UserEntity> {
|
|
14
|
+
namespace?: string;
|
|
15
|
+
defaultDomain?: string;
|
|
16
|
+
canImpersonate?: (context: CanImpersonateContext<UserEntity>) => Promise<boolean> | boolean;
|
|
17
|
+
}
|
|
18
|
+
type TokenMetadata = Partial<Token> & {
|
|
19
|
+
sessionCookie?: boolean;
|
|
20
|
+
};
|
|
21
|
+
interface TokenIssueOptions extends TokenMetadata {
|
|
22
|
+
expires?: Date;
|
|
23
|
+
sessionCookie?: boolean;
|
|
24
|
+
}
|
|
25
|
+
interface NormalizedTokenMetadata extends TokenMetadata {
|
|
26
|
+
domain: string;
|
|
27
|
+
fingerprint: string;
|
|
28
|
+
label: string;
|
|
29
|
+
browser: string;
|
|
30
|
+
device: string;
|
|
31
|
+
ip: string;
|
|
32
|
+
os: string;
|
|
33
|
+
}
|
|
34
|
+
type TokenClaims = TokenMetadata & {
|
|
35
|
+
uid: string;
|
|
36
|
+
exp?: number;
|
|
37
|
+
iat?: number;
|
|
38
|
+
};
|
|
39
|
+
type AuthCapableServer<PublicUser> = ApiServer & {
|
|
40
|
+
initiateOAuth?: (params: OAuthStartParams) => Promise<OAuthStartResult>;
|
|
41
|
+
completeOAuth?: (params: OAuthCallbackParams) => Promise<OAuthCallbackResult<PublicUser>>;
|
|
42
|
+
};
|
|
43
|
+
export default class AuthModule<UserEntity, PublicUser> extends BaseAuthModule<UserEntity> implements AuthProviderModule<UserEntity> {
|
|
44
|
+
static defaultNamespace: string;
|
|
45
|
+
server: AuthCapableServer<PublicUser>;
|
|
46
|
+
private readonly defaultDomain?;
|
|
47
|
+
private readonly canImpersonateHook?;
|
|
48
|
+
constructor(options?: AuthModuleOptions<UserEntity>);
|
|
49
|
+
protected get storage(): AuthStorage<UserEntity, PublicUser>;
|
|
50
|
+
protected canImpersonate(apiReq: ApiRequest, realUser: UserEntity, targetUser: UserEntity): Promise<boolean>;
|
|
51
|
+
protected ensureImpersonationAllowed(apiReq: ApiRequest, realUser: UserEntity, targetUser: UserEntity): Promise<void>;
|
|
52
|
+
protected buildTokenPayload(user: UserEntity, metadata?: TokenMetadata): TokenClaims;
|
|
53
|
+
protected buildTokenMetadata(metadata?: TokenMetadata): NormalizedTokenMetadata;
|
|
54
|
+
protected enrichTokenMetadata(apiReq: ApiRequest, metadata?: TokenMetadata): TokenMetadata;
|
|
55
|
+
private sessionRefreshTtlSeconds;
|
|
56
|
+
private normalizeRefreshTtlSeconds;
|
|
57
|
+
private resolveSessionPreferences;
|
|
58
|
+
private mergeSessionPreferences;
|
|
59
|
+
private sessionPrefsFromRecord;
|
|
60
|
+
private cookieOptions;
|
|
61
|
+
private setJwtCookies;
|
|
62
|
+
issueTokens(apiReq: ApiRequest, user: UserEntity, metadata?: TokenIssueOptions): Promise<TokenPair>;
|
|
63
|
+
private assertAuthReady;
|
|
64
|
+
private parseLoginBody;
|
|
65
|
+
private parseImpersonationRequest;
|
|
66
|
+
private resolveImpersonationIdentifier;
|
|
67
|
+
private buildImpersonationMetadata;
|
|
68
|
+
private getUserOrThrow;
|
|
69
|
+
private getRealUserIdentifier;
|
|
70
|
+
private resolveActorContext;
|
|
71
|
+
private extractRefreshToken;
|
|
72
|
+
private normalizeScope;
|
|
73
|
+
private postLogin;
|
|
74
|
+
private postRefresh;
|
|
75
|
+
private postLogout;
|
|
76
|
+
private postWhoAmI;
|
|
77
|
+
private postPasskeyChallenge;
|
|
78
|
+
private postPasskeyVerify;
|
|
79
|
+
private postImpersonation;
|
|
80
|
+
private deleteImpersonation;
|
|
81
|
+
private getUserFromPasskey;
|
|
82
|
+
private postOAuthStart;
|
|
83
|
+
private postOAuthCallback;
|
|
84
|
+
private postOAuthAuthorize;
|
|
85
|
+
private postOAuthToken;
|
|
86
|
+
private handleAuthorizationCodeGrant;
|
|
87
|
+
private handleRefreshTokenGrant;
|
|
88
|
+
private clearOAuthCookies;
|
|
89
|
+
private buildTokenResponse;
|
|
90
|
+
private resolveScope;
|
|
91
|
+
private resolveClientAuthentication;
|
|
92
|
+
private assertRedirectUriAllowed;
|
|
93
|
+
private resolveUserForOAuth;
|
|
94
|
+
defineRoutes(): ApiRoute[];
|
|
95
|
+
}
|
|
96
|
+
export {};
|