@rapidrest/auth 1.0.0-beta.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.
Files changed (201) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +75 -0
  3. package/dist/lib/auth/BasicStrategy.js +82 -0
  4. package/dist/lib/auth/BasicStrategy.js.map +1 -0
  5. package/dist/lib/auth/FIDO2Strategy.js +179 -0
  6. package/dist/lib/auth/FIDO2Strategy.js.map +1 -0
  7. package/dist/lib/auth/MFAStrategy.js +219 -0
  8. package/dist/lib/auth/MFAStrategy.js.map +1 -0
  9. package/dist/lib/auth/OIDCStrategy.js +397 -0
  10. package/dist/lib/auth/OIDCStrategy.js.map +1 -0
  11. package/dist/lib/auth/OTPStrategy.js +143 -0
  12. package/dist/lib/auth/OTPStrategy.js.map +1 -0
  13. package/dist/lib/auth/PasskeyStrategy.js +185 -0
  14. package/dist/lib/auth/PasskeyStrategy.js.map +1 -0
  15. package/dist/lib/auth/TOTPStrategy.js +84 -0
  16. package/dist/lib/auth/TOTPStrategy.js.map +1 -0
  17. package/dist/lib/auth/index.js +10 -0
  18. package/dist/lib/auth/index.js.map +1 -0
  19. package/dist/lib/auth/shared.js +431 -0
  20. package/dist/lib/auth/shared.js.map +1 -0
  21. package/dist/lib/auth/types.js +12 -0
  22. package/dist/lib/auth/types.js.map +1 -0
  23. package/dist/lib/index.js +4 -0
  24. package/dist/lib/index.js.map +1 -0
  25. package/dist/lib/models/index.js +2 -0
  26. package/dist/lib/models/index.js.map +1 -0
  27. package/dist/lib/models/mongo/AliasMongo.js +77 -0
  28. package/dist/lib/models/mongo/AliasMongo.js.map +1 -0
  29. package/dist/lib/models/mongo/ProfileMongo.js +99 -0
  30. package/dist/lib/models/mongo/ProfileMongo.js.map +1 -0
  31. package/dist/lib/models/mongo/SecretMongo.js +71 -0
  32. package/dist/lib/models/mongo/SecretMongo.js.map +1 -0
  33. package/dist/lib/models/mongo/UserMongo.js +71 -0
  34. package/dist/lib/models/mongo/UserMongo.js.map +1 -0
  35. package/dist/lib/models/mongo/index.js +5 -0
  36. package/dist/lib/models/mongo/index.js.map +1 -0
  37. package/dist/lib/models/mongo.js +2 -0
  38. package/dist/lib/models/mongo.js.map +1 -0
  39. package/dist/lib/models/sql/AliasSQL.js +77 -0
  40. package/dist/lib/models/sql/AliasSQL.js.map +1 -0
  41. package/dist/lib/models/sql/ProfileSQL.js +99 -0
  42. package/dist/lib/models/sql/ProfileSQL.js.map +1 -0
  43. package/dist/lib/models/sql/SecretSQL.js +71 -0
  44. package/dist/lib/models/sql/SecretSQL.js.map +1 -0
  45. package/dist/lib/models/sql/UserSQL.js +68 -0
  46. package/dist/lib/models/sql/UserSQL.js.map +1 -0
  47. package/dist/lib/models/sql/index.js +5 -0
  48. package/dist/lib/models/sql/index.js.map +1 -0
  49. package/dist/lib/models/sql.js +2 -0
  50. package/dist/lib/models/sql.js.map +1 -0
  51. package/dist/lib/models/types.js +35 -0
  52. package/dist/lib/models/types.js.map +1 -0
  53. package/dist/lib/mongo.js +3 -0
  54. package/dist/lib/mongo.js.map +1 -0
  55. package/dist/lib/routes/BaseAliasRoute.js +10 -0
  56. package/dist/lib/routes/BaseAliasRoute.js.map +1 -0
  57. package/dist/lib/routes/BaseAuthBasicRoute.js +132 -0
  58. package/dist/lib/routes/BaseAuthBasicRoute.js.map +1 -0
  59. package/dist/lib/routes/BaseAuthFIDO2Route.js +191 -0
  60. package/dist/lib/routes/BaseAuthFIDO2Route.js.map +1 -0
  61. package/dist/lib/routes/BaseAuthMFARoute.js +310 -0
  62. package/dist/lib/routes/BaseAuthMFARoute.js.map +1 -0
  63. package/dist/lib/routes/BaseAuthOIDCRoute.js +231 -0
  64. package/dist/lib/routes/BaseAuthOIDCRoute.js.map +1 -0
  65. package/dist/lib/routes/BaseAuthOTPRoute.js +214 -0
  66. package/dist/lib/routes/BaseAuthOTPRoute.js.map +1 -0
  67. package/dist/lib/routes/BaseAuthPasskeyRoute.js +182 -0
  68. package/dist/lib/routes/BaseAuthPasskeyRoute.js.map +1 -0
  69. package/dist/lib/routes/BaseAuthTOTPRoute.js +133 -0
  70. package/dist/lib/routes/BaseAuthTOTPRoute.js.map +1 -0
  71. package/dist/lib/routes/BaseProfileRoute.js +10 -0
  72. package/dist/lib/routes/BaseProfileRoute.js.map +1 -0
  73. package/dist/lib/routes/BaseSecretRoute.js +399 -0
  74. package/dist/lib/routes/BaseSecretRoute.js.map +1 -0
  75. package/dist/lib/routes/BaseUserRoute.js +10 -0
  76. package/dist/lib/routes/BaseUserRoute.js.map +1 -0
  77. package/dist/lib/routes/UserUtils.js +78 -0
  78. package/dist/lib/routes/UserUtils.js.map +1 -0
  79. package/dist/lib/routes/index.js +13 -0
  80. package/dist/lib/routes/index.js.map +1 -0
  81. package/dist/lib/routes/mongo/BaseAliasRouteMongo.js +20 -0
  82. package/dist/lib/routes/mongo/BaseAliasRouteMongo.js.map +1 -0
  83. package/dist/lib/routes/mongo/BaseAuthBasicRouteMongo.js +14 -0
  84. package/dist/lib/routes/mongo/BaseAuthBasicRouteMongo.js.map +1 -0
  85. package/dist/lib/routes/mongo/BaseAuthFIDO2RouteMongo.js +14 -0
  86. package/dist/lib/routes/mongo/BaseAuthFIDO2RouteMongo.js.map +1 -0
  87. package/dist/lib/routes/mongo/BaseAuthMFARouteMongo.js +14 -0
  88. package/dist/lib/routes/mongo/BaseAuthMFARouteMongo.js.map +1 -0
  89. package/dist/lib/routes/mongo/BaseAuthOIDCRouteMongo.js +11 -0
  90. package/dist/lib/routes/mongo/BaseAuthOIDCRouteMongo.js.map +1 -0
  91. package/dist/lib/routes/mongo/BaseAuthOTPRouteMongo.js +14 -0
  92. package/dist/lib/routes/mongo/BaseAuthOTPRouteMongo.js.map +1 -0
  93. package/dist/lib/routes/mongo/BaseAuthPasskeyRouteMongo.js +14 -0
  94. package/dist/lib/routes/mongo/BaseAuthPasskeyRouteMongo.js.map +1 -0
  95. package/dist/lib/routes/mongo/BaseAuthTOTPRouteMongo.js +14 -0
  96. package/dist/lib/routes/mongo/BaseAuthTOTPRouteMongo.js.map +1 -0
  97. package/dist/lib/routes/mongo/BaseProfileRouteMongo.js +20 -0
  98. package/dist/lib/routes/mongo/BaseProfileRouteMongo.js.map +1 -0
  99. package/dist/lib/routes/mongo/BaseSecretRouteMongo.js +20 -0
  100. package/dist/lib/routes/mongo/BaseSecretRouteMongo.js.map +1 -0
  101. package/dist/lib/routes/mongo/BaseUserRouteMongo.js +20 -0
  102. package/dist/lib/routes/mongo/BaseUserRouteMongo.js.map +1 -0
  103. package/dist/lib/routes/mongo/index.js +12 -0
  104. package/dist/lib/routes/mongo/index.js.map +1 -0
  105. package/dist/lib/routes/mongo.js +2 -0
  106. package/dist/lib/routes/mongo.js.map +1 -0
  107. package/dist/lib/routes/sql/BaseAliasRouteSQL.js +20 -0
  108. package/dist/lib/routes/sql/BaseAliasRouteSQL.js.map +1 -0
  109. package/dist/lib/routes/sql/BaseAuthBasicRouteSQL.js +14 -0
  110. package/dist/lib/routes/sql/BaseAuthBasicRouteSQL.js.map +1 -0
  111. package/dist/lib/routes/sql/BaseAuthFIDO2RouteSQL.js +14 -0
  112. package/dist/lib/routes/sql/BaseAuthFIDO2RouteSQL.js.map +1 -0
  113. package/dist/lib/routes/sql/BaseAuthMFARouteSQL.js +14 -0
  114. package/dist/lib/routes/sql/BaseAuthMFARouteSQL.js.map +1 -0
  115. package/dist/lib/routes/sql/BaseAuthOIDCRouteSQL.js +11 -0
  116. package/dist/lib/routes/sql/BaseAuthOIDCRouteSQL.js.map +1 -0
  117. package/dist/lib/routes/sql/BaseAuthOTPRouteSQL.js +14 -0
  118. package/dist/lib/routes/sql/BaseAuthOTPRouteSQL.js.map +1 -0
  119. package/dist/lib/routes/sql/BaseAuthPasskeyRouteSQL.js +14 -0
  120. package/dist/lib/routes/sql/BaseAuthPasskeyRouteSQL.js.map +1 -0
  121. package/dist/lib/routes/sql/BaseAuthTOTPRouteSQL.js +14 -0
  122. package/dist/lib/routes/sql/BaseAuthTOTPRouteSQL.js.map +1 -0
  123. package/dist/lib/routes/sql/BaseProfileRouteSQL.js +20 -0
  124. package/dist/lib/routes/sql/BaseProfileRouteSQL.js.map +1 -0
  125. package/dist/lib/routes/sql/BaseSecretRouteSQL.js +20 -0
  126. package/dist/lib/routes/sql/BaseSecretRouteSQL.js.map +1 -0
  127. package/dist/lib/routes/sql/BaseUserRouteSQL.js +20 -0
  128. package/dist/lib/routes/sql/BaseUserRouteSQL.js.map +1 -0
  129. package/dist/lib/routes/sql/index.js +12 -0
  130. package/dist/lib/routes/sql/index.js.map +1 -0
  131. package/dist/lib/routes/sql.js +2 -0
  132. package/dist/lib/routes/sql.js.map +1 -0
  133. package/dist/lib/sql.js +3 -0
  134. package/dist/lib/sql.js.map +1 -0
  135. package/dist/types/auth/BasicStrategy.d.ts +39 -0
  136. package/dist/types/auth/FIDO2Strategy.d.ts +85 -0
  137. package/dist/types/auth/MFAStrategy.d.ts +110 -0
  138. package/dist/types/auth/OIDCStrategy.d.ts +188 -0
  139. package/dist/types/auth/OTPStrategy.d.ts +88 -0
  140. package/dist/types/auth/PasskeyStrategy.d.ts +81 -0
  141. package/dist/types/auth/TOTPStrategy.d.ts +49 -0
  142. package/dist/types/auth/index.d.ts +9 -0
  143. package/dist/types/auth/shared.d.ts +136 -0
  144. package/dist/types/auth/types.d.ts +127 -0
  145. package/dist/types/index.d.ts +3 -0
  146. package/dist/types/models/index.d.ts +1 -0
  147. package/dist/types/models/mongo/AliasMongo.d.ts +15 -0
  148. package/dist/types/models/mongo/ProfileMongo.d.ts +17 -0
  149. package/dist/types/models/mongo/SecretMongo.d.ts +14 -0
  150. package/dist/types/models/mongo/UserMongo.d.ts +14 -0
  151. package/dist/types/models/mongo/index.d.ts +4 -0
  152. package/dist/types/models/mongo.d.ts +1 -0
  153. package/dist/types/models/sql/AliasSQL.d.ts +15 -0
  154. package/dist/types/models/sql/ProfileSQL.d.ts +17 -0
  155. package/dist/types/models/sql/SecretSQL.d.ts +14 -0
  156. package/dist/types/models/sql/UserSQL.d.ts +14 -0
  157. package/dist/types/models/sql/index.d.ts +4 -0
  158. package/dist/types/models/sql.d.ts +1 -0
  159. package/dist/types/models/types.d.ts +136 -0
  160. package/dist/types/mongo.d.ts +2 -0
  161. package/dist/types/routes/BaseAliasRoute.d.ts +7 -0
  162. package/dist/types/routes/BaseAuthBasicRoute.d.ts +27 -0
  163. package/dist/types/routes/BaseAuthFIDO2Route.d.ts +50 -0
  164. package/dist/types/routes/BaseAuthMFARoute.d.ts +61 -0
  165. package/dist/types/routes/BaseAuthOIDCRoute.d.ts +33 -0
  166. package/dist/types/routes/BaseAuthOTPRoute.d.ts +53 -0
  167. package/dist/types/routes/BaseAuthPasskeyRoute.d.ts +41 -0
  168. package/dist/types/routes/BaseAuthTOTPRoute.d.ts +38 -0
  169. package/dist/types/routes/BaseProfileRoute.d.ts +7 -0
  170. package/dist/types/routes/BaseSecretRoute.d.ts +89 -0
  171. package/dist/types/routes/BaseUserRoute.d.ts +7 -0
  172. package/dist/types/routes/UserUtils.d.ts +21 -0
  173. package/dist/types/routes/index.d.ts +12 -0
  174. package/dist/types/routes/mongo/BaseAliasRouteMongo.d.ts +4 -0
  175. package/dist/types/routes/mongo/BaseAuthBasicRouteMongo.d.ts +7 -0
  176. package/dist/types/routes/mongo/BaseAuthFIDO2RouteMongo.d.ts +7 -0
  177. package/dist/types/routes/mongo/BaseAuthMFARouteMongo.d.ts +7 -0
  178. package/dist/types/routes/mongo/BaseAuthOIDCRouteMongo.d.ts +7 -0
  179. package/dist/types/routes/mongo/BaseAuthOTPRouteMongo.d.ts +7 -0
  180. package/dist/types/routes/mongo/BaseAuthPasskeyRouteMongo.d.ts +7 -0
  181. package/dist/types/routes/mongo/BaseAuthTOTPRouteMongo.d.ts +7 -0
  182. package/dist/types/routes/mongo/BaseProfileRouteMongo.d.ts +4 -0
  183. package/dist/types/routes/mongo/BaseSecretRouteMongo.d.ts +4 -0
  184. package/dist/types/routes/mongo/BaseUserRouteMongo.d.ts +4 -0
  185. package/dist/types/routes/mongo/index.d.ts +11 -0
  186. package/dist/types/routes/mongo.d.ts +1 -0
  187. package/dist/types/routes/sql/BaseAliasRouteSQL.d.ts +4 -0
  188. package/dist/types/routes/sql/BaseAuthBasicRouteSQL.d.ts +7 -0
  189. package/dist/types/routes/sql/BaseAuthFIDO2RouteSQL.d.ts +7 -0
  190. package/dist/types/routes/sql/BaseAuthMFARouteSQL.d.ts +7 -0
  191. package/dist/types/routes/sql/BaseAuthOIDCRouteSQL.d.ts +7 -0
  192. package/dist/types/routes/sql/BaseAuthOTPRouteSQL.d.ts +7 -0
  193. package/dist/types/routes/sql/BaseAuthPasskeyRouteSQL.d.ts +7 -0
  194. package/dist/types/routes/sql/BaseAuthTOTPRouteSQL.d.ts +7 -0
  195. package/dist/types/routes/sql/BaseProfileRouteSQL.d.ts +4 -0
  196. package/dist/types/routes/sql/BaseSecretRouteSQL.d.ts +4 -0
  197. package/dist/types/routes/sql/BaseUserRouteSQL.d.ts +4 -0
  198. package/dist/types/routes/sql/index.d.ts +11 -0
  199. package/dist/types/routes/sql.d.ts +1 -0
  200. package/dist/types/sql.d.ts +2 -0
  201. package/package.json +138 -0
@@ -0,0 +1,41 @@
1
+ import { JWTUser, MessagingUtils } from "@rapidrest/core";
2
+ import { RepoUtils, AuthMiddleware, ObjectFactory } from "@rapidrest/service-core";
3
+ import { Alias, AuthResult, Secret, User } from "../models/types.js";
4
+ import { PasskeyConfig, StoredPasskeyCredential } from "../auth/types.js";
5
+ import { UserUtils } from "./UserUtils.js";
6
+ /**
7
+ *
8
+ *
9
+ * @author Jean-Philippe Steinmetz
10
+ */
11
+ export declare abstract class BaseAuthPasskeyRoute<U extends User, A extends Alias, S extends Secret> {
12
+ protected abstract aliasClass: any;
13
+ protected abstract secretClass: any;
14
+ protected abstract userClass: any;
15
+ protected aliasRepo?: RepoUtils<A>;
16
+ protected authMiddleware?: AuthMiddleware;
17
+ protected jwtConfig?: any;
18
+ protected objectFactory?: ObjectFactory;
19
+ protected messagingUtils?: MessagingUtils;
20
+ protected secretRepo?: RepoUtils<S>;
21
+ protected passkeyConfig: PasskeyConfig;
22
+ protected userRepo?: RepoUtils<U>;
23
+ protected userUtils?: UserUtils<U, A>;
24
+ /**
25
+ * Called on server startup to initialize the route with any defaults.
26
+ */
27
+ protected initialize(): Promise<void>;
28
+ /**
29
+ * Authenticates the user using Passkey and returns a JSON Web Token access token to be used with future API requests.
30
+ */
31
+ authenticate(user: JWTUser): Promise<AuthResult | undefined>;
32
+ protected getCredentialById(credentialId: string): Promise<StoredPasskeyCredential | undefined>;
33
+ protected getCredentials(id: string): Promise<StoredPasskeyCredential[]>;
34
+ /**
35
+ * Retrieve the user associated with a given uid or alias.
36
+ *
37
+ * @param id The unqique id of the user or alias to lookup.
38
+ */
39
+ protected getUser(id: string): Promise<JWTUser | undefined>;
40
+ protected updateCredentialCounter(credentialId: string, newCounter: number): Promise<void>;
41
+ }
@@ -0,0 +1,38 @@
1
+ import { JWTUser, MessagingUtils } from "@rapidrest/core";
2
+ import { RepoUtils, AuthMiddleware, ObjectFactory } from "@rapidrest/service-core";
3
+ import { Alias, AuthResult, Secret, User } from "../models/types.js";
4
+ import { TOTPSecret } from "../auth/types.js";
5
+ import { UserUtils } from "./UserUtils.js";
6
+ /**
7
+ *
8
+ *
9
+ * @author Jean-Philippe Steinmetz
10
+ */
11
+ export declare abstract class BaseAuthTOTPRoute<U extends User, A extends Alias, S extends Secret> {
12
+ protected abstract aliasClass: any;
13
+ protected abstract secretClass: any;
14
+ protected abstract userClass: any;
15
+ protected authMiddleware?: AuthMiddleware;
16
+ protected jwtConfig?: any;
17
+ protected objectFactory?: ObjectFactory;
18
+ protected messagingUtils?: MessagingUtils;
19
+ protected secretRepo?: RepoUtils<S>;
20
+ /** The name of the messaging template to use for sending notifications. */
21
+ protected template: string;
22
+ protected userUtils?: UserUtils<U, A>;
23
+ /**
24
+ * Called on server startup to initialize the route with any defaults.
25
+ */
26
+ protected initialize(): Promise<void>;
27
+ /**
28
+ * Authenticates the user using TOTP and returns a JSON Web Token access token to be used with future API requests.
29
+ */
30
+ authenticate(user: JWTUser): Promise<AuthResult | undefined>;
31
+ protected getSecrets(uid: string): Promise<TOTPSecret[]>;
32
+ /**
33
+ * Retrieves the user with the given unique id.
34
+ * @param uid The unique id of the user to retrieve.
35
+ * @returns The user if found, otherwise `undefined`.
36
+ */
37
+ protected getUser(uid: string): Promise<JWTUser | undefined>;
38
+ }
@@ -0,0 +1,7 @@
1
+ import { CRUDRoute } from "@rapidrest/service-core";
2
+ import { Profile } from "../models/types.js";
3
+ /**
4
+ * @author Jean-Philippe Steinmetz
5
+ */
6
+ export declare abstract class BaseProfileRoute<T extends Profile> extends CRUDRoute<T> {
7
+ }
@@ -0,0 +1,89 @@
1
+ import { HttpRequest, HttpResponse, ModelRoute } from "@rapidrest/service-core";
2
+ import { Secret } from "../models/types.js";
3
+ import { JWTUser } from "@rapidrest/core";
4
+ import { PasskeyConfig, TOTPConfig } from "../auth/types.js";
5
+ /**
6
+ * @author Jean-Philippe Steinmetz
7
+ */
8
+ export declare abstract class BaseSecretRoute<T extends Secret> extends ModelRoute<T> {
9
+ protected readonly repoUtilsClass: any;
10
+ /**
11
+ * The relying party configuration used for validating and generating passkey (WebAuthn) registration data.
12
+ */
13
+ protected passkeyConfig: PasskeyConfig;
14
+ /**
15
+ * The relying party configuration used for validating and generating FIDO2 hardware security key
16
+ * (WebAuthn) registration data. Kept separate from `passkeyConfig` since a hardware key deployment
17
+ * commonly wants a different `authenticatorAttachment`/`residentKey` policy — a hardware key is
18
+ * typically registered as a `"cross-platform"`, non-discoverable credential tied to a known
19
+ * account, rather than a discoverable, possibly-synced passkey.
20
+ */
21
+ protected fido2Config: PasskeyConfig;
22
+ /**
23
+ * The issuer configuration used for validating and generating TOTP (RFC 6238) registration data.
24
+ */
25
+ protected totpConfig: TOTPConfig;
26
+ /**
27
+ * Removes the `data` property from the secret(s) to protect sensitive information.
28
+ */
29
+ protected cleanData(obj: T | T[]): void;
30
+ count(params: any, query: any, res: HttpResponse, user?: JWTUser): Promise<any>;
31
+ protected validateCreate(obj: Partial<T> | Partial<T>[], req: HttpRequest, user?: JWTUser): Promise<void>;
32
+ /**
33
+ * Verifies a client-submitted WebAuthn `RegistrationResponseJSON` (as produced by
34
+ * `navigator.credentials.create()` using the options from `generatePasskeyRegistrationOptions()`) against
35
+ * the challenge stored in the session, and replaces `obj.data` with the resulting `StoredPasskeyCredential`.
36
+ *
37
+ * Shared by both `passkey` and `fido2` secrets — the two differ only in relying party configuration
38
+ * (see `passkeyConfig`/`fido2Config`) and which `SecretType` they're persisted under, not in the
39
+ * underlying WebAuthn ceremony.
40
+ *
41
+ * Per the WebAuthn registration ceremony (https://www.w3.org/TR/webauthn-2/#sctn-registering-a-new-credential),
42
+ * the credential ID must be unique across all accounts known to this relying party. Rather than duplicate that
43
+ * check here, the credential ID is used directly as this secret's own `uid` so that `ModelRoute`'s existing
44
+ * create-time identifier check rejects the request should the ID already be registered to any account. This
45
+ * also lets a login ceremony, which only has the credential ID to go on, look the secret up directly by its
46
+ * primary key (see `BaseAuthPasskeyRoute`/`BaseAuthFIDO2Route`'s `getCredentialById`/`updateCredentialCounter`).
47
+ *
48
+ * @param obj The secret being created. Its `data` property must be a `RegistrationResponseJSON`.
49
+ * @param req The source HTTP request, used to retrieve the challenge stored in the session by a prior call to
50
+ * `generatePasskeyRegistrationOptions()`.
51
+ * @param config The relying party configuration to verify the response against.
52
+ */
53
+ protected validateWebAuthnCreate(obj: Partial<T>, req: HttpRequest, config: PasskeyConfig): Promise<void>;
54
+ /**
55
+ * Validates (or generates) the secret for a new `totp` secret per RFC 6238/RFC 4226.
56
+ *
57
+ * The client may either bring their own Base32-encoded secret (e.g. one generated on a
58
+ * different server for migration purposes) or, more commonly, omit `data` entirely and have one
59
+ * generated here. Either way, the secret's token parameters (`digits`/`period`/`algorithm`) are
60
+ * captured onto the stored `TOTPSecret` alongside it, rather than left to always defer to
61
+ * `totpConfig`, so verification keeps working for this secret even if the configured defaults
62
+ * change later.
63
+ *
64
+ * @param obj The secret being created. If `data` is a string, it's used as the caller-supplied
65
+ * secret; otherwise a new one is generated.
66
+ */
67
+ protected validateTOTPCreate(obj: Partial<T>): Promise<void>;
68
+ /**
69
+ * Begins a WebAuthn registration ceremony for the authenticated user: generates a set of
70
+ * `PublicKeyCredentialCreationOptions` (RFC/spec compliant per https://www.w3.org/TR/webauthn-2/), scoped
71
+ * to exclude any credentials of the given type the user already has registered, and stores the challenge
72
+ * in the session for verification by `validateWebAuthnCreate()` once the client completes the ceremony
73
+ * and submits a new secret of that type. Shared by both the `passkey` and `fido2` registration endpoints.
74
+ *
75
+ * @param req The source HTTP request. Used to persist the generated challenge in the session.
76
+ * @param user The authenticated user the new credential will be associated with.
77
+ * @param type The secret type being registered — `passkey` or `fido2`.
78
+ * @param config The relying party configuration to generate options with.
79
+ */
80
+ private beginWebAuthnRegistration;
81
+ passkeyRegistrationOptions(req: HttpRequest, user?: JWTUser): Promise<any>;
82
+ fido2RegistrationOptions(req: HttpRequest, user?: JWTUser): Promise<any>;
83
+ create(obj: T | T[], req: HttpRequest, user?: JWTUser): Promise<T | Array<T>>;
84
+ delete(id: string, version: string | undefined, purge: string | undefined, req: HttpRequest, user?: JWTUser): Promise<void>;
85
+ exists(id: string, query: any, res: HttpResponse, user?: JWTUser): Promise<any>;
86
+ find(params: any, query: any, user?: JWTUser): Promise<Array<T>>;
87
+ findById(id: string, query: any, user?: JWTUser): Promise<T | null>;
88
+ truncate(params: any, query: any, user?: JWTUser): Promise<void>;
89
+ }
@@ -0,0 +1,7 @@
1
+ import { CRUDRoute } from "@rapidrest/service-core";
2
+ import { User } from "../models/types.js";
3
+ /**
4
+ * @author Jean-Philippe Steinmetz
5
+ */
6
+ export declare abstract class BaseUserRoute<T extends User> extends CRUDRoute<T> {
7
+ }
@@ -0,0 +1,21 @@
1
+ import { ObjectFactory, RepoUtils } from "@rapidrest/service-core";
2
+ import { Alias, User } from "../models/types.js";
3
+ /**
4
+ * Utility class for working with persisted `User` objects in the database.
5
+ */
6
+ export declare class UserUtils<U extends User, A extends Alias> {
7
+ protected aliasClass: any;
8
+ protected aliasRepo?: RepoUtils<A>;
9
+ protected userClass: any;
10
+ protected userRepo?: RepoUtils<U>;
11
+ protected objectFactory?: ObjectFactory;
12
+ constructor(userClass: any, aliasClass: any);
13
+ protected init(): Promise<void>;
14
+ /**
15
+ * Performs a look up of the user with the given id. The id may be one of: the user's `uid` or an `Alias`.
16
+ *
17
+ * @param id The unique id of the user to lookup.
18
+ * @returns The `User` if found, otherwise `undefined`.
19
+ */
20
+ lookup(id: string): Promise<U | undefined>;
21
+ }
@@ -0,0 +1,12 @@
1
+ export * from "./BaseAliasRoute.js";
2
+ export * from "./BaseAuthBasicRoute.js";
3
+ export * from "./BaseAuthFIDO2Route.js";
4
+ export * from "./BaseAuthMFARoute.js";
5
+ export * from "./BaseAuthOIDCRoute.js";
6
+ export * from "./BaseAuthOTPRoute.js";
7
+ export * from "./BaseAuthPasskeyRoute.js";
8
+ export * from "./BaseAuthTOTPRoute.js";
9
+ export * from "./BaseProfileRoute.js";
10
+ export * from "./BaseSecretRoute.js";
11
+ export * from "./BaseUserRoute.js";
12
+ export * from "./UserUtils.js";
@@ -0,0 +1,4 @@
1
+ import { AliasMongo } from "../../mongo.js";
2
+ import { BaseAliasRoute } from "../BaseAliasRoute.js";
3
+ export declare class BaseAliasRouteMongo extends BaseAliasRoute<AliasMongo> {
4
+ }
@@ -0,0 +1,7 @@
1
+ import { AliasMongo, SecretMongo, UserMongo } from "../../mongo.js";
2
+ import { BaseAuthBasicRoute } from "../BaseAuthBasicRoute.js";
3
+ export declare abstract class BaseAuthBasicRouteMongo extends BaseAuthBasicRoute<UserMongo, SecretMongo, AliasMongo> {
4
+ protected aliasClass: any;
5
+ protected secretClass: any;
6
+ protected userClass: any;
7
+ }
@@ -0,0 +1,7 @@
1
+ import { AliasMongo, SecretMongo, UserMongo } from "../../mongo.js";
2
+ import { BaseAuthFIDO2Route } from "../BaseAuthFIDO2Route.js";
3
+ export declare abstract class BaseAuthFIDO2RouteMongo extends BaseAuthFIDO2Route<UserMongo, AliasMongo, SecretMongo> {
4
+ protected aliasClass: any;
5
+ protected secretClass: any;
6
+ protected userClass: any;
7
+ }
@@ -0,0 +1,7 @@
1
+ import { AliasMongo, SecretMongo, UserMongo } from "../../mongo.js";
2
+ import { BaseAuthMFARoute } from "../BaseAuthMFARoute.js";
3
+ export declare abstract class BaseAuthMFARouteMongo extends BaseAuthMFARoute<UserMongo, SecretMongo, AliasMongo> {
4
+ protected aliasClass: any;
5
+ protected secretClass: any;
6
+ protected userClass: any;
7
+ }
@@ -0,0 +1,7 @@
1
+ import { AliasMongo, ProfileMongo, UserMongo } from "../../mongo.js";
2
+ import { BaseAuthOIDCRoute } from "../BaseAuthOIDCRoute.js";
3
+ export declare abstract class BaseAuthOIDCRouteMongo extends BaseAuthOIDCRoute<UserMongo, AliasMongo, ProfileMongo> {
4
+ protected aliasClass: any;
5
+ protected profileClass: any;
6
+ protected userClass: any;
7
+ }
@@ -0,0 +1,7 @@
1
+ import { AliasMongo, SecretMongo, UserMongo } from "../../mongo.js";
2
+ import { BaseAuthOTPRoute } from "../BaseAuthOTPRoute.js";
3
+ export declare abstract class BaseAuthOTPRouteMongo extends BaseAuthOTPRoute<UserMongo, AliasMongo, SecretMongo> {
4
+ protected aliasClass: any;
5
+ protected secretClass: any;
6
+ protected userClass: any;
7
+ }
@@ -0,0 +1,7 @@
1
+ import { AliasMongo, SecretMongo, UserMongo } from "../../mongo.js";
2
+ import { BaseAuthPasskeyRoute } from "../BaseAuthPasskeyRoute.js";
3
+ export declare abstract class BaseAuthPasskeyRouteMongo extends BaseAuthPasskeyRoute<UserMongo, AliasMongo, SecretMongo> {
4
+ protected aliasClass: any;
5
+ protected secretClass: any;
6
+ protected userClass: any;
7
+ }
@@ -0,0 +1,7 @@
1
+ import { AliasMongo, SecretMongo, UserMongo } from "../../mongo.js";
2
+ import { BaseAuthTOTPRoute } from "../BaseAuthTOTPRoute.js";
3
+ export declare abstract class BaseAuthTOTPRouteMongo extends BaseAuthTOTPRoute<UserMongo, AliasMongo, SecretMongo> {
4
+ protected aliasClass: any;
5
+ protected secretClass: any;
6
+ protected userClass: any;
7
+ }
@@ -0,0 +1,4 @@
1
+ import { ProfileMongo } from "../../mongo.js";
2
+ import { BaseProfileRoute } from "../BaseProfileRoute.js";
3
+ export declare class BaseProfileRouteMongo extends BaseProfileRoute<ProfileMongo> {
4
+ }
@@ -0,0 +1,4 @@
1
+ import { SecretMongo } from "../../mongo.js";
2
+ import { BaseSecretRoute } from "../BaseSecretRoute.js";
3
+ export declare class BaseSecretRouteMongo extends BaseSecretRoute<SecretMongo> {
4
+ }
@@ -0,0 +1,4 @@
1
+ import { UserMongo } from "../../mongo.js";
2
+ import { BaseUserRoute } from "../BaseUserRoute.js";
3
+ export declare class BaseUserRouteMongo extends BaseUserRoute<UserMongo> {
4
+ }
@@ -0,0 +1,11 @@
1
+ export * from "./BaseAliasRouteMongo.js";
2
+ export * from "./BaseAuthBasicRouteMongo.js";
3
+ export * from "./BaseAuthFIDO2RouteMongo.js";
4
+ export * from "./BaseAuthMFARouteMongo.js";
5
+ export * from "./BaseAuthOIDCRouteMongo.js";
6
+ export * from "./BaseAuthOTPRouteMongo.js";
7
+ export * from "./BaseAuthPasskeyRouteMongo.js";
8
+ export * from "./BaseAuthTOTPRouteMongo.js";
9
+ export * from "./BaseProfileRouteMongo.js";
10
+ export * from "./BaseSecretRouteMongo.js";
11
+ export * from "./BaseUserRouteMongo.js";
@@ -0,0 +1 @@
1
+ export * from "./mongo/index.js";
@@ -0,0 +1,4 @@
1
+ import { AliasSQL } from "../../sql.js";
2
+ import { BaseAliasRoute } from "../BaseAliasRoute.js";
3
+ export declare class BaseAliasRouteSQL extends BaseAliasRoute<AliasSQL> {
4
+ }
@@ -0,0 +1,7 @@
1
+ import { AliasSQL, SecretSQL, UserSQL } from "../../sql.js";
2
+ import { BaseAuthBasicRoute } from "../BaseAuthBasicRoute.js";
3
+ export declare abstract class BaseAuthBasicRouteSQL extends BaseAuthBasicRoute<UserSQL, SecretSQL, AliasSQL> {
4
+ protected aliasClass: any;
5
+ protected secretClass: any;
6
+ protected userClass: any;
7
+ }
@@ -0,0 +1,7 @@
1
+ import { AliasSQL, SecretSQL, UserSQL } from "../../sql.js";
2
+ import { BaseAuthFIDO2Route } from "../BaseAuthFIDO2Route.js";
3
+ export declare abstract class BaseAuthFIDO2RouteSQL extends BaseAuthFIDO2Route<UserSQL, AliasSQL, SecretSQL> {
4
+ protected aliasClass: any;
5
+ protected secretClass: any;
6
+ protected userClass: any;
7
+ }
@@ -0,0 +1,7 @@
1
+ import { AliasSQL, SecretSQL, UserSQL } from "../../sql.js";
2
+ import { BaseAuthMFARoute } from "../BaseAuthMFARoute.js";
3
+ export declare abstract class BaseAuthMFARouteSQL extends BaseAuthMFARoute<UserSQL, SecretSQL, AliasSQL> {
4
+ protected aliasClass: any;
5
+ protected secretClass: any;
6
+ protected userClass: any;
7
+ }
@@ -0,0 +1,7 @@
1
+ import { AliasSQL, ProfileSQL, UserSQL } from "../../sql.js";
2
+ import { BaseAuthOIDCRoute } from "../BaseAuthOIDCRoute.js";
3
+ export declare abstract class BaseAuthOIDCRouteSQL extends BaseAuthOIDCRoute<UserSQL, AliasSQL, ProfileSQL> {
4
+ protected aliasClass: any;
5
+ protected profileClass: any;
6
+ protected userClass: any;
7
+ }
@@ -0,0 +1,7 @@
1
+ import { AliasSQL, SecretSQL, UserSQL } from "../../sql.js";
2
+ import { BaseAuthOTPRoute } from "../BaseAuthOTPRoute.js";
3
+ export declare abstract class BaseAuthOTPRouteSQL extends BaseAuthOTPRoute<UserSQL, AliasSQL, SecretSQL> {
4
+ protected aliasClass: any;
5
+ protected secretClass: any;
6
+ protected userClass: any;
7
+ }
@@ -0,0 +1,7 @@
1
+ import { AliasSQL, SecretSQL, UserSQL } from "../../sql.js";
2
+ import { BaseAuthPasskeyRoute } from "../BaseAuthPasskeyRoute.js";
3
+ export declare abstract class BaseAuthPasskeyRouteSQL extends BaseAuthPasskeyRoute<UserSQL, AliasSQL, SecretSQL> {
4
+ protected aliasClass: any;
5
+ protected secretClass: any;
6
+ protected userClass: any;
7
+ }
@@ -0,0 +1,7 @@
1
+ import { AliasSQL, SecretSQL, UserSQL } from "../../sql.js";
2
+ import { BaseAuthTOTPRoute } from "../BaseAuthTOTPRoute.js";
3
+ export declare abstract class BaseAuthTOTPRouteSQL extends BaseAuthTOTPRoute<UserSQL, AliasSQL, SecretSQL> {
4
+ protected aliasClass: any;
5
+ protected secretClass: any;
6
+ protected userClass: any;
7
+ }
@@ -0,0 +1,4 @@
1
+ import { ProfileSQL } from "../../sql.js";
2
+ import { BaseProfileRoute } from "../BaseProfileRoute.js";
3
+ export declare class BaseProfileRouteSQL extends BaseProfileRoute<ProfileSQL> {
4
+ }
@@ -0,0 +1,4 @@
1
+ import { SecretSQL } from "../../sql.js";
2
+ import { BaseSecretRoute } from "../BaseSecretRoute.js";
3
+ export declare class BaseSecretRouteSQL extends BaseSecretRoute<SecretSQL> {
4
+ }
@@ -0,0 +1,4 @@
1
+ import { UserSQL } from "../../sql.js";
2
+ import { BaseUserRoute } from "../BaseUserRoute.js";
3
+ export declare class BaseUserRouteSQL extends BaseUserRoute<UserSQL> {
4
+ }
@@ -0,0 +1,11 @@
1
+ export * from "./BaseAliasRouteSQL.js";
2
+ export * from "./BaseAuthBasicRouteSQL.js";
3
+ export * from "./BaseAuthFIDO2RouteSQL.js";
4
+ export * from "./BaseAuthMFARouteSQL.js";
5
+ export * from "./BaseAuthOIDCRouteSQL.js";
6
+ export * from "./BaseAuthOTPRouteSQL.js";
7
+ export * from "./BaseAuthPasskeyRouteSQL.js";
8
+ export * from "./BaseAuthTOTPRouteSQL.js";
9
+ export * from "./BaseProfileRouteSQL.js";
10
+ export * from "./BaseSecretRouteSQL.js";
11
+ export * from "./BaseUserRouteSQL.js";
@@ -0,0 +1 @@
1
+ export * from "./sql/index.js";
@@ -0,0 +1,2 @@
1
+ export * from "./models/sql.js";
2
+ export * from "./routes/sql.js";
package/package.json ADDED
@@ -0,0 +1,138 @@
1
+ {
2
+ "name": "@rapidrest/auth",
3
+ "version": "1.0.0-beta.1",
4
+ "description": "A library for implementing a complete authentication server in RapidREST.",
5
+ "repository": "https://github.com/rapidrest/auth.git",
6
+ "author": "RapidREST <rapidrests@gmail.com>",
7
+ "license": "MIT",
8
+ "contributors": [
9
+ "Jean-Philippe Steinmetz"
10
+ ],
11
+ "scripts": {
12
+ "build": "yarn lint && rimraf dist && tsc",
13
+ "lint": "eslint ./src ./test",
14
+ "local-audit": "yarn install && yarn npm audit -A -R \"$@\"",
15
+ "checkup": "yarn dlx @yarnpkg/doctor \"$@\"",
16
+ "dependency-check": "yarn dlx depcheck \"$@\"",
17
+ "report-coverage": "cat ./coverage/lcov.info | coveralls",
18
+ "bench": "tsx bench/index.ts",
19
+ "bench:baseline": "yarn bench 2>&1 | tee bench/baseline.txt",
20
+ "test": "vitest run",
21
+ "test:prod": "npm run lint && vitest run --coverage",
22
+ "test:watch": "vitest",
23
+ "postversion": "git push && git push --tags"
24
+ },
25
+ "peerDependencies": {
26
+ "@rapidrest/core": "1.x",
27
+ "@rapidrest/service-core": "1.x",
28
+ "@simplewebauthn/server": ">=13.0.0",
29
+ "@vitejs/plugin-react": ">=4.0.0",
30
+ "argon2": "0.x",
31
+ "jwks-rsa": "4.x",
32
+ "nodemon": ">=3.0.0",
33
+ "otplib": ">=13.0.0",
34
+ "react": "19.x",
35
+ "react-dom": "19.x",
36
+ "tsx": ">=4.0.0"
37
+ },
38
+ "peerDependenciesMeta": {
39
+ "@simplewebauthn/server": {
40
+ "optional": true
41
+ },
42
+ "@vitejs/plugin-react": {
43
+ "optional": true
44
+ },
45
+ "argon2": {
46
+ "optional": true
47
+ },
48
+ "jwks-rsa": {
49
+ "optional": true
50
+ },
51
+ "nodemon": {
52
+ "optional": true
53
+ },
54
+ "otplib": {
55
+ "optional": true
56
+ },
57
+ "tsx": {
58
+ "optional": true
59
+ }
60
+ },
61
+ "bin": {
62
+ "rapidreact": "./dist/cli/cli.js"
63
+ },
64
+ "dependencies": {
65
+ "cross-spawn": "^7.0.5"
66
+ },
67
+ "devDependencies": {
68
+ "@rapidrest/core": "^1.9.0",
69
+ "@rapidrest/service-core": "1.0.0-rc.25",
70
+ "@simplewebauthn/server": "^13.3.2",
71
+ "@swc/core": "^1.15.41",
72
+ "@types/cross-spawn": "^6.0.6",
73
+ "@types/node": "^25.9.2",
74
+ "@types/speakeasy": "^2",
75
+ "@typescript-eslint/eslint-plugin": "^8.61.0",
76
+ "@typescript-eslint/parser": "^8.61.0",
77
+ "@vitejs/plugin-react": "^6.0.3",
78
+ "@vitest/coverage-v8": "^4.1.8",
79
+ "argon2": "^0.44.0",
80
+ "eslint": "^10.4.1",
81
+ "eslint-config-prettier": "^10.1.8",
82
+ "eslint-plugin-import": "^2.32.0",
83
+ "eslint-plugin-jsdoc": "^63.0.2",
84
+ "globals": "^17.6.0",
85
+ "ioredis": "^5.11.1",
86
+ "ioredis-mock": "^8.13.1",
87
+ "jwks-rsa": "^4.1.0",
88
+ "lodash-es": "^4.18.1",
89
+ "mongodb": "^7.5.0",
90
+ "mongodb-memory-server": "^11.2.0",
91
+ "nconf": "^0.13.0",
92
+ "openapi3-ts": "^4.6.0",
93
+ "otplib": "^13.4.1",
94
+ "prom-client": "^15.1.3",
95
+ "reflect-metadata": "^0.2.2",
96
+ "rimraf": "^6.1.3",
97
+ "speakeasy": "^2.0.0",
98
+ "sqlite3": "^6.0.1",
99
+ "ts-node": "^10.9.2",
100
+ "tsx": "^4.19.3",
101
+ "typeorm": "^0.3.20",
102
+ "typescript": "^6.0.3",
103
+ "unplugin-swc": "^1.5.9",
104
+ "uuid": "^14.0.1",
105
+ "vitest": "^4.1.8",
106
+ "winston": "^3.19.0"
107
+ },
108
+ "resolutions": {
109
+ "cross-spawn": "^7.0.5"
110
+ },
111
+ "packageManager": "yarn@4.5.3",
112
+ "engines": {
113
+ "node": ">=24.0.0"
114
+ },
115
+ "publishConfig": {
116
+ "registry": "https://registry.npmjs.org/"
117
+ },
118
+ "type": "module",
119
+ "main": "dist/lib/index.js",
120
+ "exports": {
121
+ ".": {
122
+ "import": "./dist/lib/index.js",
123
+ "types": "./dist/types/index.d.ts"
124
+ },
125
+ "./mongo": {
126
+ "import": "./dist/lib/mongo.js",
127
+ "types": "./dist/types/mongo.d.ts"
128
+ },
129
+ "./sql": {
130
+ "import": "./dist/lib/sql.js",
131
+ "types": "./dist/types/sql.d.ts"
132
+ }
133
+ },
134
+ "typings": "dist/types/index.d.ts",
135
+ "files": [
136
+ "dist"
137
+ ]
138
+ }