@webda/auth 0.0.0-stage → 4.0.0-beta.11

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 (77) hide show
  1. package/LICENSE +166 -0
  2. package/README.md +59 -2
  3. package/lib/authentication.service.d.ts +322 -0
  4. package/lib/authentication.service.d.ts.map +1 -0
  5. package/lib/authentication.service.js +978 -0
  6. package/lib/authentication.service.js.map +1 -0
  7. package/lib/certificate/certificate.service.d.ts +139 -0
  8. package/lib/certificate/certificate.service.d.ts.map +1 -0
  9. package/lib/certificate/certificate.service.js +343 -0
  10. package/lib/certificate/certificate.service.js.map +1 -0
  11. package/lib/compat/upgrade.d.ts +71 -0
  12. package/lib/compat/upgrade.d.ts.map +1 -0
  13. package/lib/compat/upgrade.js +200 -0
  14. package/lib/compat/upgrade.js.map +1 -0
  15. package/lib/email/emailpassword.service.d.ts +249 -0
  16. package/lib/email/emailpassword.service.d.ts.map +1 -0
  17. package/lib/email/emailpassword.service.js +714 -0
  18. package/lib/email/emailpassword.service.js.map +1 -0
  19. package/lib/email/tokens.d.ts +36 -0
  20. package/lib/email/tokens.d.ts.map +1 -0
  21. package/lib/email/tokens.js +46 -0
  22. package/lib/email/tokens.js.map +1 -0
  23. package/lib/errors.d.ts +53 -0
  24. package/lib/errors.d.ts.map +1 -0
  25. package/lib/errors.js +74 -0
  26. package/lib/errors.js.map +1 -0
  27. package/lib/index.d.ts +12 -0
  28. package/lib/index.d.ts.map +1 -0
  29. package/lib/index.js +12 -0
  30. package/lib/index.js.map +1 -0
  31. package/lib/mfa/secondfactor.service.d.ts +44 -0
  32. package/lib/mfa/secondfactor.service.d.ts.map +1 -0
  33. package/lib/mfa/secondfactor.service.js +38 -0
  34. package/lib/mfa/secondfactor.service.js.map +1 -0
  35. package/lib/mfa/totp.service.d.ts +41 -0
  36. package/lib/mfa/totp.service.d.ts.map +1 -0
  37. package/lib/mfa/totp.service.js +63 -0
  38. package/lib/mfa/totp.service.js.map +1 -0
  39. package/lib/oauth/oauth.service.d.ts +296 -0
  40. package/lib/oauth/oauth.service.d.ts.map +1 -0
  41. package/lib/oauth/oauth.service.js +560 -0
  42. package/lib/oauth/oauth.service.js.map +1 -0
  43. package/lib/provider.d.ts +53 -0
  44. package/lib/provider.d.ts.map +1 -0
  45. package/lib/provider.js +55 -0
  46. package/lib/provider.js.map +1 -0
  47. package/lib/test/authtest.d.ts +39 -0
  48. package/lib/test/authtest.d.ts.map +1 -0
  49. package/lib/test/authtest.js +62 -0
  50. package/lib/test/authtest.js.map +1 -0
  51. package/lib/test/emailtest.d.ts +25 -0
  52. package/lib/test/emailtest.d.ts.map +1 -0
  53. package/lib/test/emailtest.js +42 -0
  54. package/lib/test/emailtest.js.map +1 -0
  55. package/lib/test/fakeoauth.service.d.ts +45 -0
  56. package/lib/test/fakeoauth.service.d.ts.map +1 -0
  57. package/lib/test/fakeoauth.service.js +78 -0
  58. package/lib/test/fakeoauth.service.js.map +1 -0
  59. package/lib/test/mfauser.fixture.model.d.ts +11 -0
  60. package/lib/test/mfauser.fixture.model.d.ts.map +1 -0
  61. package/lib/test/mfauser.fixture.model.js +44 -0
  62. package/lib/test/mfauser.fixture.model.js.map +1 -0
  63. package/lib/test/stubprovider.d.ts +35 -0
  64. package/lib/test/stubprovider.d.ts.map +1 -0
  65. package/lib/test/stubprovider.js +46 -0
  66. package/lib/test/stubprovider.js.map +1 -0
  67. package/lib/test/v3.d.ts +29 -0
  68. package/lib/test/v3.d.ts.map +1 -0
  69. package/lib/test/v3.js +47 -0
  70. package/lib/test/v3.js.map +1 -0
  71. package/lib/throttle.d.ts +41 -0
  72. package/lib/throttle.d.ts.map +1 -0
  73. package/lib/throttle.js +49 -0
  74. package/lib/throttle.js.map +1 -0
  75. package/package.json +69 -3
  76. package/test/config.json +23 -0
  77. package/webda.module.json +891 -0
@@ -0,0 +1,41 @@
1
+ import type { Ident, IdentThrottle } from "@webda/core";
2
+ export { countAttempt, type ThrottleParameters } from "@webda/core";
3
+ /** Login failure state of an ident: its top-level `_loginAttempts` / `_lastLoginAttemptAt` attributes */
4
+ export type LoginAttempts = Pick<Ident, "_loginAttempts" | "_lastLoginAttemptAt">;
5
+ /**
6
+ * Check if an ident is locked due to too many failed logins
7
+ * @param s - login failure state (an ident)
8
+ * @param failedBefore - failures before locking
9
+ * @param lockoutMs - lock duration after the last attempt
10
+ * @param now - clock
11
+ * @returns true while locked
12
+ */
13
+ export declare function isLocked(s: LoginAttempts, failedBefore: number, lockoutMs: number, now?: number): boolean;
14
+ /**
15
+ * Record a failure in the login failure state
16
+ * @param s - login failure state
17
+ * @param now - clock
18
+ * @returns state with one more failure
19
+ */
20
+ export declare function recordFailure(s: LoginAttempts, now?: number): LoginAttempts;
21
+ /**
22
+ * Clear all login failures
23
+ * @returns state with failures cleared
24
+ */
25
+ export declare function resetFailures(): LoginAttempts;
26
+ /**
27
+ * Check if a message can be sent based on throttle delay
28
+ * @param t - throttle state
29
+ * @param delayMs - minimal delay between two emails
30
+ * @param now - clock
31
+ * @returns true when an email may be sent
32
+ */
33
+ export declare function canSend(t: IdentThrottle | undefined, delayMs: number, now?: number): boolean;
34
+ /**
35
+ * Mark that a message was sent
36
+ * @param t - throttle state
37
+ * @param now - clock
38
+ * @returns state with the send timestamp set
39
+ */
40
+ export declare function markSent(t: IdentThrottle | undefined, now?: number): IdentThrottle;
41
+ //# sourceMappingURL=throttle.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"throttle.d.ts","sourceRoot":"","sources":["../src/throttle.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAExD,OAAO,EAAE,YAAY,EAAE,KAAK,kBAAkB,EAAE,MAAM,aAAa,CAAC;AAEpE,yGAAyG;AACzG,MAAM,MAAM,aAAa,GAAG,IAAI,CAAC,KAAK,EAAE,gBAAgB,GAAG,qBAAqB,CAAC,CAAC;AAElF;;;;;;;GAOG;AACH,wBAAgB,QAAQ,CAAC,CAAC,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,GAAG,GAAE,MAAmB,GAAG,OAAO,CAErH;AAED;;;;;GAKG;AACH,wBAAgB,aAAa,CAAC,CAAC,EAAE,aAAa,EAAE,GAAG,GAAE,MAAmB,GAAG,aAAa,CAEvF;AAED;;;GAGG;AACH,wBAAgB,aAAa,IAAI,aAAa,CAE7C;AAED;;;;;;GAMG;AACH,wBAAgB,OAAO,CAAC,CAAC,EAAE,aAAa,GAAG,SAAS,EAAE,OAAO,EAAE,MAAM,EAAE,GAAG,GAAE,MAAmB,GAAG,OAAO,CAExG;AAED;;;;;GAKG;AACH,wBAAgB,QAAQ,CAAC,CAAC,EAAE,aAAa,GAAG,SAAS,EAAE,GAAG,GAAE,MAAmB,GAAG,aAAa,CAE9F"}
@@ -0,0 +1,49 @@
1
+ // Generic attempt counting lives in core, shared with the MFA behavior
2
+ export { countAttempt } from "@webda/core";
3
+ /**
4
+ * Check if an ident is locked due to too many failed logins
5
+ * @param s - login failure state (an ident)
6
+ * @param failedBefore - failures before locking
7
+ * @param lockoutMs - lock duration after the last attempt
8
+ * @param now - clock
9
+ * @returns true while locked
10
+ */
11
+ export function isLocked(s, failedBefore, lockoutMs, now = Date.now()) {
12
+ return !!s && (s._loginAttempts ?? 0) >= failedBefore && (s._lastLoginAttemptAt ?? 0) + lockoutMs > now;
13
+ }
14
+ /**
15
+ * Record a failure in the login failure state
16
+ * @param s - login failure state
17
+ * @param now - clock
18
+ * @returns state with one more failure
19
+ */
20
+ export function recordFailure(s, now = Date.now()) {
21
+ return { _loginAttempts: (s?._loginAttempts ?? 0) + 1, _lastLoginAttemptAt: now };
22
+ }
23
+ /**
24
+ * Clear all login failures
25
+ * @returns state with failures cleared
26
+ */
27
+ export function resetFailures() {
28
+ return { _loginAttempts: 0, _lastLoginAttemptAt: undefined };
29
+ }
30
+ /**
31
+ * Check if a message can be sent based on throttle delay
32
+ * @param t - throttle state
33
+ * @param delayMs - minimal delay between two emails
34
+ * @param now - clock
35
+ * @returns true when an email may be sent
36
+ */
37
+ export function canSend(t, delayMs, now = Date.now()) {
38
+ return !t?.lastSentAt || t.lastSentAt + delayMs < now;
39
+ }
40
+ /**
41
+ * Mark that a message was sent
42
+ * @param t - throttle state
43
+ * @param now - clock
44
+ * @returns state with the send timestamp set
45
+ */
46
+ export function markSent(t, now = Date.now()) {
47
+ return { ...(t ?? {}), lastSentAt: now };
48
+ }
49
+ //# sourceMappingURL=throttle.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"throttle.js","sourceRoot":"","sources":["../src/throttle.ts"],"names":[],"mappings":"AACA,uEAAuE;AACvE,OAAO,EAAE,YAAY,EAA2B,MAAM,aAAa,CAAC;AAKpE;;;;;;;GAOG;AACH,MAAM,UAAU,QAAQ,CAAC,CAAgB,EAAE,YAAoB,EAAE,SAAiB,EAAE,GAAG,GAAW,IAAI,CAAC,GAAG,EAAE;IAC1G,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,cAAc,IAAI,CAAC,CAAC,IAAI,YAAY,IAAI,CAAC,CAAC,CAAC,mBAAmB,IAAI,CAAC,CAAC,GAAG,SAAS,GAAG,GAAG,CAAC;AAC1G,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,aAAa,CAAC,CAAgB,EAAE,GAAG,GAAW,IAAI,CAAC,GAAG,EAAE;IACtE,OAAO,EAAE,cAAc,EAAE,CAAC,CAAC,EAAE,cAAc,IAAI,CAAC,CAAC,GAAG,CAAC,EAAE,mBAAmB,EAAE,GAAG,EAAE,CAAC;AACpF,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,aAAa;IAC3B,OAAO,EAAE,cAAc,EAAE,CAAC,EAAE,mBAAmB,EAAE,SAAS,EAAE,CAAC;AAC/D,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,OAAO,CAAC,CAA4B,EAAE,OAAe,EAAE,GAAG,GAAW,IAAI,CAAC,GAAG,EAAE;IAC7F,OAAO,CAAC,CAAC,EAAE,UAAU,IAAI,CAAC,CAAC,UAAU,GAAG,OAAO,GAAG,GAAG,CAAC;AACxD,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,QAAQ,CAAC,CAA4B,EAAE,GAAG,GAAW,IAAI,CAAC,GAAG,EAAE;IAC7E,OAAO,EAAE,GAAG,CAAC,CAAC,IAAI,EAAE,CAAC,EAAE,UAAU,EAAE,GAAG,EAAE,CAAC;AAC3C,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,72 @@
1
1
  {
2
2
  "name": "@webda/auth",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "version": "4.0.0-beta.11",
4
+ "description": "Authentication service and providers for Webda",
5
+ "keywords": [
6
+ "authentication",
7
+ "auth",
8
+ "webda"
9
+ ],
10
+ "author": "Remi Cattiau <remi@cattiau.com>",
11
+ "repository": {
12
+ "type": "git",
13
+ "url": "git+https://github.com/loopingz/webda.io.git",
14
+ "directory": "packages/auth"
15
+ },
16
+ "main": "lib/index.js",
17
+ "typings": "lib/index.d.ts",
18
+ "dependencies": {
19
+ "@webda/core": "4.0.0-beta.11",
20
+ "@webda/utils": "4.0.0-beta.10",
21
+ "@webda/workout": "4.0.0-beta.5",
22
+ "@webda/models": "4.0.0-beta.11"
23
+ },
24
+ "files": [
25
+ "lib",
26
+ "test",
27
+ "webda.module.json"
28
+ ],
29
+ "homepage": "https://webda.io",
30
+ "publishConfig": {
31
+ "access": "public"
32
+ },
33
+ "webda": {
34
+ "namespace": "Webda"
35
+ },
36
+ "devDependencies": {
37
+ "@types/node": "25.5.0",
38
+ "@vitest/coverage-v8": "^4.1.2",
39
+ "jscodeshift": "^17.3.0",
40
+ "skott": "^0.35.8",
41
+ "tsx": "^4.21.0",
42
+ "typescript": "7.1.0-dev.20260929.1",
43
+ "vite": "^6.0.0",
44
+ "vitest": "^4.1.2",
45
+ "@webda/content-mapper": "^4.0.0-beta.9",
46
+ "@webda/fs": "4.0.0-beta.11",
47
+ "@webda/test": "4.0.0-beta.7",
48
+ "@webda/compiler": "^4.0.0-beta.11"
49
+ },
50
+ "type": "module",
51
+ "engines": {
52
+ "node": ">=22.0.0"
53
+ },
54
+ "nx": {
55
+ "implicitDependencies": [
56
+ "@webda/core"
57
+ ]
58
+ },
59
+ "license": "LGPL-3.0-only",
60
+ "scripts": {
61
+ "build": "webdac build",
62
+ "build:watch": "webdac build --watch",
63
+ "pretest": "npm run build",
64
+ "lint": "eslint",
65
+ "lint:fix": "eslint --fix",
66
+ "test": "vitest run",
67
+ "format": "prettier --check src/**/*",
68
+ "format:fix": "prettier --write src/**/*",
69
+ "deps:graph": "skott --showCircularDependencies --no-trackTypeOnlyDependencies --displayMode=raw -e .ts",
70
+ "codemod": "jscodeshift --parser=ts --extensions=tsx,ts -t ../codemod/current.mjs src"
71
+ }
6
72
  }
@@ -0,0 +1,23 @@
1
+ {
2
+ "version": 3,
3
+ "parameters": { "ignoreBeans": true },
4
+ "services": {
5
+ "AuthStore": {
6
+ "type": "Webda/MemoryStore",
7
+ "models": ["Webda/User", "Webda/Ident", "Webda/RefreshToken", "Webda/RevokedAccess"]
8
+ },
9
+ "DefinedMailer": { "type": "WebdaTest/Mailer" },
10
+ "Authentication": { "type": "Webda/Authentication" },
11
+ "googleStub": { "type": "WebdaTest/Stub_google" },
12
+ "emailAuth": {
13
+ "type": "Webda/EmailPasswordProvider",
14
+ "mailer": "DefinedMailer",
15
+ "redirects": {
16
+ "verified": "https://app/verified",
17
+ "failure": "https://app/failure",
18
+ "register": "https://app/register",
19
+ "recover": "https://app/recover"
20
+ }
21
+ }
22
+ }
23
+ }