@tstdl/base 0.93.178 → 0.93.180
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/api/response.js +4 -3
- package/api/server/gateway.js +9 -3
- package/audit/auditor.d.ts +1 -2
- package/audit/drizzle/{0000_lumpy_thunderball.sql → 0000_shallow_elektra.sql} +1 -1
- package/audit/drizzle/meta/0000_snapshot.json +2 -2
- package/audit/drizzle/meta/_journal.json +2 -2
- package/authentication/README.md +87 -42
- package/authentication/authentication.api.d.ts +392 -53
- package/authentication/authentication.api.js +133 -28
- package/authentication/client/api.client.d.ts +3 -3
- package/authentication/client/api.client.js +4 -4
- package/authentication/client/authentication.service.d.ts +93 -23
- package/authentication/client/authentication.service.js +113 -28
- package/authentication/client/http-client.middleware.d.ts +1 -1
- package/authentication/client/http-client.middleware.js +5 -4
- package/authentication/client/module.d.ts +1 -1
- package/authentication/client/module.js +2 -2
- package/authentication/errors/index.d.ts +1 -1
- package/authentication/errors/index.js +1 -1
- package/authentication/errors/password-requirements.error.d.ts +5 -0
- package/authentication/errors/{secret-requirements.error.js → password-requirements.error.js} +2 -2
- package/authentication/models/authentication-password.model.d.ts +8 -0
- package/authentication/models/{authentication-credentials.model.js → authentication-password.model.js} +11 -17
- package/authentication/models/authentication-session.model.d.ts +0 -2
- package/authentication/models/authentication-session.model.js +1 -7
- package/authentication/models/authentication-totp-recovery-code.model.d.ts +6 -0
- package/authentication/models/authentication-totp-recovery-code.model.js +34 -0
- package/authentication/models/authentication-totp.model.d.ts +19 -0
- package/authentication/models/authentication-totp.model.js +51 -0
- package/authentication/models/authentication-used-totp-token.model.d.ts +5 -0
- package/authentication/models/authentication-used-totp-token.model.js +32 -0
- package/authentication/models/index.d.ts +6 -3
- package/authentication/models/index.js +6 -3
- package/authentication/models/{init-secret-reset-data.model.d.ts → init-password-reset-data.model.d.ts} +3 -3
- package/authentication/models/{init-secret-reset-data.model.js → init-password-reset-data.model.js} +5 -5
- package/authentication/models/password-check-result.model.d.ts +3 -0
- package/authentication/models/{secret-check-result.model.js → password-check-result.model.js} +6 -6
- package/authentication/models/subject.model.d.ts +0 -6
- package/authentication/models/subject.model.js +0 -6
- package/authentication/models/token.model.d.ts +16 -2
- package/authentication/server/authentication-ancillary.service.d.ts +6 -6
- package/authentication/server/authentication-ancillary.service.js +1 -1
- package/authentication/server/authentication-password-requirements.validator.d.ts +55 -0
- package/authentication/server/{authentication-secret-requirements.validator.js → authentication-password-requirements.validator.js} +22 -22
- package/authentication/server/authentication.api-controller.d.ts +55 -27
- package/authentication/server/authentication.api-controller.js +214 -39
- package/authentication/server/authentication.audit.d.ts +42 -5
- package/authentication/server/authentication.service.d.ts +182 -93
- package/authentication/server/authentication.service.js +628 -206
- package/authentication/server/drizzle/{0000_soft_tag.sql → 0000_odd_echo.sql} +59 -13
- package/authentication/server/drizzle/meta/0000_snapshot.json +345 -32
- package/authentication/server/drizzle/meta/_journal.json +2 -2
- package/authentication/server/helper.d.ts +16 -16
- package/authentication/server/helper.js +33 -34
- package/authentication/server/index.d.ts +1 -1
- package/authentication/server/index.js +1 -1
- package/authentication/server/module.d.ts +2 -2
- package/authentication/server/module.js +4 -2
- package/authentication/server/schemas.d.ts +11 -7
- package/authentication/server/schemas.js +7 -3
- package/authentication/tests/authentication-password-requirements.validator.test.js +29 -0
- package/authentication/tests/authentication.api-controller.test.js +49 -15
- package/authentication/tests/authentication.client-error-handling.test.js +3 -2
- package/authentication/tests/authentication.client-middleware.test.js +5 -5
- package/authentication/tests/authentication.client-service-methods.test.js +28 -14
- package/authentication/tests/authentication.client-service-refresh.test.js +7 -6
- package/authentication/tests/authentication.client-service.test.js +10 -8
- package/authentication/tests/authentication.service.test.js +37 -29
- package/authentication/tests/authentication.test-ancillary-service.d.ts +1 -1
- package/authentication/tests/authentication.test-ancillary-service.js +1 -1
- package/authentication/tests/brute-force-protection.test.js +211 -0
- package/authentication/tests/helper.test.js +25 -21
- package/authentication/tests/password-requirements.error.test.js +14 -0
- package/authentication/tests/remember.api.test.js +22 -14
- package/authentication/tests/remember.service.test.js +23 -16
- package/authentication/tests/subject.service.test.js +2 -2
- package/authentication/tests/suspended-subject.test.d.ts +1 -0
- package/authentication/tests/suspended-subject.test.js +120 -0
- package/authentication/tests/totp.enrollment.test.d.ts +1 -0
- package/authentication/tests/totp.enrollment.test.js +123 -0
- package/authentication/tests/totp.login.test.d.ts +1 -0
- package/authentication/tests/totp.login.test.js +213 -0
- package/authentication/tests/totp.recovery-codes.test.d.ts +1 -0
- package/authentication/tests/totp.recovery-codes.test.js +97 -0
- package/authentication/tests/totp.status.test.d.ts +1 -0
- package/authentication/tests/totp.status.test.js +72 -0
- package/circuit-breaker/postgres/drizzle/{0000_cooing_korath.sql → 0000_same_captain_cross.sql} +1 -1
- package/circuit-breaker/postgres/drizzle/meta/0000_snapshot.json +2 -2
- package/circuit-breaker/postgres/drizzle/meta/_journal.json +2 -2
- package/cryptography/cryptography.d.ts +336 -0
- package/cryptography/cryptography.js +328 -0
- package/cryptography/index.d.ts +4 -0
- package/cryptography/index.js +4 -0
- package/{utils → cryptography}/jwt.d.ts +22 -4
- package/{utils → cryptography}/jwt.js +36 -18
- package/cryptography/module.d.ts +35 -0
- package/cryptography/module.js +148 -0
- package/cryptography/tests/cryptography.test.d.ts +1 -0
- package/cryptography/tests/cryptography.test.js +175 -0
- package/cryptography/tests/jwt.test.d.ts +1 -0
- package/cryptography/tests/jwt.test.js +54 -0
- package/cryptography/tests/modern.test.d.ts +1 -0
- package/cryptography/tests/modern.test.js +105 -0
- package/cryptography/tests/module.test.d.ts +1 -0
- package/cryptography/tests/module.test.js +100 -0
- package/cryptography/tests/totp.test.d.ts +1 -0
- package/cryptography/tests/totp.test.js +108 -0
- package/cryptography/totp.d.ts +96 -0
- package/cryptography/totp.js +123 -0
- package/document-management/server/drizzle/{0000_curious_nighthawk.sql → 0000_sharp_scream.sql} +21 -21
- package/document-management/server/drizzle/meta/0000_snapshot.json +22 -22
- package/document-management/server/drizzle/meta/_journal.json +2 -2
- package/document-management/server/services/document-file.service.js +1 -1
- package/errors/errors.localization.d.ts +2 -2
- package/errors/errors.localization.js +2 -2
- package/errors/index.d.ts +1 -0
- package/errors/index.js +1 -0
- package/errors/too-many-requests.error.d.ts +5 -0
- package/errors/too-many-requests.error.js +7 -0
- package/examples/api/authentication.js +5 -5
- package/examples/api/custom-authentication.js +4 -3
- package/file/server/mime-type.js +1 -1
- package/http/http-body.d.ts +1 -0
- package/http/http-body.js +3 -0
- package/image-service/imgproxy/imgproxy-image-service.d.ts +0 -1
- package/image-service/imgproxy/imgproxy-image-service.js +9 -27
- package/key-value-store/postgres/drizzle/{0000_shocking_slipstream.sql → 0000_moaning_calypso.sql} +1 -1
- package/key-value-store/postgres/drizzle/meta/0000_snapshot.json +2 -2
- package/key-value-store/postgres/drizzle/meta/_journal.json +2 -2
- package/lock/postgres/drizzle/{0000_busy_tattoo.sql → 0000_nappy_wraith.sql} +1 -1
- package/lock/postgres/drizzle/meta/0000_snapshot.json +2 -2
- package/lock/postgres/drizzle/meta/_journal.json +2 -2
- package/logger/formatters/json.js +1 -1
- package/logger/formatters/pretty-print.js +1 -1
- package/mail/drizzle/{0000_numerous_the_watchers.sql → 0000_cultured_quicksilver.sql} +2 -2
- package/mail/drizzle/meta/0000_snapshot.json +4 -4
- package/mail/drizzle/meta/_journal.json +2 -9
- package/notification/server/drizzle/{0000_wise_pyro.sql → 0000_new_tenebrous.sql} +6 -6
- package/notification/server/drizzle/meta/0000_snapshot.json +7 -7
- package/notification/server/drizzle/meta/_journal.json +2 -2
- package/notification/tests/notification-flow.test.js +1 -8
- package/notification/tests/notification-type.service.test.js +3 -3
- package/openid-connect/oidc.service.js +2 -3
- package/orm/data-types/common.js +1 -1
- package/orm/server/drizzle/schema-converter.js +9 -4
- package/orm/server/encryption.js +1 -1
- package/orm/server/module.d.ts +0 -1
- package/orm/server/module.js +0 -4
- package/orm/server/repository.d.ts +2 -1
- package/orm/server/repository.js +7 -10
- package/orm/tests/encryption.test.js +4 -6
- package/orm/tests/repository-extra-coverage.test.js +0 -2
- package/orm/tests/repository-regression.test.js +0 -3
- package/package.json +9 -8
- package/password/README.md +1 -1
- package/password/have-i-been-pwned.js +1 -1
- package/rate-limit/postgres/drizzle/{0000_watery_rage.sql → 0000_serious_sauron.sql} +1 -1
- package/rate-limit/postgres/drizzle/meta/0000_snapshot.json +2 -2
- package/rate-limit/postgres/drizzle/meta/_journal.json +2 -2
- package/rate-limit/postgres/postgres-rate-limiter.d.ts +1 -1
- package/rate-limit/postgres/postgres-rate-limiter.js +1 -1
- package/rate-limit/rate-limiter.d.ts +1 -1
- package/rpc/tests/rpc.integration.test.js +25 -31
- package/supports.d.ts +1 -0
- package/supports.js +1 -0
- package/task-queue/postgres/drizzle/{0000_faithful_daimon_hellstrom.sql → 0000_dark_ronan.sql} +5 -5
- package/task-queue/postgres/drizzle/meta/0000_snapshot.json +10 -10
- package/task-queue/postgres/drizzle/meta/_journal.json +2 -9
- package/task-queue/postgres/task-queue.js +2 -2
- package/task-queue/tests/coverage-enhancement.test.js +2 -2
- package/test/drizzle/{0000_natural_cannonball.sql → 0000_organic_gamora.sql} +2 -2
- package/test/drizzle/meta/0000_snapshot.json +3 -4
- package/test/drizzle/meta/_journal.json +2 -9
- package/testing/integration-setup.d.ts +7 -3
- package/testing/integration-setup.js +119 -96
- package/utils/alphabet.d.ts +1 -0
- package/utils/alphabet.js +1 -0
- package/utils/base32.d.ts +4 -0
- package/utils/base32.js +49 -0
- package/utils/base64.d.ts +0 -2
- package/utils/base64.js +6 -70
- package/utils/equals.d.ts +13 -3
- package/utils/equals.js +29 -9
- package/utils/index.d.ts +1 -2
- package/utils/index.js +1 -2
- package/utils/random.d.ts +1 -0
- package/utils/random.js +14 -8
- package/authentication/errors/secret-requirements.error.d.ts +0 -5
- package/authentication/models/authentication-credentials.model.d.ts +0 -10
- package/authentication/models/secret-check-result.model.d.ts +0 -3
- package/authentication/server/authentication-secret-requirements.validator.d.ts +0 -55
- package/authentication/tests/authentication-ancillary.service.test.js +0 -13
- package/authentication/tests/authentication-secret-requirements.validator.test.js +0 -29
- package/authentication/tests/secret-requirements.error.test.js +0 -14
- package/mail/drizzle/0001_married_tarantula.sql +0 -12
- package/mail/drizzle/meta/0001_snapshot.json +0 -69
- package/orm/server/tokens.d.ts +0 -1
- package/orm/server/tokens.js +0 -2
- package/task-queue/postgres/drizzle/0001_rapid_infant_terrible.sql +0 -16
- package/task-queue/postgres/drizzle/meta/0001_snapshot.json +0 -753
- package/test/drizzle/0001_closed_the_captain.sql +0 -2
- package/test/drizzle/meta/0001_snapshot.json +0 -117
- package/utils/cryptography.d.ts +0 -137
- package/utils/cryptography.js +0 -201
- /package/authentication/tests/{authentication-ancillary.service.test.d.ts → authentication-password-requirements.validator.test.d.ts} +0 -0
- /package/authentication/tests/{authentication-secret-requirements.validator.test.d.ts → brute-force-protection.test.d.ts} +0 -0
- /package/authentication/tests/{secret-requirements.error.test.d.ts → password-requirements.error.test.d.ts} +0 -0
|
@@ -26,15 +26,52 @@ export type AuthenticationAuditEvents = {
|
|
|
26
26
|
impersonatedSubjectId: string;
|
|
27
27
|
};
|
|
28
28
|
'unimpersonate-success': {};
|
|
29
|
-
'change-
|
|
30
|
-
'change-
|
|
29
|
+
'change-password-success': {};
|
|
30
|
+
'change-password-failure': {
|
|
31
31
|
subjectInput: SubjectInput;
|
|
32
32
|
resolvedSubjectId: string | null;
|
|
33
33
|
};
|
|
34
|
-
'init-
|
|
35
|
-
'reset-
|
|
36
|
-
'reset-
|
|
34
|
+
'init-password-reset': {};
|
|
35
|
+
'reset-password-success': {};
|
|
36
|
+
'reset-password-failure': {
|
|
37
37
|
reason: string;
|
|
38
38
|
};
|
|
39
|
+
'rate-limit-exceeded': {
|
|
40
|
+
type: 'ip' | 'subject';
|
|
41
|
+
resource: string;
|
|
42
|
+
action: string;
|
|
43
|
+
};
|
|
39
44
|
'invalidate-all-sessions': {};
|
|
45
|
+
'invalidate-all-other-sessions': {
|
|
46
|
+
currentSessionId: string;
|
|
47
|
+
};
|
|
48
|
+
'totp-enroll-init': {
|
|
49
|
+
subjectId: string;
|
|
50
|
+
};
|
|
51
|
+
'totp-enroll-success': {};
|
|
52
|
+
'totp-enroll-failure': {
|
|
53
|
+
reason: string;
|
|
54
|
+
};
|
|
55
|
+
'totp-disable-success': {};
|
|
56
|
+
'totp-disable-failure': {
|
|
57
|
+
reason: string;
|
|
58
|
+
};
|
|
59
|
+
'totp-verify-failure': {
|
|
60
|
+
reason: string;
|
|
61
|
+
};
|
|
62
|
+
'totp-token-reused': {
|
|
63
|
+
token: string;
|
|
64
|
+
};
|
|
65
|
+
'totp-recovery-code-used': {};
|
|
66
|
+
'recovery-codes-regenerated': {
|
|
67
|
+
count: number;
|
|
68
|
+
};
|
|
69
|
+
'recovery-login-success': {
|
|
70
|
+
sessionId: string;
|
|
71
|
+
remember: boolean;
|
|
72
|
+
};
|
|
73
|
+
'recovery-login-failure': {
|
|
74
|
+
subjectInput: SubjectInput;
|
|
75
|
+
resolvedSubjectId: string | null;
|
|
76
|
+
};
|
|
40
77
|
};
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
/** biome-ignore-all lint/nursery/noExcessiveClassesPerFile: <explanation> */
|
|
2
2
|
import { Auditor } from '../../audit/index.js';
|
|
3
|
-
import {
|
|
4
|
-
import type {
|
|
5
|
-
import { AuthenticationSession, Subject, type
|
|
3
|
+
import { type Argon2Params, type TotpHashAlgorithm } from '../../cryptography/index.js';
|
|
4
|
+
import type { Record, TypedOmit } from '../../types/index.js';
|
|
5
|
+
import { AuthenticationSession, AuthenticationTotp, Subject, type PasswordCheckResult, type PasswordResetToken, type RefreshToken, type Token, type TotpChallengeToken } from '../models/index.js';
|
|
6
6
|
import type { SubjectInput } from '../types.js';
|
|
7
|
-
import { type
|
|
7
|
+
import { type PasswordTestResult } from './authentication-password-requirements.validator.js';
|
|
8
8
|
/**
|
|
9
9
|
* Data for creating a token.
|
|
10
10
|
*
|
|
@@ -33,15 +33,6 @@ export type CreateTokenData<AdditionalTokenPayload extends Record> = {
|
|
|
33
33
|
timestamp?: number;
|
|
34
34
|
};
|
|
35
35
|
export declare class AuthenticationServiceOptions {
|
|
36
|
-
/**
|
|
37
|
-
* Secrets used for signing tokens and refreshTokens.
|
|
38
|
-
* If single secret is provided, multiple secrets are derived internally.
|
|
39
|
-
*/
|
|
40
|
-
secret: string | BinaryData<ArrayBuffer> | {
|
|
41
|
-
tokenSigningSecret: Uint8Array<ArrayBuffer>;
|
|
42
|
-
refreshTokenSigningSecret: Uint8Array<ArrayBuffer>;
|
|
43
|
-
secretResetTokenSigningSecret: Uint8Array<ArrayBuffer>;
|
|
44
|
-
};
|
|
45
36
|
/**
|
|
46
37
|
* Token version, forces refresh on mismatch (useful if payload changes).
|
|
47
38
|
*
|
|
@@ -67,24 +58,79 @@ export declare class AuthenticationServiceOptions {
|
|
|
67
58
|
*/
|
|
68
59
|
rememberRefreshTokenTimeToLive?: number;
|
|
69
60
|
/**
|
|
70
|
-
* How long a
|
|
61
|
+
* How long a password reset token is valid in milliseconds.
|
|
71
62
|
*
|
|
72
63
|
* @default 10 minutes
|
|
73
64
|
*/
|
|
74
|
-
|
|
65
|
+
passwordResetTokenTimeToLive?: number;
|
|
75
66
|
/**
|
|
76
|
-
*
|
|
67
|
+
* How long a TOTP challenge token is valid in milliseconds.
|
|
77
68
|
*
|
|
78
|
-
* @default
|
|
69
|
+
* @default 5 minutes
|
|
79
70
|
*/
|
|
80
|
-
|
|
71
|
+
totpChallengeTokenTimeToLive?: number;
|
|
81
72
|
/**
|
|
82
|
-
*
|
|
83
|
-
|
|
84
|
-
|
|
73
|
+
* Options for brute force protection.
|
|
74
|
+
*/
|
|
75
|
+
bruteForceProtection?: BruteForceProtectionOptions;
|
|
76
|
+
/**
|
|
77
|
+
* TOTP issuer name.
|
|
85
78
|
*/
|
|
86
|
-
|
|
79
|
+
totpIssuer?: string;
|
|
80
|
+
/**
|
|
81
|
+
* Options for password hashing.
|
|
82
|
+
*/
|
|
83
|
+
passwordHashing?: PasswordHashingOptions;
|
|
84
|
+
/**
|
|
85
|
+
* Options for TOTP.
|
|
86
|
+
*/
|
|
87
|
+
totp?: TotpHashingOptions;
|
|
87
88
|
}
|
|
89
|
+
/**
|
|
90
|
+
* Options for password hashing.
|
|
91
|
+
*/
|
|
92
|
+
export type PasswordHashingOptions = {
|
|
93
|
+
algorithm: TypedOmit<Argon2Params, 'nonce'>;
|
|
94
|
+
};
|
|
95
|
+
/**
|
|
96
|
+
* Options for TOTP.
|
|
97
|
+
*/
|
|
98
|
+
export type TotpHashingOptions = {
|
|
99
|
+
codeHashAlgorithm: TotpHashAlgorithm;
|
|
100
|
+
recoveryCodeHashOptions: {
|
|
101
|
+
algorithm: TypedOmit<Argon2Params, 'nonce'>;
|
|
102
|
+
length: number;
|
|
103
|
+
};
|
|
104
|
+
};
|
|
105
|
+
/**
|
|
106
|
+
* Options for brute force protection.
|
|
107
|
+
*/
|
|
108
|
+
export type BruteForceProtectionOptions = {
|
|
109
|
+
/**
|
|
110
|
+
* Burst capacity for subject rate limit.
|
|
111
|
+
*
|
|
112
|
+
* @default 10
|
|
113
|
+
*/
|
|
114
|
+
subjectBurstCapacity?: number;
|
|
115
|
+
/**
|
|
116
|
+
* Refill interval for subject rate limit in milliseconds.
|
|
117
|
+
*
|
|
118
|
+
* @default 1800000 (30 minutes)
|
|
119
|
+
*/
|
|
120
|
+
subjectRefillInterval?: number;
|
|
121
|
+
/**
|
|
122
|
+
* Burst capacity for ip rate limit.
|
|
123
|
+
*
|
|
124
|
+
* @default 20
|
|
125
|
+
*/
|
|
126
|
+
ipBurstCapacity?: number;
|
|
127
|
+
/**
|
|
128
|
+
* Refill interval for ip rate limit in milliseconds.
|
|
129
|
+
*
|
|
130
|
+
* @default 300000 (5 minutes)
|
|
131
|
+
*/
|
|
132
|
+
ipRefillInterval?: number;
|
|
133
|
+
};
|
|
88
134
|
/**
|
|
89
135
|
* Result of an authentication attempt.
|
|
90
136
|
*/
|
|
@@ -109,7 +155,17 @@ export type TokenResult<AdditionalTokenPayload extends Record> = {
|
|
|
109
155
|
impersonatorRefreshToken?: string;
|
|
110
156
|
impersonatorRefreshTokenExpiration?: number;
|
|
111
157
|
};
|
|
112
|
-
export type
|
|
158
|
+
export type LoginSuccessResult<AdditionalTokenPayload extends Record> = {
|
|
159
|
+
type: 'success';
|
|
160
|
+
result: TokenResult<AdditionalTokenPayload>;
|
|
161
|
+
lowRecoveryCodesWarning?: boolean;
|
|
162
|
+
};
|
|
163
|
+
export type LoginTotpResult = {
|
|
164
|
+
type: 'totp';
|
|
165
|
+
challengeToken: string;
|
|
166
|
+
};
|
|
167
|
+
export type LoginResult<AdditionalTokenPayload extends Record> = LoginSuccessResult<AdditionalTokenPayload> | LoginTotpResult;
|
|
168
|
+
export type SetPasswordOptions = {
|
|
113
169
|
/**
|
|
114
170
|
* Skip validation for password strength.
|
|
115
171
|
*
|
|
@@ -133,24 +189,15 @@ type CreateRefreshTokenResult = {
|
|
|
133
189
|
salt: Uint8Array<ArrayBuffer>;
|
|
134
190
|
hash: Uint8Array<ArrayBuffer>;
|
|
135
191
|
};
|
|
192
|
+
export declare const DEFAULT_TOTP_OPTIONS: TotpHashingOptions;
|
|
136
193
|
/**
|
|
137
194
|
* Handles authentication on server side.
|
|
138
195
|
*
|
|
139
|
-
* Can be used to:
|
|
140
|
-
* - Set credentials
|
|
141
|
-
* - Authenticate
|
|
142
|
-
* - Get token
|
|
143
|
-
* - End session
|
|
144
|
-
* - Refresh token
|
|
145
|
-
* - Impersonate/unimpersonate
|
|
146
|
-
* - Reset secret
|
|
147
|
-
* - Check secret
|
|
148
|
-
*
|
|
149
196
|
* @template AdditionalTokenPayload Type of additional token payload
|
|
150
197
|
* @template AuthenticationData Type of additional authentication data
|
|
151
|
-
* @template
|
|
198
|
+
* @template AdditionalInitPasswordResetData Type of additional password reset data
|
|
152
199
|
*/
|
|
153
|
-
export declare class AuthenticationService<AdditionalTokenPayload extends Record = Record<never>, AuthenticationData = void,
|
|
200
|
+
export declare class AuthenticationService<AdditionalTokenPayload extends Record = Record<never>, AuthenticationData = void, AdditionalInitPasswordResetData = void> {
|
|
154
201
|
#private;
|
|
155
202
|
readonly hooks: {
|
|
156
203
|
beforeLogin: import("../../utils/async-hook/async-hook.js").AsyncHook<{
|
|
@@ -159,10 +206,10 @@ export declare class AuthenticationService<AdditionalTokenPayload extends Record
|
|
|
159
206
|
afterLogin: import("../../utils/async-hook/async-hook.js").AsyncHook<{
|
|
160
207
|
subject: Subject;
|
|
161
208
|
}, never, unknown>;
|
|
162
|
-
|
|
209
|
+
beforeChangePassword: import("../../utils/async-hook/async-hook.js").AsyncHook<{
|
|
163
210
|
subject: Subject;
|
|
164
211
|
}, never, unknown>;
|
|
165
|
-
|
|
212
|
+
afterChangePassword: import("../../utils/async-hook/async-hook.js").AsyncHook<{
|
|
166
213
|
subject: Subject;
|
|
167
214
|
}, never, unknown>;
|
|
168
215
|
};
|
|
@@ -170,34 +217,31 @@ export declare class AuthenticationService<AdditionalTokenPayload extends Record
|
|
|
170
217
|
private readonly tokenTimeToLive;
|
|
171
218
|
private readonly refreshTokenTimeToLive;
|
|
172
219
|
private readonly rememberRefreshTokenTimeToLive;
|
|
173
|
-
private readonly
|
|
174
|
-
private
|
|
175
|
-
private
|
|
176
|
-
|
|
177
|
-
/** @internal */
|
|
178
|
-
[afterResolve](): Promise<void>;
|
|
179
|
-
/**
|
|
180
|
-
* Initializes the service.
|
|
181
|
-
* Derives signing secrets if necessary.
|
|
182
|
-
*
|
|
183
|
-
* @internal
|
|
184
|
-
*/
|
|
185
|
-
initialize(): Promise<void>;
|
|
220
|
+
private readonly passwordResetTokenTimeToLive;
|
|
221
|
+
private readonly totpOptions;
|
|
222
|
+
private readonly hashDeriveOptions;
|
|
223
|
+
getTotpOptions(): TotpHashingOptions;
|
|
186
224
|
/**
|
|
187
|
-
* Sets the
|
|
188
|
-
* This method should not be exposed to the public API without an authenticated current password or
|
|
189
|
-
* @param subject The subject to set the
|
|
190
|
-
* @param
|
|
191
|
-
* @param options Options for setting the
|
|
225
|
+
* Sets the password for a subject.
|
|
226
|
+
* This method should not be exposed to the public API without an authenticated current password or password reset token check.
|
|
227
|
+
* @param subject The subject to set the password for.
|
|
228
|
+
* @param password The password to set.
|
|
229
|
+
* @param options Options for setting the password.
|
|
192
230
|
*/
|
|
193
|
-
|
|
231
|
+
setPassword(subject: Subject, password: string, options?: SetPasswordOptions): Promise<void>;
|
|
194
232
|
/**
|
|
195
|
-
* Authenticates a subject with a
|
|
233
|
+
* Authenticates a subject with a password.
|
|
196
234
|
* @param subject The subject to authenticate.
|
|
197
|
-
* @param
|
|
235
|
+
* @param password The password to authenticate with.
|
|
198
236
|
* @returns The result of the authentication.
|
|
199
237
|
*/
|
|
200
|
-
|
|
238
|
+
authenticateWithPassword(subject: SubjectInput, password: string): Promise<AuthenticationResult>;
|
|
239
|
+
/**
|
|
240
|
+
* Ensures that a subject is not suspended.
|
|
241
|
+
* @param subject The subject to check.
|
|
242
|
+
* @throws {ForbiddenError} If the subject is suspended.
|
|
243
|
+
*/
|
|
244
|
+
ensureNotSuspended(subject: Subject): void;
|
|
201
245
|
/**
|
|
202
246
|
* Gets a token for a subject.
|
|
203
247
|
* @param subject The subject to get the token for.
|
|
@@ -212,13 +256,14 @@ export declare class AuthenticationService<AdditionalTokenPayload extends Record
|
|
|
212
256
|
/**
|
|
213
257
|
* Logs in a subject.
|
|
214
258
|
* @param subjectInput The subject to log in.
|
|
215
|
-
* @param
|
|
259
|
+
* @param password The password to log in with.
|
|
216
260
|
* @param data Additional authentication data.
|
|
217
261
|
* @param auditor Auditor for auditing.
|
|
218
262
|
* @param remember Whether to remember the session.
|
|
219
|
-
* @returns Token
|
|
263
|
+
* @returns Token or TOTP challenge.
|
|
220
264
|
*/
|
|
221
|
-
login(subjectInput: SubjectInput,
|
|
265
|
+
login(subjectInput: SubjectInput, password: string, data: AuthenticationData, auditor: Auditor, remember?: boolean): Promise<LoginResult<AdditionalTokenPayload>>;
|
|
266
|
+
loginAlreadyValidatedSubject(subject: Subject, data: AuthenticationData, auditor: Auditor, remember: boolean): Promise<LoginSuccessResult<AdditionalTokenPayload>>;
|
|
222
267
|
/**
|
|
223
268
|
* Ends a session.
|
|
224
269
|
* @param sessionId The id of the session to end.
|
|
@@ -232,6 +277,14 @@ export declare class AuthenticationService<AdditionalTokenPayload extends Record
|
|
|
232
277
|
* @param auditor Auditor for auditing.
|
|
233
278
|
*/
|
|
234
279
|
invalidateAllSessions(tenantId: string, subjectId: string, auditor: Auditor): Promise<void>;
|
|
280
|
+
/**
|
|
281
|
+
* Invalidates all sessions for a subject except the current one.
|
|
282
|
+
* @param tenantId The tenant id of the subject.
|
|
283
|
+
* @param subjectId The id of the subject.
|
|
284
|
+
* @param currentSessionId The id of the current session to keep.
|
|
285
|
+
* @param auditor Auditor for auditing.
|
|
286
|
+
*/
|
|
287
|
+
invalidateAllOtherSessions(tenantId: string, subjectId: string, currentSessionId: string, auditor: Auditor): Promise<void>;
|
|
235
288
|
/**
|
|
236
289
|
* Lists all sessions for a subject.
|
|
237
290
|
* @param tenantId The tenant id of the subject.
|
|
@@ -263,6 +316,18 @@ export declare class AuthenticationService<AdditionalTokenPayload extends Record
|
|
|
263
316
|
refresh(refreshToken: string, authenticationData: AuthenticationData, options: {
|
|
264
317
|
omitImpersonator?: boolean;
|
|
265
318
|
} | undefined, auditor: Auditor): Promise<TokenResult<AdditionalTokenPayload>>;
|
|
319
|
+
/**
|
|
320
|
+
* Refreshes a token.
|
|
321
|
+
* @param refreshToken The refresh token to use.
|
|
322
|
+
* @param authenticationData Additional authentication data.
|
|
323
|
+
* @param options Options for refreshing the token.
|
|
324
|
+
* @param auditor Auditor for auditing.
|
|
325
|
+
* @returns The token result.
|
|
326
|
+
* @throws {InvalidTokenError} If the refresh token is invalid.
|
|
327
|
+
*/
|
|
328
|
+
refreshAlreadyValidatedToken(validatedRefreshToken: RefreshToken, authenticationData: AuthenticationData, options: {
|
|
329
|
+
omitImpersonator?: boolean;
|
|
330
|
+
} | undefined, auditor: Auditor): Promise<TokenResult<AdditionalTokenPayload>>;
|
|
266
331
|
/**
|
|
267
332
|
* Impersonates a subject.
|
|
268
333
|
* @param impersonatorToken The token of the impersonator.
|
|
@@ -277,53 +342,54 @@ export declare class AuthenticationService<AdditionalTokenPayload extends Record
|
|
|
277
342
|
/**
|
|
278
343
|
* Unimpersonates a subject.
|
|
279
344
|
* @param impersonatorRefreshToken The refresh token of the impersonator.
|
|
345
|
+
* @param tokenString The token of the impersonated subject to end the session.
|
|
280
346
|
* @param authenticationData Additional authentication data.
|
|
281
347
|
* @param auditor Auditor for auditing.
|
|
282
348
|
* @returns The token result.
|
|
283
349
|
*/
|
|
284
|
-
unimpersonate(impersonatorRefreshToken: string, authenticationData: AuthenticationData, auditor: Auditor): Promise<TokenResult<AdditionalTokenPayload>>;
|
|
350
|
+
unimpersonate(impersonatorRefreshToken: string, tokenString: string, authenticationData: AuthenticationData, auditor: Auditor): Promise<TokenResult<AdditionalTokenPayload>>;
|
|
285
351
|
/**
|
|
286
|
-
* Initializes a
|
|
287
|
-
* @param subject The subject to reset the
|
|
288
|
-
* @param data Additional data for the
|
|
352
|
+
* Initializes a password reset. This usually involves sending an email for verification.
|
|
353
|
+
* @param subject The subject to reset the password for.
|
|
354
|
+
* @param data Additional data for the password reset.
|
|
289
355
|
* @param auditor Auditor for auditing.
|
|
290
356
|
* @throws {NotImplementedError} If no ancillary service is registered.
|
|
291
357
|
*/
|
|
292
|
-
|
|
358
|
+
initPasswordReset(subject: SubjectInput, data: AdditionalInitPasswordResetData, auditor: Auditor): Promise<void>;
|
|
293
359
|
/**
|
|
294
|
-
* Changes a subject's
|
|
295
|
-
* @param subjectInput The subject to change the
|
|
296
|
-
* @param
|
|
297
|
-
* @param
|
|
360
|
+
* Changes a subject's password.
|
|
361
|
+
* @param subjectInput The subject to change the password for.
|
|
362
|
+
* @param currentPassword The current password.
|
|
363
|
+
* @param newPassword The new password.
|
|
298
364
|
* @param auditor Auditor for auditing.
|
|
299
365
|
*/
|
|
300
|
-
|
|
366
|
+
changePassword(subjectInput: SubjectInput, currentPassword: string, newPassword: string, auditor: Auditor): Promise<void>;
|
|
301
367
|
/**
|
|
302
|
-
* Resets a
|
|
303
|
-
* @param tokenString The
|
|
304
|
-
* @param
|
|
368
|
+
* Resets a password.
|
|
369
|
+
* @param tokenString The password reset token.
|
|
370
|
+
* @param newPassword The new password.
|
|
305
371
|
* @param auditor Auditor for auditing.
|
|
306
372
|
* @throws {InvalidTokenError} If the token is invalid.
|
|
307
373
|
*/
|
|
308
|
-
|
|
374
|
+
resetPassword(tokenString: string, newPassword: string, auditor: Auditor): Promise<void>;
|
|
309
375
|
/**
|
|
310
|
-
* Checks a
|
|
311
|
-
* @param
|
|
376
|
+
* Checks a password against the requirements.
|
|
377
|
+
* @param password The password to check.
|
|
312
378
|
* @returns The result of the check.
|
|
313
379
|
*/
|
|
314
|
-
|
|
380
|
+
checkPassword(password: string): Promise<PasswordCheckResult>;
|
|
315
381
|
/**
|
|
316
|
-
* Tests a
|
|
317
|
-
* @param
|
|
382
|
+
* Tests a password against the requirements.
|
|
383
|
+
* @param password The password to test.
|
|
318
384
|
* @returns The result of the test.
|
|
319
385
|
*/
|
|
320
|
-
|
|
386
|
+
testPassword(password: string): Promise<PasswordTestResult>;
|
|
321
387
|
/**
|
|
322
|
-
* Validates a
|
|
323
|
-
* @param
|
|
324
|
-
* @throws {
|
|
388
|
+
* Validates a password against the requirements. Throws an error if the requirements are not met.
|
|
389
|
+
* @param password The password to validate.
|
|
390
|
+
* @throws {PasswordRequirementsError} If the password does not meet the requirements.
|
|
325
391
|
*/
|
|
326
|
-
|
|
392
|
+
validatePassword(password: string): Promise<void>;
|
|
327
393
|
/**
|
|
328
394
|
* Validates a token.
|
|
329
395
|
* @param token The token to validate.
|
|
@@ -339,12 +405,12 @@ export declare class AuthenticationService<AdditionalTokenPayload extends Record
|
|
|
339
405
|
*/
|
|
340
406
|
validateRefreshToken(token: string): Promise<RefreshToken>;
|
|
341
407
|
/**
|
|
342
|
-
* Validates a
|
|
343
|
-
* @param token The
|
|
344
|
-
* @returns The validated
|
|
345
|
-
* @throws {InvalidTokenError} If the
|
|
408
|
+
* Validates a password reset token.
|
|
409
|
+
* @param token The password reset token to validate.
|
|
410
|
+
* @returns The validated password reset token.
|
|
411
|
+
* @throws {InvalidTokenError} If the password reset token is invalid.
|
|
346
412
|
*/
|
|
347
|
-
|
|
413
|
+
validatePasswordResetToken(token: string): Promise<PasswordResetToken>;
|
|
348
414
|
/**
|
|
349
415
|
* Tries to resolve a subject.
|
|
350
416
|
* @param subject The subject to resolve.
|
|
@@ -387,8 +453,31 @@ export declare class AuthenticationService<AdditionalTokenPayload extends Record
|
|
|
387
453
|
tenantId?: string;
|
|
388
454
|
subject: string;
|
|
389
455
|
}): Promise<Subject>;
|
|
390
|
-
private
|
|
391
|
-
private deriveSigningSecrets;
|
|
456
|
+
private createPasswordResetToken;
|
|
392
457
|
private getHash;
|
|
458
|
+
tryGetTotp(tenantId: string, subjectId: string): Promise<AuthenticationTotp | undefined>;
|
|
459
|
+
getTotpStatus(tenantId: string, subjectId: string): Promise<{
|
|
460
|
+
active: boolean;
|
|
461
|
+
}>;
|
|
462
|
+
initEnrollTotp(tenantId: string, subjectId: string, auditor: Auditor): Promise<{
|
|
463
|
+
secret: string;
|
|
464
|
+
uri: string;
|
|
465
|
+
}>;
|
|
466
|
+
completeEnrollTotp(tenantId: string, subjectId: string, token: string, auditor: Auditor): Promise<{
|
|
467
|
+
recoveryCodes: string[];
|
|
468
|
+
}>;
|
|
469
|
+
disableTotp(tenantId: string, subjectId: string, token: string, auditor: Auditor): Promise<void>;
|
|
470
|
+
disableTotpWithRecoveryCode(tenantId: string, subjectId: string, recoveryCode: string, auditor: Auditor): Promise<void>;
|
|
471
|
+
regenerateRecoveryCodes(tenantId: string, subjectId: string, token: string, auditor: Auditor, options?: {
|
|
472
|
+
invalidateOtherSessions?: boolean;
|
|
473
|
+
}): Promise<{
|
|
474
|
+
recoveryCodes: string[];
|
|
475
|
+
}>;
|
|
476
|
+
loginVerifyTotp(challengeTokenString: string, token: string, auditor: Auditor): Promise<LoginSuccessResult<AdditionalTokenPayload>>;
|
|
477
|
+
loginRecovery(challengeTokenString: string, recoveryCode: string, auditor: Auditor): Promise<LoginSuccessResult<AdditionalTokenPayload>>;
|
|
478
|
+
validateTotpChallengeToken(tokenString: string): Promise<TotpChallengeToken<AuthenticationData>>;
|
|
479
|
+
private createTotpChallengeToken;
|
|
480
|
+
private verifyAndUseRecoveryCode;
|
|
481
|
+
private verifyAndRecordTotpToken;
|
|
393
482
|
}
|
|
394
483
|
export {};
|