@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.
- package/LICENSE +21 -0
- package/README.md +75 -0
- package/dist/lib/auth/BasicStrategy.js +82 -0
- package/dist/lib/auth/BasicStrategy.js.map +1 -0
- package/dist/lib/auth/FIDO2Strategy.js +179 -0
- package/dist/lib/auth/FIDO2Strategy.js.map +1 -0
- package/dist/lib/auth/MFAStrategy.js +219 -0
- package/dist/lib/auth/MFAStrategy.js.map +1 -0
- package/dist/lib/auth/OIDCStrategy.js +397 -0
- package/dist/lib/auth/OIDCStrategy.js.map +1 -0
- package/dist/lib/auth/OTPStrategy.js +143 -0
- package/dist/lib/auth/OTPStrategy.js.map +1 -0
- package/dist/lib/auth/PasskeyStrategy.js +185 -0
- package/dist/lib/auth/PasskeyStrategy.js.map +1 -0
- package/dist/lib/auth/TOTPStrategy.js +84 -0
- package/dist/lib/auth/TOTPStrategy.js.map +1 -0
- package/dist/lib/auth/index.js +10 -0
- package/dist/lib/auth/index.js.map +1 -0
- package/dist/lib/auth/shared.js +431 -0
- package/dist/lib/auth/shared.js.map +1 -0
- package/dist/lib/auth/types.js +12 -0
- package/dist/lib/auth/types.js.map +1 -0
- package/dist/lib/index.js +4 -0
- package/dist/lib/index.js.map +1 -0
- package/dist/lib/models/index.js +2 -0
- package/dist/lib/models/index.js.map +1 -0
- package/dist/lib/models/mongo/AliasMongo.js +77 -0
- package/dist/lib/models/mongo/AliasMongo.js.map +1 -0
- package/dist/lib/models/mongo/ProfileMongo.js +99 -0
- package/dist/lib/models/mongo/ProfileMongo.js.map +1 -0
- package/dist/lib/models/mongo/SecretMongo.js +71 -0
- package/dist/lib/models/mongo/SecretMongo.js.map +1 -0
- package/dist/lib/models/mongo/UserMongo.js +71 -0
- package/dist/lib/models/mongo/UserMongo.js.map +1 -0
- package/dist/lib/models/mongo/index.js +5 -0
- package/dist/lib/models/mongo/index.js.map +1 -0
- package/dist/lib/models/mongo.js +2 -0
- package/dist/lib/models/mongo.js.map +1 -0
- package/dist/lib/models/sql/AliasSQL.js +77 -0
- package/dist/lib/models/sql/AliasSQL.js.map +1 -0
- package/dist/lib/models/sql/ProfileSQL.js +99 -0
- package/dist/lib/models/sql/ProfileSQL.js.map +1 -0
- package/dist/lib/models/sql/SecretSQL.js +71 -0
- package/dist/lib/models/sql/SecretSQL.js.map +1 -0
- package/dist/lib/models/sql/UserSQL.js +68 -0
- package/dist/lib/models/sql/UserSQL.js.map +1 -0
- package/dist/lib/models/sql/index.js +5 -0
- package/dist/lib/models/sql/index.js.map +1 -0
- package/dist/lib/models/sql.js +2 -0
- package/dist/lib/models/sql.js.map +1 -0
- package/dist/lib/models/types.js +35 -0
- package/dist/lib/models/types.js.map +1 -0
- package/dist/lib/mongo.js +3 -0
- package/dist/lib/mongo.js.map +1 -0
- package/dist/lib/routes/BaseAliasRoute.js +10 -0
- package/dist/lib/routes/BaseAliasRoute.js.map +1 -0
- package/dist/lib/routes/BaseAuthBasicRoute.js +132 -0
- package/dist/lib/routes/BaseAuthBasicRoute.js.map +1 -0
- package/dist/lib/routes/BaseAuthFIDO2Route.js +191 -0
- package/dist/lib/routes/BaseAuthFIDO2Route.js.map +1 -0
- package/dist/lib/routes/BaseAuthMFARoute.js +310 -0
- package/dist/lib/routes/BaseAuthMFARoute.js.map +1 -0
- package/dist/lib/routes/BaseAuthOIDCRoute.js +231 -0
- package/dist/lib/routes/BaseAuthOIDCRoute.js.map +1 -0
- package/dist/lib/routes/BaseAuthOTPRoute.js +214 -0
- package/dist/lib/routes/BaseAuthOTPRoute.js.map +1 -0
- package/dist/lib/routes/BaseAuthPasskeyRoute.js +182 -0
- package/dist/lib/routes/BaseAuthPasskeyRoute.js.map +1 -0
- package/dist/lib/routes/BaseAuthTOTPRoute.js +133 -0
- package/dist/lib/routes/BaseAuthTOTPRoute.js.map +1 -0
- package/dist/lib/routes/BaseProfileRoute.js +10 -0
- package/dist/lib/routes/BaseProfileRoute.js.map +1 -0
- package/dist/lib/routes/BaseSecretRoute.js +399 -0
- package/dist/lib/routes/BaseSecretRoute.js.map +1 -0
- package/dist/lib/routes/BaseUserRoute.js +10 -0
- package/dist/lib/routes/BaseUserRoute.js.map +1 -0
- package/dist/lib/routes/UserUtils.js +78 -0
- package/dist/lib/routes/UserUtils.js.map +1 -0
- package/dist/lib/routes/index.js +13 -0
- package/dist/lib/routes/index.js.map +1 -0
- package/dist/lib/routes/mongo/BaseAliasRouteMongo.js +20 -0
- package/dist/lib/routes/mongo/BaseAliasRouteMongo.js.map +1 -0
- package/dist/lib/routes/mongo/BaseAuthBasicRouteMongo.js +14 -0
- package/dist/lib/routes/mongo/BaseAuthBasicRouteMongo.js.map +1 -0
- package/dist/lib/routes/mongo/BaseAuthFIDO2RouteMongo.js +14 -0
- package/dist/lib/routes/mongo/BaseAuthFIDO2RouteMongo.js.map +1 -0
- package/dist/lib/routes/mongo/BaseAuthMFARouteMongo.js +14 -0
- package/dist/lib/routes/mongo/BaseAuthMFARouteMongo.js.map +1 -0
- package/dist/lib/routes/mongo/BaseAuthOIDCRouteMongo.js +11 -0
- package/dist/lib/routes/mongo/BaseAuthOIDCRouteMongo.js.map +1 -0
- package/dist/lib/routes/mongo/BaseAuthOTPRouteMongo.js +14 -0
- package/dist/lib/routes/mongo/BaseAuthOTPRouteMongo.js.map +1 -0
- package/dist/lib/routes/mongo/BaseAuthPasskeyRouteMongo.js +14 -0
- package/dist/lib/routes/mongo/BaseAuthPasskeyRouteMongo.js.map +1 -0
- package/dist/lib/routes/mongo/BaseAuthTOTPRouteMongo.js +14 -0
- package/dist/lib/routes/mongo/BaseAuthTOTPRouteMongo.js.map +1 -0
- package/dist/lib/routes/mongo/BaseProfileRouteMongo.js +20 -0
- package/dist/lib/routes/mongo/BaseProfileRouteMongo.js.map +1 -0
- package/dist/lib/routes/mongo/BaseSecretRouteMongo.js +20 -0
- package/dist/lib/routes/mongo/BaseSecretRouteMongo.js.map +1 -0
- package/dist/lib/routes/mongo/BaseUserRouteMongo.js +20 -0
- package/dist/lib/routes/mongo/BaseUserRouteMongo.js.map +1 -0
- package/dist/lib/routes/mongo/index.js +12 -0
- package/dist/lib/routes/mongo/index.js.map +1 -0
- package/dist/lib/routes/mongo.js +2 -0
- package/dist/lib/routes/mongo.js.map +1 -0
- package/dist/lib/routes/sql/BaseAliasRouteSQL.js +20 -0
- package/dist/lib/routes/sql/BaseAliasRouteSQL.js.map +1 -0
- package/dist/lib/routes/sql/BaseAuthBasicRouteSQL.js +14 -0
- package/dist/lib/routes/sql/BaseAuthBasicRouteSQL.js.map +1 -0
- package/dist/lib/routes/sql/BaseAuthFIDO2RouteSQL.js +14 -0
- package/dist/lib/routes/sql/BaseAuthFIDO2RouteSQL.js.map +1 -0
- package/dist/lib/routes/sql/BaseAuthMFARouteSQL.js +14 -0
- package/dist/lib/routes/sql/BaseAuthMFARouteSQL.js.map +1 -0
- package/dist/lib/routes/sql/BaseAuthOIDCRouteSQL.js +11 -0
- package/dist/lib/routes/sql/BaseAuthOIDCRouteSQL.js.map +1 -0
- package/dist/lib/routes/sql/BaseAuthOTPRouteSQL.js +14 -0
- package/dist/lib/routes/sql/BaseAuthOTPRouteSQL.js.map +1 -0
- package/dist/lib/routes/sql/BaseAuthPasskeyRouteSQL.js +14 -0
- package/dist/lib/routes/sql/BaseAuthPasskeyRouteSQL.js.map +1 -0
- package/dist/lib/routes/sql/BaseAuthTOTPRouteSQL.js +14 -0
- package/dist/lib/routes/sql/BaseAuthTOTPRouteSQL.js.map +1 -0
- package/dist/lib/routes/sql/BaseProfileRouteSQL.js +20 -0
- package/dist/lib/routes/sql/BaseProfileRouteSQL.js.map +1 -0
- package/dist/lib/routes/sql/BaseSecretRouteSQL.js +20 -0
- package/dist/lib/routes/sql/BaseSecretRouteSQL.js.map +1 -0
- package/dist/lib/routes/sql/BaseUserRouteSQL.js +20 -0
- package/dist/lib/routes/sql/BaseUserRouteSQL.js.map +1 -0
- package/dist/lib/routes/sql/index.js +12 -0
- package/dist/lib/routes/sql/index.js.map +1 -0
- package/dist/lib/routes/sql.js +2 -0
- package/dist/lib/routes/sql.js.map +1 -0
- package/dist/lib/sql.js +3 -0
- package/dist/lib/sql.js.map +1 -0
- package/dist/types/auth/BasicStrategy.d.ts +39 -0
- package/dist/types/auth/FIDO2Strategy.d.ts +85 -0
- package/dist/types/auth/MFAStrategy.d.ts +110 -0
- package/dist/types/auth/OIDCStrategy.d.ts +188 -0
- package/dist/types/auth/OTPStrategy.d.ts +88 -0
- package/dist/types/auth/PasskeyStrategy.d.ts +81 -0
- package/dist/types/auth/TOTPStrategy.d.ts +49 -0
- package/dist/types/auth/index.d.ts +9 -0
- package/dist/types/auth/shared.d.ts +136 -0
- package/dist/types/auth/types.d.ts +127 -0
- package/dist/types/index.d.ts +3 -0
- package/dist/types/models/index.d.ts +1 -0
- package/dist/types/models/mongo/AliasMongo.d.ts +15 -0
- package/dist/types/models/mongo/ProfileMongo.d.ts +17 -0
- package/dist/types/models/mongo/SecretMongo.d.ts +14 -0
- package/dist/types/models/mongo/UserMongo.d.ts +14 -0
- package/dist/types/models/mongo/index.d.ts +4 -0
- package/dist/types/models/mongo.d.ts +1 -0
- package/dist/types/models/sql/AliasSQL.d.ts +15 -0
- package/dist/types/models/sql/ProfileSQL.d.ts +17 -0
- package/dist/types/models/sql/SecretSQL.d.ts +14 -0
- package/dist/types/models/sql/UserSQL.d.ts +14 -0
- package/dist/types/models/sql/index.d.ts +4 -0
- package/dist/types/models/sql.d.ts +1 -0
- package/dist/types/models/types.d.ts +136 -0
- package/dist/types/mongo.d.ts +2 -0
- package/dist/types/routes/BaseAliasRoute.d.ts +7 -0
- package/dist/types/routes/BaseAuthBasicRoute.d.ts +27 -0
- package/dist/types/routes/BaseAuthFIDO2Route.d.ts +50 -0
- package/dist/types/routes/BaseAuthMFARoute.d.ts +61 -0
- package/dist/types/routes/BaseAuthOIDCRoute.d.ts +33 -0
- package/dist/types/routes/BaseAuthOTPRoute.d.ts +53 -0
- package/dist/types/routes/BaseAuthPasskeyRoute.d.ts +41 -0
- package/dist/types/routes/BaseAuthTOTPRoute.d.ts +38 -0
- package/dist/types/routes/BaseProfileRoute.d.ts +7 -0
- package/dist/types/routes/BaseSecretRoute.d.ts +89 -0
- package/dist/types/routes/BaseUserRoute.d.ts +7 -0
- package/dist/types/routes/UserUtils.d.ts +21 -0
- package/dist/types/routes/index.d.ts +12 -0
- package/dist/types/routes/mongo/BaseAliasRouteMongo.d.ts +4 -0
- package/dist/types/routes/mongo/BaseAuthBasicRouteMongo.d.ts +7 -0
- package/dist/types/routes/mongo/BaseAuthFIDO2RouteMongo.d.ts +7 -0
- package/dist/types/routes/mongo/BaseAuthMFARouteMongo.d.ts +7 -0
- package/dist/types/routes/mongo/BaseAuthOIDCRouteMongo.d.ts +7 -0
- package/dist/types/routes/mongo/BaseAuthOTPRouteMongo.d.ts +7 -0
- package/dist/types/routes/mongo/BaseAuthPasskeyRouteMongo.d.ts +7 -0
- package/dist/types/routes/mongo/BaseAuthTOTPRouteMongo.d.ts +7 -0
- package/dist/types/routes/mongo/BaseProfileRouteMongo.d.ts +4 -0
- package/dist/types/routes/mongo/BaseSecretRouteMongo.d.ts +4 -0
- package/dist/types/routes/mongo/BaseUserRouteMongo.d.ts +4 -0
- package/dist/types/routes/mongo/index.d.ts +11 -0
- package/dist/types/routes/mongo.d.ts +1 -0
- package/dist/types/routes/sql/BaseAliasRouteSQL.d.ts +4 -0
- package/dist/types/routes/sql/BaseAuthBasicRouteSQL.d.ts +7 -0
- package/dist/types/routes/sql/BaseAuthFIDO2RouteSQL.d.ts +7 -0
- package/dist/types/routes/sql/BaseAuthMFARouteSQL.d.ts +7 -0
- package/dist/types/routes/sql/BaseAuthOIDCRouteSQL.d.ts +7 -0
- package/dist/types/routes/sql/BaseAuthOTPRouteSQL.d.ts +7 -0
- package/dist/types/routes/sql/BaseAuthPasskeyRouteSQL.d.ts +7 -0
- package/dist/types/routes/sql/BaseAuthTOTPRouteSQL.d.ts +7 -0
- package/dist/types/routes/sql/BaseProfileRouteSQL.d.ts +4 -0
- package/dist/types/routes/sql/BaseSecretRouteSQL.d.ts +4 -0
- package/dist/types/routes/sql/BaseUserRouteSQL.d.ts +4 -0
- package/dist/types/routes/sql/index.d.ts +11 -0
- package/dist/types/routes/sql.d.ts +1 -0
- package/dist/types/sql.d.ts +2 -0
- package/package.json +138 -0
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The different types of supported contact methods.
|
|
3
|
+
*/
|
|
4
|
+
export declare enum OTPContactType {
|
|
5
|
+
EMAIL = "email",
|
|
6
|
+
SMS = "sms"
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Describes a single verified contact that can be used to send a OTP code to the user.
|
|
10
|
+
*/
|
|
11
|
+
export interface OTPContact {
|
|
12
|
+
/** The contact that the OTP can be sent to. */
|
|
13
|
+
contact: string;
|
|
14
|
+
/** The method type of contact (e.g. email, sms). */
|
|
15
|
+
type: OTPContactType;
|
|
16
|
+
/** Indicates if the contact has been verified. */
|
|
17
|
+
verified?: boolean;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Configuration for a WebAuthn/Passkey relying party.
|
|
21
|
+
*/
|
|
22
|
+
export interface PasskeyConfig {
|
|
23
|
+
/** The human-readable name of the relying party, shown to the user by the authenticator UI. */
|
|
24
|
+
rpName: string;
|
|
25
|
+
/** The relying party ID — a valid domain name (no scheme/port), e.g. `"example.com"`. */
|
|
26
|
+
rpID: string;
|
|
27
|
+
/**
|
|
28
|
+
* The exact scheme+host+port expected in the client's `clientDataJSON.origin` (e.g.
|
|
29
|
+
* `"https://example.com"`). May be a list to support multiple valid frontend origins.
|
|
30
|
+
*/
|
|
31
|
+
origin: string | string[];
|
|
32
|
+
/**
|
|
33
|
+
* Requested user verification behavior at options-generation time. Set to `"discouraged"` for a
|
|
34
|
+
* 2FA-style flow, `"required"`/`"preferred"` otherwise. Default is `"preferred"`.
|
|
35
|
+
*/
|
|
36
|
+
userVerification?: "required" | "preferred" | "discouraged";
|
|
37
|
+
/**
|
|
38
|
+
* Whether user verification is *enforced* at response-verification time. This is a distinct
|
|
39
|
+
* knob from `userVerification` above (which only shapes what's requested from the client).
|
|
40
|
+
* Default is `true`.
|
|
41
|
+
*/
|
|
42
|
+
requireUserVerification?: boolean;
|
|
43
|
+
/** How long (in ms) the user has to complete the ceremony. Default is `60000`. */
|
|
44
|
+
timeout?: number;
|
|
45
|
+
/**
|
|
46
|
+
* Restricts which category of authenticator may be used to create a new credential during
|
|
47
|
+
* registration. Set to `"cross-platform"` to steer users toward roaming/hardware security keys
|
|
48
|
+
* (e.g. a YubiKey), or `"platform"` for built-in authenticators (Face ID, Windows Hello, etc).
|
|
49
|
+
* Leave unset to allow either — the appropriate default for passkey registration.
|
|
50
|
+
*/
|
|
51
|
+
authenticatorAttachment?: "platform" | "cross-platform";
|
|
52
|
+
/**
|
|
53
|
+
* Whether a newly registered credential must be discoverable (usable in a "usernameless" flow).
|
|
54
|
+
* Default is `"preferred"`. A hardware security key used purely as a known-account credential
|
|
55
|
+
* typically doesn't need this and can use `"discouraged"`.
|
|
56
|
+
*/
|
|
57
|
+
residentKey?: "discouraged" | "preferred" | "required";
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* The transport hints an authenticator can report supporting. Mirrors `@simplewebauthn/server`'s
|
|
61
|
+
* `AuthenticatorTransportFuture` union without a compile-time dependency on that optional package.
|
|
62
|
+
*/
|
|
63
|
+
export type PasskeyTransport = "ble" | "cable" | "hybrid" | "internal" | "nfc" | "smart-card" | "usb";
|
|
64
|
+
/**
|
|
65
|
+
* A previously-registered WebAuthn credential as persisted by the consuming application.
|
|
66
|
+
*/
|
|
67
|
+
export interface StoredPasskeyCredential {
|
|
68
|
+
/** The base64url-encoded credential ID. */
|
|
69
|
+
id: string;
|
|
70
|
+
/** The uid of the user this credential belongs to. */
|
|
71
|
+
uid: string;
|
|
72
|
+
/** The credential's public key, as returned by the registration ceremony. */
|
|
73
|
+
publicKey: Uint8Array;
|
|
74
|
+
/** The last-known signature counter for this credential, used to detect cloned authenticators. */
|
|
75
|
+
counter: number;
|
|
76
|
+
/** The transports the authenticator reported supporting, if any (e.g. `["internal", "hybrid"]`). */
|
|
77
|
+
transports?: PasskeyTransport[];
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* The HMAC hash algorithms supported for TOTP token generation, per RFC 6238 §1.2.
|
|
81
|
+
*/
|
|
82
|
+
export type TOTPAlgorithm = "sha1" | "sha256" | "sha512";
|
|
83
|
+
/**
|
|
84
|
+
* Configuration for a TOTP (RFC 6238) issuer. Used both to generate the `otpauth://` provisioning
|
|
85
|
+
* URI (the "Key URI Format" companion convention supported by virtually every TOTP authenticator
|
|
86
|
+
* app, e.g. Google Authenticator/Authy/1Password) for enrolling a new secret, and as the default
|
|
87
|
+
* token parameters for newly registered secrets.
|
|
88
|
+
*/
|
|
89
|
+
export interface TOTPConfig {
|
|
90
|
+
/** The human-readable name of the issuing service, shown to the user by the authenticator app. */
|
|
91
|
+
issuer: string;
|
|
92
|
+
/** The number of digits each generated token contains. Default is `6`. */
|
|
93
|
+
digits?: number;
|
|
94
|
+
/** The time step, in seconds, that each generated token remains valid for. Default is `30`. */
|
|
95
|
+
period?: number;
|
|
96
|
+
/**
|
|
97
|
+
* The HMAC hash algorithm used to generate tokens. Default is `"sha1"` — the only algorithm
|
|
98
|
+
* universally supported by authenticator apps despite RFC 6238 permitting SHA-256/SHA-512.
|
|
99
|
+
*/
|
|
100
|
+
algorithm?: TOTPAlgorithm;
|
|
101
|
+
/**
|
|
102
|
+
* Specifies a tolerance window around the current time. It does not represent a strict duration in seconds
|
|
103
|
+
* (e.g., "±N seconds"), but rather dictates which periods overlap with the tolerance window `[currentTime -
|
|
104
|
+
* tolerance, currentTime + tolerance]`. Default value is `[5, 0]`.
|
|
105
|
+
*/
|
|
106
|
+
epochTolerance?: number | number[];
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Describes a secret used for TOTP authentication. The `digits`/`period`/`algorithm` parameters are
|
|
110
|
+
* captured at registration time (rather than always deferring to the current `TOTPConfig`) so a
|
|
111
|
+
* secret keeps verifying correctly even if the relying party's configured defaults change later.
|
|
112
|
+
*/
|
|
113
|
+
export interface TOTPSecret {
|
|
114
|
+
secret: string;
|
|
115
|
+
/** The number of digits the associated token contains, if it differs from the library default. */
|
|
116
|
+
digits?: number;
|
|
117
|
+
/** The time step, in seconds, that the associated token remains valid for, if it differs from the library default. */
|
|
118
|
+
period?: number;
|
|
119
|
+
/** The HMAC hash algorithm used to generate the associated token, if it differs from the library default. */
|
|
120
|
+
algorithm?: TOTPAlgorithm;
|
|
121
|
+
/**
|
|
122
|
+
* Specifies a tolerance window around the current time. It does not represent a strict duration in seconds
|
|
123
|
+
* (e.g., "±N seconds"), but rather dictates which periods overlap with the tolerance window `[currentTime -
|
|
124
|
+
* tolerance, currentTime + tolerance]`. Default value is `[5, 0]`.
|
|
125
|
+
*/
|
|
126
|
+
epochTolerance?: number | number[];
|
|
127
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./types.js";
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { BaseMongoEntity } from "@rapidrest/service-core";
|
|
2
|
+
import { Alias, AliasType } from "../types.js";
|
|
3
|
+
/**
|
|
4
|
+
* Implementation of the `Alias` interface for storage in a MongoDB database. If SQL is desired, please use
|
|
5
|
+
* `models.sql.AliasSQL` instead.
|
|
6
|
+
*
|
|
7
|
+
* @author Jean-Philippe Steinmetz
|
|
8
|
+
*/
|
|
9
|
+
export declare class AliasMongo extends BaseMongoEntity implements Alias {
|
|
10
|
+
alias: string;
|
|
11
|
+
type: AliasType;
|
|
12
|
+
userUid: string;
|
|
13
|
+
verified: boolean;
|
|
14
|
+
constructor(other?: Partial<AliasMongo>);
|
|
15
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { BaseMongoEntity } from "@rapidrest/service-core";
|
|
2
|
+
import { Contact, Preferences, Profile } from "../types.js";
|
|
3
|
+
/**
|
|
4
|
+
* Implementation of the `Profile` interface for storage in a MongoDB database. If SQL is desired, please use
|
|
5
|
+
* `models.sql.ProfileSQL` instead.
|
|
6
|
+
*
|
|
7
|
+
* @author Jean-Philippe Steinmetz
|
|
8
|
+
*/
|
|
9
|
+
export declare class ProfileMongo extends BaseMongoEntity implements Profile {
|
|
10
|
+
avatar?: string;
|
|
11
|
+
birthdate?: Date;
|
|
12
|
+
contacts: Contact[];
|
|
13
|
+
givenName?: string;
|
|
14
|
+
familyName?: string;
|
|
15
|
+
preferences: Preferences;
|
|
16
|
+
constructor(other?: Partial<ProfileMongo>);
|
|
17
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { BaseMongoEntity } from "@rapidrest/service-core";
|
|
2
|
+
import { Secret, SecretType } from "../types.js";
|
|
3
|
+
/**
|
|
4
|
+
* Implementation of the `Secret` interface for storage in a MongoDB database. If SQL is desired, please use
|
|
5
|
+
* `models.sql.SecretSQL` instead.
|
|
6
|
+
*
|
|
7
|
+
* @author Jean-Philippe Steinmetz
|
|
8
|
+
*/
|
|
9
|
+
export declare class SecretMongo extends BaseMongoEntity implements Secret {
|
|
10
|
+
data: any;
|
|
11
|
+
type: SecretType;
|
|
12
|
+
userUid: string;
|
|
13
|
+
constructor(other?: Partial<SecretMongo>);
|
|
14
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { BaseMongoEntity } from "@rapidrest/service-core";
|
|
2
|
+
import { User } from "../types.js";
|
|
3
|
+
/**
|
|
4
|
+
* Implementation of the `User` interface for storage in a MongoDB database. If SQL is desired, please use
|
|
5
|
+
* `models.sql.UserSQL` instead.
|
|
6
|
+
*
|
|
7
|
+
* @author Jean-Philippe Steinmetz
|
|
8
|
+
*/
|
|
9
|
+
export declare class UserMongo extends BaseMongoEntity implements User {
|
|
10
|
+
roles: string[];
|
|
11
|
+
scopes: string[];
|
|
12
|
+
verified: boolean;
|
|
13
|
+
constructor(other?: Partial<UserMongo>);
|
|
14
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./mongo/index.js";
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { BaseEntity } from "@rapidrest/service-core";
|
|
2
|
+
import { Alias, AliasType } from "../types.js";
|
|
3
|
+
/**
|
|
4
|
+
* Implementation of the `Alias` interface for storage in a SQL database. If MongoDB is desired, please use
|
|
5
|
+
* `models.mongo.AliasMongo` instead.
|
|
6
|
+
*
|
|
7
|
+
* @author Jean-Philippe Steinmetz
|
|
8
|
+
*/
|
|
9
|
+
export declare class AliasSQL extends BaseEntity implements Alias {
|
|
10
|
+
alias: string;
|
|
11
|
+
type: AliasType;
|
|
12
|
+
userUid: string;
|
|
13
|
+
verified: boolean;
|
|
14
|
+
constructor(other?: Partial<AliasSQL>);
|
|
15
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { BaseEntity } from "@rapidrest/service-core";
|
|
2
|
+
import { Contact, Preferences, Profile } from "../types.js";
|
|
3
|
+
/**
|
|
4
|
+
* Implementation of the `Profile` interface for storage in a SQL database. If MongoDB is desired, please use
|
|
5
|
+
* `models.mongo.ProfileMongo` instead.
|
|
6
|
+
*
|
|
7
|
+
* @author Jean-Philippe Steinmetz
|
|
8
|
+
*/
|
|
9
|
+
export declare class ProfileSQL extends BaseEntity implements Profile {
|
|
10
|
+
avatar?: string;
|
|
11
|
+
birthdate?: Date;
|
|
12
|
+
contacts: Contact[];
|
|
13
|
+
givenName?: string;
|
|
14
|
+
familyName?: string;
|
|
15
|
+
preferences: Preferences;
|
|
16
|
+
constructor(other?: Partial<ProfileSQL>);
|
|
17
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { BaseEntity } from "@rapidrest/service-core";
|
|
2
|
+
import { Secret, SecretType } from "../types.js";
|
|
3
|
+
/**
|
|
4
|
+
* Implementation of the `Secret` interface for storage in a SQL database. If MongoDB is desired, please use
|
|
5
|
+
* `models.mongo.SecretMongo` instead.
|
|
6
|
+
*
|
|
7
|
+
* @author Jean-Philippe Steinmetz
|
|
8
|
+
*/
|
|
9
|
+
export declare class SecretSQL extends BaseEntity implements Secret {
|
|
10
|
+
data: any;
|
|
11
|
+
type: SecretType;
|
|
12
|
+
userUid: string;
|
|
13
|
+
constructor(other?: Partial<SecretSQL>);
|
|
14
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { BaseEntity } from "@rapidrest/service-core";
|
|
2
|
+
import { User } from "../types.js";
|
|
3
|
+
/**
|
|
4
|
+
* Implementation of the `User` interface for storage in a SQLDB database. If MongoDB is desired, please use
|
|
5
|
+
* `models.mongo.UserMongo` instead.
|
|
6
|
+
*
|
|
7
|
+
* @author Jean-Philippe Steinmetz
|
|
8
|
+
*/
|
|
9
|
+
export declare class UserSQL extends BaseEntity implements User {
|
|
10
|
+
roles: string[];
|
|
11
|
+
scopes: string[];
|
|
12
|
+
verified: boolean;
|
|
13
|
+
constructor(other?: Partial<UserSQL>);
|
|
14
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./sql/index.js";
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
import { JWTUser } from "@rapidrest/core";
|
|
2
|
+
import { BaseEntity } from "@rapidrest/service-core";
|
|
3
|
+
/**
|
|
4
|
+
* @author Jean-Philippe Steinmetz
|
|
5
|
+
*/
|
|
6
|
+
export declare class AuthResult {
|
|
7
|
+
readonly token: string;
|
|
8
|
+
readonly user: User;
|
|
9
|
+
constructor(other: any);
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
*
|
|
13
|
+
*/
|
|
14
|
+
export declare enum AliasType {
|
|
15
|
+
EMAIL = "email",
|
|
16
|
+
NAME = "name",
|
|
17
|
+
OAUTH = "oauth",
|
|
18
|
+
PHONE = "phone"
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Defines an alternative unique identifier for a single user account.
|
|
22
|
+
*/
|
|
23
|
+
export interface Alias extends BaseEntity {
|
|
24
|
+
/** The alias to uniquely identify a specific user account. */
|
|
25
|
+
alias: string;
|
|
26
|
+
/** The type of data that the alias represents (e.g. email, phone, name). */
|
|
27
|
+
type: AliasType;
|
|
28
|
+
/** The unique identifier of the user account associated with this alias. */
|
|
29
|
+
userUid: string;
|
|
30
|
+
/** Indicates if this alias has been verified. */
|
|
31
|
+
verified: boolean;
|
|
32
|
+
}
|
|
33
|
+
export declare enum ContactType {
|
|
34
|
+
EMAIL = "email",
|
|
35
|
+
PHONE = "phone"
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Defines a single contact for a giiven user account. Contacts are stored in a user's
|
|
39
|
+
* `Profile`.
|
|
40
|
+
*
|
|
41
|
+
* @author Jean-Philippe Steinmetz
|
|
42
|
+
*/
|
|
43
|
+
export interface Contact {
|
|
44
|
+
/** The contact information of a specific kind (e.g. email, phone number, etc.). */
|
|
45
|
+
contact: string;
|
|
46
|
+
/** The type of contact information represented (e.g. email, phone). */
|
|
47
|
+
type: ContactType;
|
|
48
|
+
/** Indicates if the contact information has been verified. */
|
|
49
|
+
verified: boolean;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Defines the set of preferences for a given user account. Preferences are stored in a user's
|
|
53
|
+
* `Profile`.
|
|
54
|
+
*
|
|
55
|
+
* @author Jean-Philippe Steinmetz
|
|
56
|
+
*/
|
|
57
|
+
export interface Preferences {
|
|
58
|
+
/** The list of contact preferences for the user (e.g. 'all', 'marketing', 'system'). */
|
|
59
|
+
contact: string[];
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Defines available contact methods and preferences for a given user. Requires the `profile` scope to read.
|
|
63
|
+
*
|
|
64
|
+
* Note that the `uid` must be the same `uid` as the associated `User` record.
|
|
65
|
+
*
|
|
66
|
+
* @author Jean-Philippe Steinmetz
|
|
67
|
+
*/
|
|
68
|
+
export interface Profile extends BaseEntity {
|
|
69
|
+
/**
|
|
70
|
+
* The URL or path to the user's avatar image (e.g. gravatar).
|
|
71
|
+
*/
|
|
72
|
+
avatar?: string;
|
|
73
|
+
/**
|
|
74
|
+
* The user's date of birth.
|
|
75
|
+
*/
|
|
76
|
+
birthdate?: Date;
|
|
77
|
+
/**
|
|
78
|
+
* The list of the user's contacts.
|
|
79
|
+
*/
|
|
80
|
+
contacts: Contact[];
|
|
81
|
+
/**
|
|
82
|
+
* The user's given name (aka: first name).
|
|
83
|
+
*/
|
|
84
|
+
givenName?: string;
|
|
85
|
+
/**
|
|
86
|
+
* The user's family surname (or last name).
|
|
87
|
+
*/
|
|
88
|
+
familyName?: string;
|
|
89
|
+
/**
|
|
90
|
+
* The user's account preferences.
|
|
91
|
+
*/
|
|
92
|
+
preferences: Preferences;
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
*
|
|
96
|
+
*/
|
|
97
|
+
export declare enum SecretType {
|
|
98
|
+
FIDO2 = "fido2",
|
|
99
|
+
PASSKEY = "passkey",
|
|
100
|
+
PASSWORD = "password",
|
|
101
|
+
TOTP = "totp"
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Describes a single authentication secret associated with a specific user account. A secret is used
|
|
105
|
+
* to authenticate the user with the system.
|
|
106
|
+
*
|
|
107
|
+
* Supported types of secrets:
|
|
108
|
+
* * `fido2`
|
|
109
|
+
* * `openid`
|
|
110
|
+
* * `password`
|
|
111
|
+
* * `passkey`
|
|
112
|
+
* * `totp`
|
|
113
|
+
*
|
|
114
|
+
* @author Jean-Philippe Steinmetz
|
|
115
|
+
*/
|
|
116
|
+
export interface Secret extends BaseEntity {
|
|
117
|
+
/**
|
|
118
|
+
* The data associated with the secret.
|
|
119
|
+
*/
|
|
120
|
+
data: any;
|
|
121
|
+
/**
|
|
122
|
+
* The type of secret (e.g. `fido2`, `openid`, `password`, `passkey`, `totp`)
|
|
123
|
+
*/
|
|
124
|
+
type: SecretType;
|
|
125
|
+
/**
|
|
126
|
+
* The unique identifier of the user account this secret is associated with.
|
|
127
|
+
*/
|
|
128
|
+
userUid: string;
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* Defines a single user's account within the system.
|
|
132
|
+
*
|
|
133
|
+
* @author Jean-Philippe Steinmetz
|
|
134
|
+
*/
|
|
135
|
+
export interface User extends BaseEntity, JWTUser {
|
|
136
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { JWTUser } from "@rapidrest/core";
|
|
2
|
+
import { RepoUtils, AuthMiddleware, ObjectFactory } from "@rapidrest/service-core";
|
|
3
|
+
import { Alias, AuthResult, Secret, User } from "../models/types.js";
|
|
4
|
+
import { UserUtils } from "./UserUtils.js";
|
|
5
|
+
/**
|
|
6
|
+
*
|
|
7
|
+
*
|
|
8
|
+
* @author Jean-Philippe Steinmetz
|
|
9
|
+
*/
|
|
10
|
+
export declare abstract class BaseAuthBasicRoute<U extends User, S extends Secret, A extends Alias> {
|
|
11
|
+
protected abstract aliasClass: any;
|
|
12
|
+
protected abstract secretClass: any;
|
|
13
|
+
protected abstract userClass: any;
|
|
14
|
+
protected authMiddleware?: AuthMiddleware;
|
|
15
|
+
protected jwtConfig?: any;
|
|
16
|
+
protected objectFactory?: ObjectFactory;
|
|
17
|
+
protected secretRepo?: RepoUtils<S>;
|
|
18
|
+
protected userUtils?: UserUtils<U, A>;
|
|
19
|
+
/**
|
|
20
|
+
* Called on server startup to initialize the route with any defaults.
|
|
21
|
+
*/
|
|
22
|
+
protected initialize(): Promise<void>;
|
|
23
|
+
/**
|
|
24
|
+
* Authenticates the user using HTTP Basic and returns a JSON Web Token access token to be used with future API requests.
|
|
25
|
+
*/
|
|
26
|
+
authenticate(user: JWTUser): Promise<AuthResult | undefined>;
|
|
27
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
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
|
+
* Authenticates users via a registered FIDO2 hardware security key (e.g. a YubiKey) using
|
|
8
|
+
* WebAuthn/CTAP2. See `BaseAuthPasskeyRoute` for the software/synced-credential ("Passkey")
|
|
9
|
+
* counterpart of this route — both share the same underlying WebAuthn ceremony, but look up
|
|
10
|
+
* credentials stored as `SecretType.FIDO2` rather than `SecretType.PASSKEY`.
|
|
11
|
+
*
|
|
12
|
+
* @author Jean-Philippe Steinmetz
|
|
13
|
+
*/
|
|
14
|
+
export declare abstract class BaseAuthFIDO2Route<U extends User, A extends Alias, S extends Secret> {
|
|
15
|
+
protected abstract aliasClass: any;
|
|
16
|
+
protected abstract secretClass: any;
|
|
17
|
+
protected abstract userClass: any;
|
|
18
|
+
protected aliasRepo?: RepoUtils<A>;
|
|
19
|
+
protected authMiddleware?: AuthMiddleware;
|
|
20
|
+
protected jwtConfig?: any;
|
|
21
|
+
protected objectFactory?: ObjectFactory;
|
|
22
|
+
protected messagingUtils?: MessagingUtils;
|
|
23
|
+
protected secretRepo?: RepoUtils<S>;
|
|
24
|
+
/**
|
|
25
|
+
* The relying party configuration to use for this FIDO2 strategy. Kept separate from the Passkey
|
|
26
|
+
* strategy's configuration since a hardware key deployment commonly wants a different
|
|
27
|
+
* `authenticatorAttachment`/`residentKey` policy (see `BaseSecretRoute.fido2Config`).
|
|
28
|
+
*/
|
|
29
|
+
protected fido2Config: PasskeyConfig;
|
|
30
|
+
protected userRepo?: RepoUtils<U>;
|
|
31
|
+
protected userUtils?: UserUtils<U, A>;
|
|
32
|
+
/**
|
|
33
|
+
* Called on server startup to initialize the route with any defaults.
|
|
34
|
+
*/
|
|
35
|
+
protected initialize(): Promise<void>;
|
|
36
|
+
/**
|
|
37
|
+
* Authenticates the user using a FIDO2 hardware security key and returns a JSON Web Token access
|
|
38
|
+
* token to be used with future API requests.
|
|
39
|
+
*/
|
|
40
|
+
authenticate(user: JWTUser): Promise<AuthResult | undefined>;
|
|
41
|
+
protected getCredentialById(credentialId: string): Promise<StoredPasskeyCredential | undefined>;
|
|
42
|
+
protected getCredentials(id: string): Promise<StoredPasskeyCredential[]>;
|
|
43
|
+
/**
|
|
44
|
+
* Retrieve the user associated with a given uid or alias.
|
|
45
|
+
*
|
|
46
|
+
* @param id The unqique id of the user or alias to lookup.
|
|
47
|
+
*/
|
|
48
|
+
protected getUser(id: string): Promise<JWTUser | undefined>;
|
|
49
|
+
protected updateCredentialCounter(credentialId: string, newCounter: number): Promise<void>;
|
|
50
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { JWTUser, MessagingUtils } from "@rapidrest/core";
|
|
2
|
+
import { RepoUtils, AuthMiddleware, ObjectFactory } from "@rapidrest/service-core";
|
|
3
|
+
import { Alias, AliasType, AuthResult, Secret, User } from "../models/types.js";
|
|
4
|
+
import { MFAMethod } from "../auth/MFAStrategy.js";
|
|
5
|
+
import { OTPContact } from "../auth/types.js";
|
|
6
|
+
import { UserUtils } from "./UserUtils.js";
|
|
7
|
+
/**
|
|
8
|
+
*
|
|
9
|
+
*
|
|
10
|
+
* @author Jean-Philippe Steinmetz
|
|
11
|
+
*/
|
|
12
|
+
export declare abstract class BaseAuthMFARoute<U extends User, S extends Secret, A extends Alias> {
|
|
13
|
+
protected abstract aliasClass: any;
|
|
14
|
+
protected abstract secretClass: any;
|
|
15
|
+
protected abstract userClass: any;
|
|
16
|
+
protected aliasRepo?: RepoUtils<A>;
|
|
17
|
+
protected authMiddleware?: AuthMiddleware;
|
|
18
|
+
protected jwtConfig?: any;
|
|
19
|
+
protected objectFactory?: ObjectFactory;
|
|
20
|
+
protected messagingUtils?: MessagingUtils;
|
|
21
|
+
protected secretRepo?: RepoUtils<S>;
|
|
22
|
+
/** The name of the messaging template to use for sending notifications. */
|
|
23
|
+
protected template: string;
|
|
24
|
+
protected userRepo?: RepoUtils<U>;
|
|
25
|
+
protected userUtils?: UserUtils<U, A>;
|
|
26
|
+
/**
|
|
27
|
+
* Called on server startup to initialize the route with any defaults.
|
|
28
|
+
*/
|
|
29
|
+
protected initialize(): Promise<void>;
|
|
30
|
+
/**
|
|
31
|
+
* Authenticates the user using HTTP MFA and returns a JSON Web Token access token to be used with future API requests.
|
|
32
|
+
*/
|
|
33
|
+
authenticate(user: JWTUser): Promise<AuthResult | undefined>;
|
|
34
|
+
protected convertAliasToMethod(alias: Alias, obfuscate?: boolean): MFAMethod | undefined;
|
|
35
|
+
protected convertSecretToMethod(secret: S): MFAMethod | undefined;
|
|
36
|
+
/**
|
|
37
|
+
* Retrieves the user's secondary authentication method for a given id.
|
|
38
|
+
* @param id The unique id of the secondary auth method to retrieve.
|
|
39
|
+
*/
|
|
40
|
+
protected getMethod(id: string): Promise<MFAMethod | undefined>;
|
|
41
|
+
/**
|
|
42
|
+
* Retrieves the list of secondary authentication methods for the user with the given id. This list is sent to
|
|
43
|
+
* the user and so should be obfuscated where reasonable so as to limit discovery when a password has been
|
|
44
|
+
* compromised.
|
|
45
|
+
* @param uid The unique identifier of the user.
|
|
46
|
+
*/
|
|
47
|
+
protected getMethods(uid: string): Promise<MFAMethod[]>;
|
|
48
|
+
/**
|
|
49
|
+
* Retrieves the user with the given unique id.
|
|
50
|
+
* @param uid The unique id of the user to retrieve.
|
|
51
|
+
* @returns The user if found, otherwise `undefined`.
|
|
52
|
+
*/
|
|
53
|
+
protected getUser(uid: string): Promise<JWTUser | undefined>;
|
|
54
|
+
protected notifyContact(contact: OTPContact, totp: string): Promise<void>;
|
|
55
|
+
/**
|
|
56
|
+
* Obfuscates the given alias and returns the obfuscated value.
|
|
57
|
+
* @param contact The contact to obfuscate.
|
|
58
|
+
*/
|
|
59
|
+
protected obfuscateAlias(alias: string, type: AliasType): string;
|
|
60
|
+
protected verify(name: string, password: string): Promise<JWTUser | undefined>;
|
|
61
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import "reflect-metadata";
|
|
2
|
+
import { JWTUser, MessagingUtils } from "@rapidrest/core";
|
|
3
|
+
import { RepoUtils, AuthMiddleware, ObjectFactory } from "@rapidrest/service-core";
|
|
4
|
+
import { Alias, AuthResult, Profile, User } from "../models/types.js";
|
|
5
|
+
import { OIDCProvider } from "../auth/OIDCStrategy.js";
|
|
6
|
+
import { UserUtils } from "./UserUtils.js";
|
|
7
|
+
/**
|
|
8
|
+
*
|
|
9
|
+
*
|
|
10
|
+
* @author Jean-Philippe Steinmetz
|
|
11
|
+
*/
|
|
12
|
+
export declare abstract class BaseAuthOIDCRoute<U extends User, A extends Alias, P extends Profile> {
|
|
13
|
+
protected abstract aliasClass: any;
|
|
14
|
+
protected abstract profileClass: any;
|
|
15
|
+
protected abstract userClass: any;
|
|
16
|
+
protected aliasRepo?: RepoUtils<A>;
|
|
17
|
+
protected authMiddleware?: AuthMiddleware;
|
|
18
|
+
protected jwtConfig?: any;
|
|
19
|
+
protected objectFactory?: ObjectFactory;
|
|
20
|
+
protected messagingUtils?: MessagingUtils;
|
|
21
|
+
protected profileRepo?: RepoUtils<P>;
|
|
22
|
+
protected abstract providerConfig: OIDCProvider;
|
|
23
|
+
protected userRepo?: RepoUtils<U>;
|
|
24
|
+
protected userUtils?: UserUtils<U, A>;
|
|
25
|
+
/**
|
|
26
|
+
* Called on server startup to initialize the route with any defaults.
|
|
27
|
+
*/
|
|
28
|
+
private initialize;
|
|
29
|
+
/**
|
|
30
|
+
* Authenticates the user using OIDC and returns a JSON Web Token access token to be used with future API requests.
|
|
31
|
+
*/
|
|
32
|
+
login(user: JWTUser): Promise<AuthResult | undefined>;
|
|
33
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { JWTUser, MessagingUtils } from "@rapidrest/core";
|
|
2
|
+
import { RepoUtils, AuthMiddleware, ObjectFactory } from "@rapidrest/service-core";
|
|
3
|
+
import { Alias, AliasType, AuthResult, Secret, User } from "../models/types.js";
|
|
4
|
+
import { OTPContact, OTPContactType } from "../auth/types.js";
|
|
5
|
+
import { UserUtils } from "./UserUtils.js";
|
|
6
|
+
/**
|
|
7
|
+
*
|
|
8
|
+
*
|
|
9
|
+
* @author Jean-Philippe Steinmetz
|
|
10
|
+
*/
|
|
11
|
+
export declare abstract class BaseAuthOTPRoute<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
|
+
/** The name of the messaging template to use for sending notifications. */
|
|
22
|
+
protected template: string;
|
|
23
|
+
protected userRepo?: RepoUtils<U>;
|
|
24
|
+
protected userUtils?: UserUtils<U, A>;
|
|
25
|
+
/**
|
|
26
|
+
* Called on server startup to initialize the route with any defaults.
|
|
27
|
+
*/
|
|
28
|
+
protected initialize(): Promise<void>;
|
|
29
|
+
/**
|
|
30
|
+
* Authenticates the user using OTP and returns a JSON Web Token access token to be used with future API requests.
|
|
31
|
+
*/
|
|
32
|
+
authenticate(user: JWTUser): Promise<AuthResult | undefined>;
|
|
33
|
+
protected convertAliasType(type: AliasType): OTPContactType;
|
|
34
|
+
/**
|
|
35
|
+
* Retrieves the alias with the given unique id.
|
|
36
|
+
* @param id The unique id of the alias to retrieve.
|
|
37
|
+
* @returns The alias if found, otherwise `undefined`.
|
|
38
|
+
*/
|
|
39
|
+
protected getContact(id: string): Promise<OTPContact | undefined>;
|
|
40
|
+
/**
|
|
41
|
+
* Retrieves all aliases for the user with the given id.
|
|
42
|
+
*
|
|
43
|
+
* @param id The unique id of the user to lookup.
|
|
44
|
+
*/
|
|
45
|
+
protected getContacts(id: string): Promise<OTPContact[]>;
|
|
46
|
+
/**
|
|
47
|
+
* Retrieves the user with the given unique id.
|
|
48
|
+
* @param uid The unique id of the user to retrieve.
|
|
49
|
+
* @returns The user if found, otherwise `undefined`.
|
|
50
|
+
*/
|
|
51
|
+
protected getUser(uid: string): Promise<JWTUser | undefined>;
|
|
52
|
+
protected notifyContact(contact: OTPContact, totp: string): Promise<void>;
|
|
53
|
+
}
|