@zudojs/auth 1.0.0 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (31) hide show
  1. package/README.md +54 -10
  2. package/dist/authErrors/authError.base.d.ts +6 -25
  3. package/dist/authErrors/authError.base.js +6 -20
  4. package/dist/authPassword/authPassword.core.d.ts +17 -29
  5. package/dist/authPassword/authPassword.core.js +33 -119
  6. package/dist/authPassword/authPassword.legacy.d.ts +21 -0
  7. package/dist/authPassword/authPassword.legacy.js +85 -0
  8. package/dist/authPassword/authPassword.policy.d.ts +30 -0
  9. package/dist/authPassword/authPassword.policy.js +30 -0
  10. package/dist/authPassword/authPassword.rehash.d.ts +15 -0
  11. package/dist/authPassword/authPassword.rehash.js +33 -0
  12. package/dist/authPassword/index.d.ts +3 -1
  13. package/dist/authPassword/index.js +3 -1
  14. package/dist/authProvider/authAttempt.eviction.d.ts +26 -0
  15. package/dist/authProvider/authAttempt.eviction.js +37 -0
  16. package/dist/authProvider/authAttempt.memory.d.ts +9 -0
  17. package/dist/authProvider/authAttempt.memory.js +22 -5
  18. package/dist/authProvider/authProvider.core.d.ts +13 -0
  19. package/dist/authProvider/authProvider.core.js +23 -45
  20. package/dist/authProvider/authProvider.throttle.d.ts +52 -0
  21. package/dist/authProvider/authProvider.throttle.js +88 -0
  22. package/dist/authSession/authSession.core.d.ts +7 -0
  23. package/dist/authSession/authSession.core.js +25 -4
  24. package/dist/authToken/authToken.core.d.ts +6 -0
  25. package/dist/authToken/authToken.core.js +8 -0
  26. package/dist/authToken/authToken.signing.d.ts +5 -0
  27. package/dist/authToken/authToken.signing.js +22 -2
  28. package/dist/authTypes/authAttempt.type.d.ts +18 -6
  29. package/dist/authUtils/authUtils.helper.d.ts +4 -0
  30. package/dist/authUtils/authUtils.helper.js +4 -0
  31. package/package.json +9 -4
@@ -17,9 +17,11 @@ export interface LoginAttemptRecord {
17
17
  /**
18
18
  * Store backing failed-attempt lockout and login rate limiting.
19
19
  *
20
- * Keys are the *submitted* identifier, not a resolved user id, so unknown
21
- * and known accounts are throttled identically and the endpoint stays free
22
- * of an existence oracle. The in-memory implementation
20
+ * Keys are the *submitted* identifier — trimmed, NFKC-normalised and
21
+ * lower-cased by `createAuthService()` so that case and whitespace variants
22
+ * of one email share a budget — not a resolved user id, so unknown and
23
+ * known accounts are throttled identically and the endpoint stays free of
24
+ * an existence oracle. The in-memory implementation
23
25
  * (`createMemoryLoginAttemptStore`) is per-process; back this with Redis to
24
26
  * make limits hold across instances.
25
27
  */
@@ -28,7 +30,11 @@ export interface LoginAttemptStore {
28
30
  get(identifier: string): Promise<LoginAttemptRecord>;
29
31
  /** Count an attempt (before credentials are checked). */
30
32
  recordAttempt(identifier: string): Promise<LoginAttemptRecord>;
31
- /** Count a failed authentication. */
33
+ /**
34
+ * Count a failed authentication. Must be atomic: `createAuthService()`
35
+ * reserves a failure *before* checking the password and relies on
36
+ * concurrent calls seeing distinct, increasing counts.
37
+ */
32
38
  recordFailure(identifier: string): Promise<LoginAttemptRecord>;
33
39
  /** Lock an identifier until `until` (Unix milliseconds). */
34
40
  lock(identifier: string, until: number): Promise<void>;
@@ -50,8 +56,14 @@ export interface LoginThrottleConfig {
50
56
  readonly lockoutSeconds?: number;
51
57
  /**
52
58
  * Attempts allowed per identifier inside the store's rate-limit window
53
- * (default: 20). Exceeding it throws `AuthRateLimitError`. This bounds the
54
- * scrypt work an attacker can force the server to perform.
59
+ * (default: 20). Exceeding it throws `AuthRateLimitError`.
60
+ *
61
+ * This is a *per-identifier* budget: it bounds the password guesses
62
+ * against one account, not the scrypt work the server can be made to do.
63
+ * Every new identifier starts with a fresh budget, and unknown identifiers
64
+ * still burn a full scrypt verification, so an attacker rotating
65
+ * identifiers is not limited by it. Put a per-IP limiter (for example
66
+ * `createRateLimiter` from `@zudojs/security`) in front of `login()`.
55
67
  */
56
68
  readonly maxAttemptsPerWindow?: number;
57
69
  /**
@@ -55,6 +55,10 @@ export declare function extractUserId(token: unknown): string | null;
55
55
  /**
56
56
  * Generate a CSRF token.
57
57
  *
58
+ * @deprecated This returns an unbound random value that nothing in the
59
+ * framework can validate. Use `generateCsrfToken` / `validateCsrfToken`
60
+ * (or `createCsrfProtection`) from `@zudojs/security`, which produce
61
+ * session-bound, HMAC-signed tokens.
58
62
  * @returns Random hex string for CSRF protection
59
63
  */
60
64
  export declare function generateCsrfToken(): string;
@@ -115,6 +115,10 @@ export function extractUserId(token) {
115
115
  /**
116
116
  * Generate a CSRF token.
117
117
  *
118
+ * @deprecated This returns an unbound random value that nothing in the
119
+ * framework can validate. Use `generateCsrfToken` / `validateCsrfToken`
120
+ * (or `createCsrfProtection`) from `@zudojs/security`, which produce
121
+ * session-bound, HMAC-signed tokens.
118
122
  * @returns Random hex string for CSRF protection
119
123
  */
120
124
  export function generateCsrfToken() {
package/package.json CHANGED
@@ -1,8 +1,12 @@
1
1
  {
2
2
  "name": "@zudojs/auth",
3
- "version": "1.0.0",
3
+ "version": "1.2.0",
4
4
  "description": "Authentication and authorization services for the Zudojs framework — JWT, sessions, RBAC, and password management.",
5
5
  "license": "MIT",
6
+ "author": {
7
+ "name": "Oluwayemi Oyinlola",
8
+ "url": "https://github.com/oyinlola-tech"
9
+ },
6
10
  "type": "module",
7
11
  "main": "./dist/index.js",
8
12
  "module": "./dist/index.js",
@@ -21,9 +25,10 @@
21
25
  "!dist/.tsbuildinfo"
22
26
  ],
23
27
  "dependencies": {
24
- "@zudojs/errors": "1.0.0",
25
- "@zudojs/constants": "1.0.0",
26
- "@zudojs/permissions": "1.0.0"
28
+ "@zudojs/constants": "1.1.0",
29
+ "@zudojs/crypto": "1.2.0",
30
+ "@zudojs/errors": "1.1.0",
31
+ "@zudojs/permissions": "1.2.0"
27
32
  },
28
33
  "engines": {
29
34
  "node": ">=24.0.0"