@kurdel/auth 0.1.0-beta.4 → 0.1.0-beta.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (74) hide show
  1. package/README.md +28 -24
  2. package/lib/domain/auth-context.d.ts +16 -1
  3. package/lib/domain/auth-event-sink-provider.d.ts +10 -0
  4. package/lib/domain/auth-event.d.ts +34 -3
  5. package/lib/domain/auth-event.js +8 -1
  6. package/lib/domain/auth-event.js.map +1 -1
  7. package/lib/domain/auth-strategy-provider.d.ts +17 -0
  8. package/lib/domain/auth-strategy.d.ts +17 -7
  9. package/lib/domain/authorization-policy-composition.d.ts +20 -3
  10. package/lib/domain/authorization-policy-composition.js +24 -3
  11. package/lib/domain/authorization-policy-composition.js.map +1 -1
  12. package/lib/domain/authorization-policy-provider.d.ts +17 -0
  13. package/lib/domain/authorization-policy.d.ts +39 -3
  14. package/lib/domain/authorization-policy.js +8 -2
  15. package/lib/domain/authorization-policy.js.map +1 -1
  16. package/lib/domain/permission.d.ts +12 -2
  17. package/lib/domain/permission.js +16 -3
  18. package/lib/domain/permission.js.map +1 -1
  19. package/lib/infra/in-memory/in-memory-api-key-repository.d.ts +11 -1
  20. package/lib/infra/in-memory/in-memory-api-key-repository.js +11 -1
  21. package/lib/infra/in-memory/in-memory-api-key-repository.js.map +1 -1
  22. package/lib/infra/in-memory/in-memory-auth-user-repository.d.ts +11 -1
  23. package/lib/infra/in-memory/in-memory-auth-user-repository.js +11 -1
  24. package/lib/infra/in-memory/in-memory-auth-user-repository.js.map +1 -1
  25. package/lib/infra/in-memory/in-memory-jwt-repository.d.ts +5 -1
  26. package/lib/infra/in-memory/in-memory-jwt-repository.js +5 -1
  27. package/lib/infra/in-memory/in-memory-jwt-repository.js.map +1 -1
  28. package/lib/password/password-authentication-service.d.ts +29 -0
  29. package/lib/password/password-authentication-service.js +31 -1
  30. package/lib/password/password-authentication-service.js.map +1 -1
  31. package/lib/password/password-hasher.d.ts +18 -0
  32. package/lib/password/scrypt-password-hasher.d.ts +46 -1
  33. package/lib/password/scrypt-password-hasher.js +33 -1
  34. package/lib/password/scrypt-password-hasher.js.map +1 -1
  35. package/lib/repositories/api-key/api-key-repository.d.ts +22 -12
  36. package/lib/repositories/api-key/api-key-usage-recorder.d.ts +12 -1
  37. package/lib/repositories/jwt/jwt-repository.d.ts +7 -1
  38. package/lib/repositories/jwt/jwt-session-repository.d.ts +27 -3
  39. package/lib/repositories/password/password-credential-repository.d.ts +25 -1
  40. package/lib/repositories/user/auth-user-repository.d.ts +16 -4
  41. package/lib/runtime/auth-module.d.ts +32 -28
  42. package/lib/runtime/auth-module.js +26 -12
  43. package/lib/runtime/auth-module.js.map +1 -1
  44. package/lib/runtime/auth-strategy-registry.d.ts +24 -7
  45. package/lib/runtime/auth-strategy-registry.js +24 -7
  46. package/lib/runtime/auth-strategy-registry.js.map +1 -1
  47. package/lib/runtime/authorization-policy-registry.d.ts +35 -1
  48. package/lib/runtime/authorization-policy-registry.js +35 -1
  49. package/lib/runtime/authorization-policy-registry.js.map +1 -1
  50. package/lib/runtime/create-auth-middleware.d.ts +32 -0
  51. package/lib/runtime/create-auth-middleware.js +41 -2
  52. package/lib/runtime/create-auth-middleware.js.map +1 -1
  53. package/lib/strategies/api-key/api-key-strategy-provider.d.ts +18 -0
  54. package/lib/strategies/api-key/api-key-strategy-provider.js +30 -0
  55. package/lib/strategies/api-key/api-key-strategy-provider.js.map +1 -0
  56. package/lib/strategies/api-key/api-key-strategy.d.ts +39 -1
  57. package/lib/strategies/api-key/api-key-strategy.js +34 -1
  58. package/lib/strategies/api-key/api-key-strategy.js.map +1 -1
  59. package/lib/strategies/api-key/index.d.ts +1 -0
  60. package/lib/strategies/api-key/index.js +1 -0
  61. package/lib/strategies/api-key/index.js.map +1 -1
  62. package/lib/strategies/jwt/index.d.ts +1 -0
  63. package/lib/strategies/jwt/index.js +1 -0
  64. package/lib/strategies/jwt/index.js.map +1 -1
  65. package/lib/strategies/jwt/jwt-service.d.ts +61 -10
  66. package/lib/strategies/jwt/jwt-service.js +38 -9
  67. package/lib/strategies/jwt/jwt-service.js.map +1 -1
  68. package/lib/strategies/jwt/jwt-strategy-provider.d.ts +18 -0
  69. package/lib/strategies/jwt/jwt-strategy-provider.js +27 -0
  70. package/lib/strategies/jwt/jwt-strategy-provider.js.map +1 -0
  71. package/lib/strategies/jwt/jwt-strategy.d.ts +43 -4
  72. package/lib/strategies/jwt/jwt-strategy.js +26 -2
  73. package/lib/strategies/jwt/jwt-strategy.js.map +1 -1
  74. package/package.json +4 -4
@@ -2,10 +2,39 @@ import type { AuthUser } from '@kurdel/common';
2
2
  import type { PasswordCredentialRepository } from '../repositories/password/index.js';
3
3
  import type { AuthUserRepository } from '../repositories/user/index.js';
4
4
  import type { PasswordHasher } from './password-hasher.js';
5
+ /**
6
+ * ## PasswordAuthenticationService
7
+ *
8
+ * Coordinates password-based authentication.
9
+ *
10
+ * Responsibilities:
11
+ * - resolve password credentials from an application-defined login
12
+ * - verify the presented password
13
+ * - resolve the current authenticated user
14
+ *
15
+ * Guarantees:
16
+ * - unknown credentials never authenticate
17
+ * - invalid passwords never authenticate
18
+ * - user identity is resolved only after successful password verification
19
+ *
20
+ * Non-responsibilities:
21
+ * - password persistence
22
+ * - password hashing implementation
23
+ * - user management
24
+ */
5
25
  export declare class PasswordAuthenticationService {
6
26
  private readonly credentials;
7
27
  private readonly users;
8
28
  private readonly hasher;
9
29
  constructor(credentials: PasswordCredentialRepository, users: AuthUserRepository, hasher: PasswordHasher);
30
+ /**
31
+ * Authenticates a user using a login identifier and password.
32
+ *
33
+ * Returns `null` when the login cannot be authenticated or the
34
+ * associated user is unavailable.
35
+ *
36
+ * Unknown logins intentionally perform a password hashing operation
37
+ * before returning to reduce observable timing differences.
38
+ */
10
39
  authenticate(login: string, password: string): Promise<AuthUser | null>;
11
40
  }
@@ -1,9 +1,38 @@
1
+ /**
2
+ * ## PasswordAuthenticationService
3
+ *
4
+ * Coordinates password-based authentication.
5
+ *
6
+ * Responsibilities:
7
+ * - resolve password credentials from an application-defined login
8
+ * - verify the presented password
9
+ * - resolve the current authenticated user
10
+ *
11
+ * Guarantees:
12
+ * - unknown credentials never authenticate
13
+ * - invalid passwords never authenticate
14
+ * - user identity is resolved only after successful password verification
15
+ *
16
+ * Non-responsibilities:
17
+ * - password persistence
18
+ * - password hashing implementation
19
+ * - user management
20
+ */
1
21
  export class PasswordAuthenticationService {
2
22
  constructor(credentials, users, hasher) {
3
23
  this.credentials = credentials;
4
24
  this.users = users;
5
25
  this.hasher = hasher;
6
26
  }
27
+ /**
28
+ * Authenticates a user using a login identifier and password.
29
+ *
30
+ * Returns `null` when the login cannot be authenticated or the
31
+ * associated user is unavailable.
32
+ *
33
+ * Unknown logins intentionally perform a password hashing operation
34
+ * before returning to reduce observable timing differences.
35
+ */
7
36
  async authenticate(login, password) {
8
37
  const credential = await this.credentials.findByLogin(login);
9
38
  if (!credential) {
@@ -11,8 +40,9 @@ export class PasswordAuthenticationService {
11
40
  await this.hasher.hash(password);
12
41
  return null;
13
42
  }
14
- if (!(await this.hasher.verify(password, credential.passwordHash)))
43
+ if (!(await this.hasher.verify(password, credential.passwordHash))) {
15
44
  return null;
45
+ }
16
46
  return this.users.findById(credential.userId);
17
47
  }
18
48
  }
@@ -1 +1 @@
1
- {"version":3,"file":"password-authentication-service.js","sourceRoot":"","sources":["../../src/password/password-authentication-service.ts"],"names":[],"mappings":"AAMA,MAAM,OAAO,6BAA6B;IACxC,YACmB,WAAyC,EACzC,KAAyB,EACzB,MAAsB;QAFtB,gBAAW,GAAX,WAAW,CAA8B;QACzC,UAAK,GAAL,KAAK,CAAoB;QACzB,WAAM,GAAN,MAAM,CAAgB;IACtC,CAAC;IAEJ,KAAK,CAAC,YAAY,CAAC,KAAa,EAAE,QAAgB;QAChD,MAAM,UAAU,GAAG,MAAM,IAAI,CAAC,WAAW,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC;QAC7D,IAAI,CAAC,UAAU,EAAE,CAAC;YAChB,uEAAuE;YACvE,MAAM,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;YACjC,OAAO,IAAI,CAAC;QACd,CAAC;QACD,IAAI,CAAC,CAAC,MAAM,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,QAAQ,EAAE,UAAU,CAAC,YAAY,CAAC,CAAC;YAAE,OAAO,IAAI,CAAC;QAChF,OAAO,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC;IAChD,CAAC;CACF"}
1
+ {"version":3,"file":"password-authentication-service.js","sourceRoot":"","sources":["../../src/password/password-authentication-service.ts"],"names":[],"mappings":"AAMA;;;;;;;;;;;;;;;;;;;GAmBG;AACH,MAAM,OAAO,6BAA6B;IACxC,YACmB,WAAyC,EACzC,KAAyB,EACzB,MAAsB;QAFtB,gBAAW,GAAX,WAAW,CAA8B;QACzC,UAAK,GAAL,KAAK,CAAoB;QACzB,WAAM,GAAN,MAAM,CAAgB;IACtC,CAAC;IAEJ;;;;;;;;OAQG;IACH,KAAK,CAAC,YAAY,CAAC,KAAa,EAAE,QAAgB;QAChD,MAAM,UAAU,GAAG,MAAM,IAAI,CAAC,WAAW,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC;QAE7D,IAAI,CAAC,UAAU,EAAE,CAAC;YAChB,uEAAuE;YACvE,MAAM,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;YACjC,OAAO,IAAI,CAAC;QACd,CAAC;QAED,IAAI,CAAC,CAAC,MAAM,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,QAAQ,EAAE,UAAU,CAAC,YAAY,CAAC,CAAC,EAAE,CAAC;YACnE,OAAO,IAAI,CAAC;QACd,CAAC;QAED,OAAO,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC;IAChD,CAAC;CACF"}
@@ -1,4 +1,22 @@
1
+ /**
2
+ * ## PasswordHasher
3
+ *
4
+ * Hashes and verifies passwords.
5
+ *
6
+ * Implementations are responsible only for password hashing and
7
+ * verification. They neither manage password persistence nor enforce
8
+ * application-specific password policies.
9
+ */
1
10
  export interface PasswordHasher {
11
+ /**
12
+ * Derives a password hash suitable for persistent storage.
13
+ */
2
14
  hash(password: string): Promise<string> | string;
15
+ /**
16
+ * Verifies a password against a previously generated hash.
17
+ *
18
+ * Returns `false` when the password does not match or the encoded
19
+ * hash cannot be verified.
20
+ */
3
21
  verify(password: string, encodedHash: string): Promise<boolean> | boolean;
4
22
  }
@@ -1,12 +1,44 @@
1
1
  import type { PasswordHasher } from './password-hasher.js';
2
+ /**
3
+ * ## ScryptPasswordHasherOptions
4
+ *
5
+ * Configures password hashing parameters.
6
+ *
7
+ * The defaults follow conservative values suitable for general-purpose
8
+ * password authentication.
9
+ */
2
10
  export interface ScryptPasswordHasherOptions {
11
+ /** CPU/memory cost parameter (`N`). */
3
12
  cost?: number;
13
+ /** Block size parameter (`r`). */
4
14
  blockSize?: number;
15
+ /** Parallelization parameter (`p`). */
5
16
  parallelization?: number;
17
+ /** Derived key length in bytes. */
6
18
  keyLength?: number;
19
+ /** Random salt length in bytes. */
7
20
  saltLength?: number;
8
21
  }
9
- /** Password hasher with a self-describing format that supports future rehashing. */
22
+ /**
23
+ * ## ScryptPasswordHasher
24
+ *
25
+ * Password hasher based on the scrypt key derivation function.
26
+ *
27
+ * Responsibilities:
28
+ * - derive password hashes using scrypt
29
+ * - verify passwords against persisted hashes
30
+ * - embed hashing parameters into the stored hash format
31
+ *
32
+ * Guarantees:
33
+ * - every generated hash uses a cryptographically secure random salt
34
+ * - password verification uses constant-time comparison
35
+ * - malformed or unsupported hashes never authenticate
36
+ *
37
+ * Non-responsibilities:
38
+ * - password persistence
39
+ * - password policy enforcement
40
+ * - credential management
41
+ */
10
42
  export declare class ScryptPasswordHasher implements PasswordHasher {
11
43
  private readonly cost;
12
44
  private readonly blockSize;
@@ -14,7 +46,20 @@ export declare class ScryptPasswordHasher implements PasswordHasher {
14
46
  private readonly keyLength;
15
47
  private readonly saltLength;
16
48
  constructor(options?: ScryptPasswordHasherOptions);
49
+ /**
50
+ * Derives a self-describing password hash.
51
+ *
52
+ * The resulting hash embeds the algorithm, parameters, salt,
53
+ * and derived key, allowing future verification without
54
+ * additional metadata.
55
+ */
17
56
  hash(password: string): Promise<string>;
57
+ /**
58
+ * Verifies a password against a previously generated hash.
59
+ *
60
+ * Returns `false` for malformed hashes, unsupported parameters,
61
+ * or verification failures.
62
+ */
18
63
  verify(password: string, encodedHash: string): Promise<boolean>;
19
64
  private derive;
20
65
  private validParameters;
@@ -1,5 +1,24 @@
1
1
  import crypto from 'node:crypto';
2
- /** Password hasher with a self-describing format that supports future rehashing. */
2
+ /**
3
+ * ## ScryptPasswordHasher
4
+ *
5
+ * Password hasher based on the scrypt key derivation function.
6
+ *
7
+ * Responsibilities:
8
+ * - derive password hashes using scrypt
9
+ * - verify passwords against persisted hashes
10
+ * - embed hashing parameters into the stored hash format
11
+ *
12
+ * Guarantees:
13
+ * - every generated hash uses a cryptographically secure random salt
14
+ * - password verification uses constant-time comparison
15
+ * - malformed or unsupported hashes never authenticate
16
+ *
17
+ * Non-responsibilities:
18
+ * - password persistence
19
+ * - password policy enforcement
20
+ * - credential management
21
+ */
3
22
  export class ScryptPasswordHasher {
4
23
  constructor(options = {}) {
5
24
  this.cost = options.cost ?? 16384;
@@ -8,6 +27,13 @@ export class ScryptPasswordHasher {
8
27
  this.keyLength = options.keyLength ?? 64;
9
28
  this.saltLength = options.saltLength ?? 16;
10
29
  }
30
+ /**
31
+ * Derives a self-describing password hash.
32
+ *
33
+ * The resulting hash embeds the algorithm, parameters, salt,
34
+ * and derived key, allowing future verification without
35
+ * additional metadata.
36
+ */
11
37
  async hash(password) {
12
38
  const salt = crypto.randomBytes(this.saltLength);
13
39
  const derived = await this.derive(password, salt, this.cost, this.blockSize, this.parallelization, this.keyLength);
@@ -20,6 +46,12 @@ export class ScryptPasswordHasher {
20
46
  derived.toString('base64url'),
21
47
  ].join('$');
22
48
  }
49
+ /**
50
+ * Verifies a password against a previously generated hash.
51
+ *
52
+ * Returns `false` for malformed hashes, unsupported parameters,
53
+ * or verification failures.
54
+ */
23
55
  async verify(password, encodedHash) {
24
56
  const parts = encodedHash.split('$');
25
57
  if (parts.length !== 6 || parts[0] !== 'scrypt')
@@ -1 +1 @@
1
- {"version":3,"file":"scrypt-password-hasher.js","sourceRoot":"","sources":["../../src/password/scrypt-password-hasher.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,aAAa,CAAC;AAYjC,oFAAoF;AACpF,MAAM,OAAO,oBAAoB;IAO/B,YAAY,UAAuC,EAAE;QACnD,IAAI,CAAC,IAAI,GAAG,OAAO,CAAC,IAAI,IAAI,KAAM,CAAC;QACnC,IAAI,CAAC,SAAS,GAAG,OAAO,CAAC,SAAS,IAAI,CAAC,CAAC;QACxC,IAAI,CAAC,eAAe,GAAG,OAAO,CAAC,eAAe,IAAI,CAAC,CAAC;QACpD,IAAI,CAAC,SAAS,GAAG,OAAO,CAAC,SAAS,IAAI,EAAE,CAAC;QACzC,IAAI,CAAC,UAAU,GAAG,OAAO,CAAC,UAAU,IAAI,EAAE,CAAC;IAC7C,CAAC;IAED,KAAK,CAAC,IAAI,CAAC,QAAgB;QACzB,MAAM,IAAI,GAAG,MAAM,CAAC,WAAW,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;QACjD,MAAM,OAAO,GAAG,MAAM,IAAI,CAAC,MAAM,CAC/B,QAAQ,EACR,IAAI,EACJ,IAAI,CAAC,IAAI,EACT,IAAI,CAAC,SAAS,EACd,IAAI,CAAC,eAAe,EACpB,IAAI,CAAC,SAAS,CACf,CAAC;QACF,OAAO;YACL,QAAQ;YACR,IAAI,CAAC,IAAI;YACT,IAAI,CAAC,SAAS;YACd,IAAI,CAAC,eAAe;YACpB,IAAI,CAAC,QAAQ,CAAC,WAAW,CAAC;YAC1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,EAAE,MAAM,EAAE,EAAE;YACrC,MAAM,CAAC,MAAM,CACX,QAAQ,EACR,IAAI,EACJ,SAAS,EACT;gBACE,CAAC,EAAE,IAAI;gBACP,CAAC,EAAE,SAAS;gBACZ,CAAC,EAAE,eAAe;gBAClB,MAAM,EAAE,IAAI,CAAC,GAAG,CAAC,EAAE,GAAG,IAAI,GAAG,IAAI,EAAE,GAAG,GAAG,IAAI,GAAG,SAAS,CAAC;aAC3D,EACD,CAAC,KAAK,EAAE,UAAU,EAAE,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC,CACrE,CAAC;QACJ,CAAC,CAAC,CAAC;IACL,CAAC;IAEO,eAAe,CACrB,IAAY,EACZ,SAAiB,EACjB,eAAuB,EACvB,IAAY,EACZ,IAAY;QAEZ,OAAO,CACL,MAAM,CAAC,SAAS,CAAC,IAAI,CAAC;YACtB,IAAI,IAAI,IAAI;YACZ,IAAI,IAAI,OAAS;YACjB,MAAM,CAAC,SAAS,CAAC,SAAS,CAAC;YAC3B,SAAS,IAAI,CAAC;YACd,SAAS,IAAI,EAAE;YACf,MAAM,CAAC,SAAS,CAAC,eAAe,CAAC;YACjC,eAAe,IAAI,CAAC;YACpB,eAAe,IAAI,EAAE;YACrB,IAAI,CAAC,MAAM,IAAI,CAAC;YAChB,IAAI,CAAC,MAAM,IAAI,EAAE;YACjB,IAAI,CAAC,MAAM,IAAI,EAAE;YACjB,IAAI,CAAC,MAAM,IAAI,GAAG,CACnB,CAAC;IACJ,CAAC;CACF"}
1
+ {"version":3,"file":"scrypt-password-hasher.js","sourceRoot":"","sources":["../../src/password/scrypt-password-hasher.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,aAAa,CAAC;AA6BjC;;;;;;;;;;;;;;;;;;;GAmBG;AACH,MAAM,OAAO,oBAAoB;IAO/B,YAAY,UAAuC,EAAE;QACnD,I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AC,CACrE,CAAC;QACJ,CAAC,CAAC,CAAC;IACL,CAAC;IAEO,eAAe,CACrB,IAAY,EACZ,SAAiB,EACjB,eAAuB,EACvB,IAAY,EACZ,IAAY;QAEZ,OAAO,CACL,MAAM,CAAC,SAAS,CAAC,IAAI,CAAC;YACtB,IAAI,IAAI,IAAI;YACZ,IAAI,IAAI,OAAS;YACjB,MAAM,CAAC,SAAS,CAAC,SAAS,CAAC;YAC3B,SAAS,IAAI,CAAC;YACd,SAAS,IAAI,EAAE;YACf,MAAM,CAAC,SAAS,CAAC,eAAe,CAAC;YACjC,eAAe,IAAI,CAAC;YACpB,eAAe,IAAI,EAAE;YACrB,IAAI,CAAC,MAAM,IAAI,CAAC;YAChB,IAAI,CAAC,MAAM,IAAI,EAAE;YACjB,IAAI,CAAC,MAAM,IAAI,EAAE;YACjB,IAAI,CAAC,MAAM,IAAI,GAAG,CACnB,CAAC;IACJ,CAAC;CACF"}
@@ -1,30 +1,40 @@
1
+ /**
2
+ * ## ApiKeyCredential
3
+ *
4
+ * Metadata describing an API key after successful lookup.
5
+ *
6
+ * The credential contains only the information required for
7
+ * authentication. User identity, roles, and permissions are resolved
8
+ * separately through {@link AuthUserRepository}.
9
+ */
1
10
  export interface ApiKeyCredential {
2
11
  /** Stable credential identifier, when the backing store exposes one. */
3
12
  id?: string;
4
- /** Stable identity resolved after credential validation. */
13
+ /** Identifier of the associated application user. */
5
14
  userId: string | number;
6
- /** Revoked credentials must never authenticate. */
15
+ /** Indicates whether the credential has been revoked. */
7
16
  revoked?: boolean;
8
- /** Optional absolute expiry time. */
17
+ /** Optional absolute expiration time. */
9
18
  expiresAt?: Date;
10
19
  }
11
20
  /**
12
21
  * ## ApiKeyRepository
13
22
  *
14
- * Abstraction for retrieving credential metadata by API key.
23
+ * Resolves API-key credentials from presented secrets.
15
24
  *
16
- * A repository implementation may:
17
- * - load records from an in-memory map
18
- * - query a database
19
- * - read from Redis or any other KV store
20
- * - call an external authentication service
25
+ * Implementations may retrieve credentials from any backing store,
26
+ * including databases, in-memory collections, key-value stores, or
27
+ * external authentication services.
21
28
  *
22
- * Strategies depend only on this interface, not on the storage details.
29
+ * The returned credential contains only authentication metadata.
30
+ * Authorization data is resolved separately through
31
+ * {@link AuthUserRepository}.
23
32
  */
24
33
  export interface ApiKeyRepository {
25
34
  /**
26
- * Returns credential metadata associated with the given API key.
27
- * If the key is unknown, must return `null`.
35
+ * Resolves the credential associated with an API key.
36
+ *
37
+ * Returns `null` when the key is unknown or cannot be authenticated.
28
38
  */
29
39
  findByKey(key: string): Promise<ApiKeyCredential | null> | ApiKeyCredential | null;
30
40
  }
@@ -1,4 +1,15 @@
1
- /** Persists successful API-key usage without coupling strategies to storage. */
1
+ /**
2
+ * ## ApiKeyUsageRecorder
3
+ *
4
+ * Records successful API-key authentication events.
5
+ *
6
+ * Implementations may persist usage information in any backing store,
7
+ * such as a database or cache, without coupling authentication
8
+ * strategies to storage details.
9
+ */
2
10
  export interface ApiKeyUsageRecorder {
11
+ /**
12
+ * Records the successful use of an API-key credential.
13
+ */
3
14
  recordUsage(credentialId: string, usedAt: Date): Promise<void> | void;
4
15
  }
@@ -1,3 +1,9 @@
1
1
  import type { AuthUserRepository } from '../../repositories/user/index.js';
2
- /** @deprecated Use AuthUserRepository. JWT is a credential, not a user store. */
2
+ /**
3
+ * @deprecated Use {@link AuthUserRepository} instead.
4
+ *
5
+ * This alias reflected an earlier design where JWT authentication was
6
+ * coupled to user lookup. User identity is now resolved independently
7
+ * of the presented credential.
8
+ */
3
9
  export type JwtRepository = AuthUserRepository;
@@ -1,10 +1,34 @@
1
- export type JwtSession = {
1
+ /**
2
+ * ## JwtSession
3
+ *
4
+ * Server-side state associated with a JWT through its `jti` claim.
5
+ *
6
+ * The session allows signed tokens to be revoked before their
7
+ * cryptographic expiration without maintaining server-side token data.
8
+ */
9
+ export interface JwtSession {
10
+ /** Stable session identifier referenced by the JWT `jti` claim. */
2
11
  id: string;
12
+ /** Identifier of the associated application user. */
3
13
  userId: string | number;
14
+ /** Indicates whether the session has been revoked. */
4
15
  revoked: boolean;
16
+ /** Optional server-side expiration time. */
5
17
  expiresAt?: Date;
6
- };
7
- /** Resolves server-side JWT session state used for token revocation. */
18
+ }
19
+ /**
20
+ * ## JwtSessionRepository
21
+ *
22
+ * Resolves the current state of server-side JWT sessions.
23
+ *
24
+ * Implementations expose whether a session exists, has been revoked,
25
+ * or has expired independently of the JWT itself.
26
+ */
8
27
  export interface JwtSessionRepository {
28
+ /**
29
+ * Resolves a JWT session by its identifier.
30
+ *
31
+ * Returns `null` when the session does not exist.
32
+ */
9
33
  findById(id: string): Promise<JwtSession | null>;
10
34
  }
@@ -1,8 +1,32 @@
1
+ /**
2
+ * ## PasswordCredential
3
+ *
4
+ * Password credential associated with an application user.
5
+ *
6
+ * The credential contains only the information required for password
7
+ * verification. User identity, roles, and permissions are resolved
8
+ * separately through {@link AuthUserRepository}.
9
+ */
1
10
  export interface PasswordCredential {
11
+ /** Identifier of the associated application user. */
2
12
  userId: string | number;
13
+ /** Persisted password hash. */
3
14
  passwordHash: string;
4
15
  }
5
- /** Resolves a password credential by an application-defined login. */
16
+ /**
17
+ * ## PasswordCredentialRepository
18
+ *
19
+ * Resolves password credentials from an application-defined login.
20
+ *
21
+ * The login identifier is application-specific (for example, an email
22
+ * address or username). Implementations are responsible for mapping the
23
+ * supplied login to the corresponding credential.
24
+ */
6
25
  export interface PasswordCredentialRepository {
26
+ /**
27
+ * Resolves the password credential associated with a login.
28
+ *
29
+ * Returns `null` when the login cannot be authenticated.
30
+ */
7
31
  findByLogin(login: string): Promise<PasswordCredential | null> | PasswordCredential | null;
8
32
  }
@@ -1,11 +1,23 @@
1
1
  import type { AuthUser } from '@kurdel/common';
2
2
  /**
3
- * Resolves the current application identity used for authorization.
3
+ * ## AuthUserRepository
4
4
  *
5
- * Implementations exclude identities that must not authenticate, such as
6
- * disabled or deleted users. Roles come from this source of truth rather than
7
- * from the presented credential.
5
+ * Resolves the current application identity for authentication and
6
+ * authorization.
7
+ *
8
+ * Implementations expose the application's current source of truth.
9
+ * Users that are no longer allowed to authenticate (for example,
10
+ * disabled or deleted accounts) should not be returned.
11
+ *
12
+ * Authorization data such as roles and permissions is resolved from
13
+ * this repository rather than from the presented credential.
8
14
  */
9
15
  export interface AuthUserRepository {
16
+ /**
17
+ * Resolves the current authenticated user by identifier.
18
+ *
19
+ * Returns `null` when the user does not exist or is no longer
20
+ * eligible for authentication.
21
+ */
10
22
  findById(id: string | number): Promise<AuthUser | null> | AuthUser | null;
11
23
  }
@@ -4,19 +4,14 @@ import { type AuthEventSinkProvider, type AuthStrategyProvider, type Authorizati
4
4
  /**
5
5
  * ## AuthModuleConfig
6
6
  *
7
- * Defines authentication strategies supplied by the application.
7
+ * Configures authentication infrastructure provided by `AuthModule`.
8
8
  *
9
- * Example:
10
- * ```ts
11
- * new AuthModule({
12
- * strategies: [
13
- * { name: 'api-key', use: new ApiKeyStrategy({...}) },
14
- * { name: 'jwt', use: new JwtStrategy({...}) },
15
- * ]
16
- * })
17
- * ```
9
+ * Applications declare:
10
+ * - authentication strategies
11
+ * - authorization policies
12
+ * - optional authentication event sink
18
13
  *
19
- * Strategies are registered **once** during module initialization.
14
+ * All configured components are registered once during application startup.
20
15
  */
21
16
  export interface AuthModuleConfig {
22
17
  /** List of user-provided authentication strategies. */
@@ -29,36 +24,45 @@ export interface AuthModuleConfig {
29
24
  /**
30
25
  * ## AuthModule
31
26
  *
27
+ * Registers the authentication runtime.
28
+ *
32
29
  * Provides:
33
- * - singleton `AuthStrategyRegistry`
34
- * - automatic registration of configured strategies
30
+ * - AuthStrategyRegistry
31
+ * - AuthorizationPolicyRegistry
32
+ * - AuthEventSink
33
+ *
34
+ * Registers:
35
+ * - authentication middleware
35
36
  *
36
37
  * Responsibilities:
37
- * - expose a DI-managed registry storing all auth strategies
38
- * - populate it during `register()`
38
+ * - register configured strategies
39
+ * - register configured authorization policies
40
+ * - register the authentication middleware
41
+ * - expose authentication infrastructure through DI
39
42
  *
40
- * Non-responsibilities:
41
- * - no transport logic
42
- * - no middleware ordering
43
- * - no policy evaluation
43
+ * Guarantees:
44
+ * - configured strategies are registered exactly once
45
+ * - configured policies are registered exactly once
46
+ * - authentication middleware is installed in the `auth` zone
47
+ * - an `AuthEventSink` is always available
44
48
  *
45
- * Identity repositories, credentials and strategy-specific services are
46
- * application concerns and must be supplied outside this module.
49
+ * Non-responsibilities:
50
+ * - credential persistence
51
+ * - authentication implementations
52
+ * - authorization decisions
53
+ * - user management
47
54
  */
48
55
  export declare class AuthModule implements AppModule<AuthModuleConfig> {
49
56
  private readonly config;
50
57
  readonly priority = ModulePriority.Auth;
51
- /**
52
- * Providers exposed by the module.
53
- *
54
- * - `StrategyRegistry` → a singleton container of auth strategies
55
- */
56
58
  readonly providers: ProviderConfig[];
57
59
  constructor(config?: AuthModuleConfig);
58
60
  /**
59
- * Registers all configured authentication strategies.
61
+ * Registers authentication runtime components.
60
62
  *
61
- * Called once during app startup.
63
+ * 1. Registers authentication strategies.
64
+ * 2️. Registers authorization policies.
65
+ * 3️. Installs the authentication middleware.
62
66
  */
63
67
  register(ioc: Container): Promise<void>;
64
68
  }
@@ -6,21 +6,33 @@ import { AUTH_TOKENS } from '../tokens.js';
6
6
  /**
7
7
  * ## AuthModule
8
8
  *
9
+ * Registers the authentication runtime.
10
+ *
9
11
  * Provides:
10
- * - singleton `AuthStrategyRegistry`
11
- * - automatic registration of configured strategies
12
+ * - AuthStrategyRegistry
13
+ * - AuthorizationPolicyRegistry
14
+ * - AuthEventSink
15
+ *
16
+ * Registers:
17
+ * - authentication middleware
12
18
  *
13
19
  * Responsibilities:
14
- * - expose a DI-managed registry storing all auth strategies
15
- * - populate it during `register()`
20
+ * - register configured strategies
21
+ * - register configured authorization policies
22
+ * - register the authentication middleware
23
+ * - expose authentication infrastructure through DI
16
24
  *
17
- * Non-responsibilities:
18
- * - no transport logic
19
- * - no middleware ordering
20
- * - no policy evaluation
25
+ * Guarantees:
26
+ * - configured strategies are registered exactly once
27
+ * - configured policies are registered exactly once
28
+ * - authentication middleware is installed in the `auth` zone
29
+ * - an `AuthEventSink` is always available
21
30
  *
22
- * Identity repositories, credentials and strategy-specific services are
23
- * application concerns and must be supplied outside this module.
31
+ * Non-responsibilities:
32
+ * - credential persistence
33
+ * - authentication implementations
34
+ * - authorization decisions
35
+ * - user management
24
36
  */
25
37
  export class AuthModule {
26
38
  constructor(config = {}) {
@@ -51,9 +63,11 @@ export class AuthModule {
51
63
  ];
52
64
  }
53
65
  /**
54
- * Registers all configured authentication strategies.
66
+ * Registers authentication runtime components.
55
67
  *
56
- * Called once during app startup.
68
+ * 1. Registers authentication strategies.
69
+ * 2️. Registers authorization policies.
70
+ * 3️. Installs the authentication middleware.
57
71
  */
58
72
  async register(ioc) {
59
73
  const registry = ioc.get(AUTH_TOKENS.StrategyRegistry);
@@ -1 +1 @@
1
- {"version":3,"file":"auth-module.js","sourceRoot":"","sources":["../../src/runtime/auth-module.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAuC,MAAM,kBAAkB,CAAC;AAEvF,OAAO,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAE7C,OAAO,EACL,iBAAiB,GAKlB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EACL,oBAAoB,EACpB,2BAA2B,EAC3B,oBAAoB,GACrB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AA4B5C;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,OAAO,UAAU;IAUrB,YAA6B,SAA2B,EAAE;QAA7B,WAAM,GAAN,MAAM,CAAuB;QATjD,aAAQ,GAAG,cAAc,CAAC,IAAI,CAAC;QAUtC,MAAM,SAAS,GAAG,MAAM,CAAC,MAAM,CAAC;QAChC,IAAI,CAAC,SAAS,GAAG;YACf;gBACE,OAAO,EAAE,WAAW,CAAC,gBAAgB;gBACrC,QAAQ,EAAE,oBAAoB;gBAC9B,SAAS,E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I,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,MAAM,CAAC,UAAU,CAAC,GAAG,CAAC,CACtD,CAAC;QACJ,CAAC;QAED,kCAAkC;QAClC,MAAM,KAAK,GAAG,GAAG,CAAC,GAAG,CAAqB,MAAM,CAAC,kBAAkB,CAAC,CAAC;QACrE,KAAK,CAAC,GAAG,CAAC,oBAAoB,CAAC,QAAQ,EAAE,QAAQ,EAAE,MAAM,CAAC,EAAE;YAC1D,IAAI,EAAE,MAAM;YACZ,QAAQ,EAAE,CAAC;SACZ,CAAC,CAAC;IACL,CAAC;CACF"}
@@ -2,24 +2,41 @@ import type { AuthStrategy } from '../domain/index.js';
2
2
  /**
3
3
  * ## AuthStrategyRegistry
4
4
  *
5
- * Holds named authentication strategies (e.g. `jwt`, `apikey`, `session`).
6
- * Strategies are resolved by middleware per request.
5
+ * Stores authentication strategies by name.
6
+ *
7
+ * Responsibilities:
8
+ * - register authentication strategies during application startup
9
+ * - resolve strategies by name during request processing
10
+ * - allow strategies to be replaced or removed if required
11
+ *
12
+ * Guarantees:
13
+ * - at most one strategy exists for a given name
14
+ * - registering an existing name replaces the previous strategy
15
+ *
16
+ * Non-responsibilities:
17
+ * - strategy execution
18
+ * - authentication orchestration
19
+ * - request handling
7
20
  */
8
21
  export declare class AuthStrategyRegistry {
9
22
  private readonly strategies;
10
23
  /**
11
- * Registers a new authentication strategy.
24
+ * Registers or replaces an authentication strategy.
12
25
  *
13
- * @param name - Strategy identifier (e.g. "jwt", "apikey").
14
- * @param strategy - Implementation of {@link AuthStrategy}.
26
+ * @param name Strategy identifier.
27
+ * @param strategy Authentication strategy implementation.
15
28
  */
16
29
  register(name: string, strategy: AuthStrategy): void;
17
30
  /**
18
- * Returns a strategy by name, if registered.
31
+ * Returns the strategy registered under the specified name.
32
+ *
33
+ * @param name Strategy identifier.
19
34
  */
20
35
  get(name: string): AuthStrategy | undefined;
21
36
  /**
22
- * Removes a strategy (rarely used).
37
+ * Removes the strategy associated with the specified name.
38
+ *
39
+ * @param name Strategy identifier.
23
40
  */
24
41
  unregister(name: string): void;
25
42
  }