@opencloudcms/oauth2 0.0.0-stage → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +397 -2
- package/dist/audit/audit.service.d.ts +18 -0
- package/dist/audit/audit.service.js +61 -0
- package/dist/audit/audit.service.js.map +1 -0
- package/dist/bff/auth.controller.d.ts +41 -0
- package/dist/bff/auth.controller.js +269 -0
- package/dist/bff/auth.controller.js.map +1 -0
- package/dist/bff/cookies.d.ts +11 -0
- package/dist/bff/cookies.js +43 -0
- package/dist/bff/cookies.js.map +1 -0
- package/dist/bff/oidc-client.d.ts +73 -0
- package/dist/bff/oidc-client.js +158 -0
- package/dist/bff/oidc-client.js.map +1 -0
- package/dist/bff/session-refresher.d.ts +27 -0
- package/dist/bff/session-refresher.js +95 -0
- package/dist/bff/session-refresher.js.map +1 -0
- package/dist/bff/session.store.d.ts +88 -0
- package/dist/bff/session.store.js +167 -0
- package/dist/bff/session.store.js.map +1 -0
- package/dist/clients/clients.d.ts +37 -0
- package/dist/clients/clients.js +107 -0
- package/dist/clients/clients.js.map +1 -0
- package/dist/config/schema.d.ts +91 -0
- package/dist/config/schema.js +129 -0
- package/dist/config/schema.js.map +1 -0
- package/dist/constants.d.ts +45 -0
- package/dist/constants.js +42 -0
- package/dist/constants.js.map +1 -0
- package/dist/cors/cors-origins.controller.d.ts +19 -0
- package/dist/cors/cors-origins.controller.js +122 -0
- package/dist/cors/cors-origins.controller.js.map +1 -0
- package/dist/cors/cors-origins.service.d.ts +73 -0
- package/dist/cors/cors-origins.service.js +287 -0
- package/dist/cors/cors-origins.service.js.map +1 -0
- package/dist/cors/customer-cors.middleware.d.ts +22 -0
- package/dist/cors/customer-cors.middleware.js +84 -0
- package/dist/cors/customer-cors.middleware.js.map +1 -0
- package/dist/customers/account.controller.d.ts +91 -0
- package/dist/customers/account.controller.js +443 -0
- package/dist/customers/account.controller.js.map +1 -0
- package/dist/customers/auth-hooks.d.ts +47 -0
- package/dist/customers/auth-hooks.js +79 -0
- package/dist/customers/auth-hooks.js.map +1 -0
- package/dist/customers/customer-auth.controller.d.ts +54 -0
- package/dist/customers/customer-auth.controller.js +287 -0
- package/dist/customers/customer-auth.controller.js.map +1 -0
- package/dist/customers/customer-sessions.revoker.d.ts +21 -0
- package/dist/customers/customer-sessions.revoker.js +47 -0
- package/dist/customers/customer-sessions.revoker.js.map +1 -0
- package/dist/customers/customer.service.d.ts +53 -0
- package/dist/customers/customer.service.js +229 -0
- package/dist/customers/customer.service.js.map +1 -0
- package/dist/customers/customers-admin.controller.d.ts +21 -0
- package/dist/customers/customers-admin.controller.js +134 -0
- package/dist/customers/customers-admin.controller.js.map +1 -0
- package/dist/customers/identifier.d.ts +6 -0
- package/dist/customers/identifier.js +27 -0
- package/dist/customers/identifier.js.map +1 -0
- package/dist/customers/sign-in-settings.controller.d.ts +27 -0
- package/dist/customers/sign-in-settings.controller.js +112 -0
- package/dist/customers/sign-in-settings.controller.js.map +1 -0
- package/dist/customers/sign-in-settings.service.d.ts +35 -0
- package/dist/customers/sign-in-settings.service.js +130 -0
- package/dist/customers/sign-in-settings.service.js.map +1 -0
- package/dist/db/migrations/index.d.ts +2 -0
- package/dist/db/migrations/index.js +14 -0
- package/dist/db/migrations/index.js.map +1 -0
- package/dist/db/migrations/oauth2_0001_init.d.ts +2 -0
- package/dist/db/migrations/oauth2_0001_init.js +127 -0
- package/dist/db/migrations/oauth2_0001_init.js.map +1 -0
- package/dist/db/migrations/oauth2_0002_user_locale.d.ts +3 -0
- package/dist/db/migrations/oauth2_0002_user_locale.js +13 -0
- package/dist/db/migrations/oauth2_0002_user_locale.js.map +1 -0
- package/dist/db/migrations/oauth2_0003_groups.d.ts +6 -0
- package/dist/db/migrations/oauth2_0003_groups.js +46 -0
- package/dist/db/migrations/oauth2_0003_groups.js.map +1 -0
- package/dist/db/migrations/oauth2_0004_customers.d.ts +3 -0
- package/dist/db/migrations/oauth2_0004_customers.js +108 -0
- package/dist/db/migrations/oauth2_0004_customers.js.map +1 -0
- package/dist/db/types.d.ts +176 -0
- package/dist/db/types.js +3 -0
- package/dist/db/types.js.map +1 -0
- package/dist/errors.d.ts +28 -0
- package/dist/errors.js +115 -0
- package/dist/errors.js.map +1 -0
- package/dist/groups/groups.controller.d.ts +28 -0
- package/dist/groups/groups.controller.js +126 -0
- package/dist/groups/groups.controller.js.map +1 -0
- package/dist/groups/groups.service.d.ts +38 -0
- package/dist/groups/groups.service.js +134 -0
- package/dist/groups/groups.service.js.map +1 -0
- package/dist/guard/auth.guard.d.ts +29 -0
- package/dist/guard/auth.guard.js +119 -0
- package/dist/guard/auth.guard.js.map +1 -0
- package/dist/guard/current-user.decorator.d.ts +33 -0
- package/dist/guard/current-user.decorator.js +16 -0
- package/dist/guard/current-user.decorator.js.map +1 -0
- package/dist/guard/customer-auth.decorator.d.ts +26 -0
- package/dist/guard/customer-auth.decorator.js +16 -0
- package/dist/guard/customer-auth.decorator.js.map +1 -0
- package/dist/guard/customer-authenticator.d.ts +58 -0
- package/dist/guard/customer-authenticator.js +215 -0
- package/dist/guard/customer-authenticator.js.map +1 -0
- package/dist/guard/public.decorator.d.ts +2 -0
- package/dist/guard/public.decorator.js +8 -0
- package/dist/guard/public.decorator.js.map +1 -0
- package/dist/guard/session-auth.service.d.ts +28 -0
- package/dist/guard/session-auth.service.js +125 -0
- package/dist/guard/session-auth.service.js.map +1 -0
- package/dist/idp/identity-linker.d.ts +19 -0
- package/dist/idp/identity-linker.js +93 -0
- package/dist/idp/identity-linker.js.map +1 -0
- package/dist/idp/identity-provider.d.ts +54 -0
- package/dist/idp/identity-provider.js +36 -0
- package/dist/idp/identity-provider.js.map +1 -0
- package/dist/idp/idp.controller.d.ts +36 -0
- package/dist/idp/idp.controller.js +232 -0
- package/dist/idp/idp.controller.js.map +1 -0
- package/dist/idp/oidc.identity-provider.d.ts +42 -0
- package/dist/idp/oidc.identity-provider.js +96 -0
- package/dist/idp/oidc.identity-provider.js.map +1 -0
- package/dist/index.d.ts +50 -0
- package/dist/index.js +98 -0
- package/dist/index.js.map +1 -0
- package/dist/interaction/customer-interaction.controller.d.ts +64 -0
- package/dist/interaction/customer-interaction.controller.js +336 -0
- package/dist/interaction/customer-interaction.controller.js.map +1 -0
- package/dist/interaction/interaction.controller.d.ts +36 -0
- package/dist/interaction/interaction.controller.js +175 -0
- package/dist/interaction/interaction.controller.js.map +1 -0
- package/dist/interaction/interaction.service.d.ts +40 -0
- package/dist/interaction/interaction.service.js +102 -0
- package/dist/interaction/interaction.service.js.map +1 -0
- package/dist/maintenance/cleanup.service.d.ts +22 -0
- package/dist/maintenance/cleanup.service.js +77 -0
- package/dist/maintenance/cleanup.service.js.map +1 -0
- package/dist/oauth2.module.d.ts +37 -0
- package/dist/oauth2.module.js +214 -0
- package/dist/oauth2.module.js.map +1 -0
- package/dist/otp/otp-guard.d.ts +7 -0
- package/dist/otp/otp-guard.js +27 -0
- package/dist/otp/otp-guard.js.map +1 -0
- package/dist/otp/otp.service.d.ts +57 -0
- package/dist/otp/otp.service.js +202 -0
- package/dist/otp/otp.service.js.map +1 -0
- package/dist/otp/otp.types.d.ts +36 -0
- package/dist/otp/otp.types.js +34 -0
- package/dist/otp/otp.types.js.map +1 -0
- package/dist/otp/storefront-boot-check.d.ts +13 -0
- package/dist/otp/storefront-boot-check.js +53 -0
- package/dist/otp/storefront-boot-check.js.map +1 -0
- package/dist/permissions.d.ts +12 -0
- package/dist/permissions.js +24 -0
- package/dist/permissions.js.map +1 -0
- package/dist/provider/kysely.adapter.d.ts +27 -0
- package/dist/provider/kysely.adapter.js +79 -0
- package/dist/provider/kysely.adapter.js.map +1 -0
- package/dist/provider/provider.factory.d.ts +101 -0
- package/dist/provider/provider.factory.js +377 -0
- package/dist/provider/provider.factory.js.map +1 -0
- package/dist/provider/provider.service.d.ts +60 -0
- package/dist/provider/provider.service.js +200 -0
- package/dist/provider/provider.service.js.map +1 -0
- package/dist/provider/signing-keys.d.ts +19 -0
- package/dist/provider/signing-keys.js +41 -0
- package/dist/provider/signing-keys.js.map +1 -0
- package/dist/register-migrations.d.ts +1 -0
- package/dist/register-migrations.js +7 -0
- package/dist/register-migrations.js.map +1 -0
- package/dist/security/crypto.d.ts +6 -0
- package/dist/security/crypto.js +29 -0
- package/dist/security/crypto.js.map +1 -0
- package/dist/security/email.d.ts +1 -0
- package/dist/security/email.js +7 -0
- package/dist/security/email.js.map +1 -0
- package/dist/security/origin.d.ts +1 -0
- package/dist/security/origin.js +15 -0
- package/dist/security/origin.js.map +1 -0
- package/dist/security/password.d.ts +12 -0
- package/dist/security/password.js +92 -0
- package/dist/security/password.js.map +1 -0
- package/dist/security/rate-limiter.d.ts +25 -0
- package/dist/security/rate-limiter.js +52 -0
- package/dist/security/rate-limiter.js.map +1 -0
- package/dist/security/return-to.d.ts +6 -0
- package/dist/security/return-to.js +33 -0
- package/dist/security/return-to.js.map +1 -0
- package/dist/security/validate.d.ts +3 -0
- package/dist/security/validate.js +14 -0
- package/dist/security/validate.js.map +1 -0
- package/dist/settings/settings.provider.d.ts +11 -0
- package/dist/settings/settings.provider.js +20 -0
- package/dist/settings/settings.provider.js.map +1 -0
- package/dist/setup/bootstrap.service.d.ts +24 -0
- package/dist/setup/bootstrap.service.js +117 -0
- package/dist/setup/bootstrap.service.js.map +1 -0
- package/dist/setup/setup-state.d.ts +8 -0
- package/dist/setup/setup-state.js +42 -0
- package/dist/setup/setup-state.js.map +1 -0
- package/dist/setup/setup.controller.d.ts +23 -0
- package/dist/setup/setup.controller.js +96 -0
- package/dist/setup/setup.controller.js.map +1 -0
- package/dist/users/password.controller.d.ts +19 -0
- package/dist/users/password.controller.js +87 -0
- package/dist/users/password.controller.js.map +1 -0
- package/dist/users/user.service.d.ts +114 -0
- package/dist/users/user.service.js +336 -0
- package/dist/users/user.service.js.map +1 -0
- package/dist/users/users.controller.d.ts +43 -0
- package/dist/users/users.controller.js +188 -0
- package/dist/users/users.controller.js.map +1 -0
- package/package.json +75 -3
|
@@ -0,0 +1,443 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
12
|
+
return function (target, key) { decorator(target, key, paramIndex); }
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.CustomerPasswordResetController = exports.CustomerAccountController = void 0;
|
|
16
|
+
const common_1 = require("@nestjs/common");
|
|
17
|
+
const zod_1 = require("zod");
|
|
18
|
+
const audit_service_1 = require("../audit/audit.service");
|
|
19
|
+
const constants_1 = require("../constants");
|
|
20
|
+
const errors_1 = require("../errors");
|
|
21
|
+
const customer_auth_decorator_1 = require("../guard/customer-auth.decorator");
|
|
22
|
+
const public_decorator_1 = require("../guard/public.decorator");
|
|
23
|
+
const otp_service_1 = require("../otp/otp.service");
|
|
24
|
+
const cors_origins_service_1 = require("../cors/cors-origins.service");
|
|
25
|
+
const origin_1 = require("../security/origin");
|
|
26
|
+
const password_1 = require("../security/password");
|
|
27
|
+
const validate_1 = require("../security/validate");
|
|
28
|
+
const auth_hooks_1 = require("./auth-hooks");
|
|
29
|
+
const customer_sessions_revoker_1 = require("./customer-sessions.revoker");
|
|
30
|
+
const customer_service_1 = require("./customer.service");
|
|
31
|
+
const identifier_1 = require("./identifier");
|
|
32
|
+
const sign_in_settings_service_1 = require("./sign-in-settings.service");
|
|
33
|
+
const identifier = zod_1.z.string().min(1).max(320);
|
|
34
|
+
// Never trimmed: leading/trailing spaces are part of a password. Length rules are PasswordService's (422 weak_password).
|
|
35
|
+
const password = zod_1.z.string().max(1024);
|
|
36
|
+
const code = zod_1.z.string().min(1).max(16);
|
|
37
|
+
const passwordSchema = zod_1.z.object({ currentPassword: password.optional(), newPassword: password }).strict();
|
|
38
|
+
const resetSchema = zod_1.z.object({ identifier }).strict();
|
|
39
|
+
const resetConfirmSchema = zod_1.z.object({ identifier, code, newPassword: password }).strict();
|
|
40
|
+
const nameSchema = zod_1.z.object({ name: zod_1.z.string().trim().max(200).nullable() }).strict();
|
|
41
|
+
const addIdentifierSchema = zod_1.z.object({ identifier }).strict();
|
|
42
|
+
const verifyIdentifierSchema = zod_1.z.object({ identifier, code }).strict();
|
|
43
|
+
const UUID = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
44
|
+
const ctxOf = (req) => {
|
|
45
|
+
const ua = req.headers['user-agent'];
|
|
46
|
+
return { ip: req.ip, userAgent: typeof ua === 'string' ? ua : undefined };
|
|
47
|
+
};
|
|
48
|
+
function identify(raw, region) {
|
|
49
|
+
const id = (0, identifier_1.normalizeIdentifier)(raw, region);
|
|
50
|
+
if (!id)
|
|
51
|
+
throw new errors_1.AuthError('invalid_identifier', 422, 'Enter a valid email address or phone number');
|
|
52
|
+
return id;
|
|
53
|
+
}
|
|
54
|
+
/** PasswordService's rules (admin `password.minLength`, max length) and "not equal to any of the identifiers". */
|
|
55
|
+
function validatePassword(passwords, pw, identifiers) {
|
|
56
|
+
for (const v of identifiers.length ? identifiers : [''])
|
|
57
|
+
passwords.validate(pw, v);
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Verifies with uniform errors (every refusal is `401 invalid_code`, so an identifier that never got a code — unknown,
|
|
61
|
+
* disabled, owned by another customer — looks like an expired or used-up one). The real reason is audited as
|
|
62
|
+
* `customer.otp_failed`; wrong codes are already audited by OtpService itself.
|
|
63
|
+
*/
|
|
64
|
+
async function verifyUniform(otp, audit, i, ctx, customerId) {
|
|
65
|
+
try {
|
|
66
|
+
await otp.verify(i, { uniformErrors: true });
|
|
67
|
+
}
|
|
68
|
+
catch (e) {
|
|
69
|
+
if (e instanceof otp_service_1.OtpRejectedError && e.reason !== 'wrong_code') {
|
|
70
|
+
await audit.record({
|
|
71
|
+
type: 'customer.otp_failed',
|
|
72
|
+
...ctx,
|
|
73
|
+
meta: { purpose: i.purpose, kind: i.kind, reason: e.reason, ...(customerId ? { customerId } : {}) },
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
throw e;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Spec "Customer API": the signed-in customer's own account (`@CustomerAuth()`: the site's cookie, or a mobile/web
|
|
81
|
+
* bearer token). Cookie writes are Origin-checked by the guard. Every answer is `no-store`.
|
|
82
|
+
*/
|
|
83
|
+
let CustomerAccountController = class CustomerAccountController {
|
|
84
|
+
cfg;
|
|
85
|
+
db;
|
|
86
|
+
customers;
|
|
87
|
+
settings;
|
|
88
|
+
otp;
|
|
89
|
+
passwords;
|
|
90
|
+
hooks;
|
|
91
|
+
audit;
|
|
92
|
+
limiter;
|
|
93
|
+
sessions;
|
|
94
|
+
revoker;
|
|
95
|
+
constructor(cfg, db, customers, settings, otp, passwords, hooks, audit, limiter, sessions, revoker) {
|
|
96
|
+
this.cfg = cfg;
|
|
97
|
+
this.db = db;
|
|
98
|
+
this.customers = customers;
|
|
99
|
+
this.settings = settings;
|
|
100
|
+
this.otp = otp;
|
|
101
|
+
this.passwords = passwords;
|
|
102
|
+
this.hooks = hooks;
|
|
103
|
+
this.audit = audit;
|
|
104
|
+
this.limiter = limiter;
|
|
105
|
+
this.sessions = sessions;
|
|
106
|
+
this.revoker = revoker;
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* `{ currentPassword?, newPassword }` → 204. With a password already set, `currentPassword` must match (else
|
|
110
|
+
* `401 invalid_credentials`, also when missing); without one it is ignored (`reason: 'set'`). A change ends the
|
|
111
|
+
* customer's other sessions and grants and keeps the calling credential.
|
|
112
|
+
*/
|
|
113
|
+
async password(req, me, res, body) {
|
|
114
|
+
res.setHeader('Cache-Control', 'no-store');
|
|
115
|
+
const { limit, windowSec } = this.cfg.rateLimit.loginPerEmail;
|
|
116
|
+
const hit = this.limiter.hit(`customer-pwchange:${me.id}`, limit, windowSec);
|
|
117
|
+
if (!hit.ok)
|
|
118
|
+
throw new errors_1.AuthError('rate_limited', 429, 'Too many attempts', { retryAfterSec: hit.retryAfterSec });
|
|
119
|
+
const { currentPassword, newPassword } = (0, validate_1.parseBody)(passwordSchema, body);
|
|
120
|
+
const current = await this.customers.passwordHashOf(me.id);
|
|
121
|
+
if (current === undefined)
|
|
122
|
+
throw new errors_1.AuthError('unauthenticated', 401, 'Not authenticated');
|
|
123
|
+
const reason = current === null ? 'set' : 'change';
|
|
124
|
+
if (current !== null) {
|
|
125
|
+
const ok = currentPassword === undefined ? false : await this.passwords.verify(current, currentPassword);
|
|
126
|
+
if (!ok)
|
|
127
|
+
throw new errors_1.AuthError('invalid_credentials', 401, 'Invalid credentials');
|
|
128
|
+
}
|
|
129
|
+
validatePassword(this.passwords, newPassword, me.identifiers.map((i) => i.value));
|
|
130
|
+
await this.customers.setPassword(me.id, await this.passwords.hash(newPassword));
|
|
131
|
+
if (reason === 'change') {
|
|
132
|
+
// The old password may be known to someone else: end every other sign-in, keep this one.
|
|
133
|
+
const auth = req.customerAuth;
|
|
134
|
+
if (auth.via === 'cookie') {
|
|
135
|
+
await this.revoker.revokeAll(me.id, { exceptSessionId: auth.idHash, exceptGrantId: await this.sessions.grantIdOf(auth.idHash) });
|
|
136
|
+
}
|
|
137
|
+
else {
|
|
138
|
+
await this.revoker.revokeAll(me.id, { exceptGrantId: auth.grantId });
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
const ctx = ctxOf(req);
|
|
142
|
+
await this.audit.record({
|
|
143
|
+
type: reason === 'set' ? 'customer.password_set' : 'customer.password_changed',
|
|
144
|
+
...ctx,
|
|
145
|
+
meta: { customerId: me.id, clientId: me.clientId },
|
|
146
|
+
});
|
|
147
|
+
const customer = await this.customers.findById(me.id);
|
|
148
|
+
if (customer)
|
|
149
|
+
await this.hooks.after('afterPasswordChange', customer, { db: this.db, ...ctx, reason });
|
|
150
|
+
}
|
|
151
|
+
/** `{ name }` (trimmed; empty or null clears it) → the customer. */
|
|
152
|
+
async update(me, res, body) {
|
|
153
|
+
res.setHeader('Cache-Control', 'no-store');
|
|
154
|
+
const { name } = (0, validate_1.parseBody)(nameSchema, body);
|
|
155
|
+
await this.customers.setName(me.id, name ? name : null);
|
|
156
|
+
return this.load(me.id);
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* `{ identifier }` → `202 { resendAfterSec }` and a `verify` code to it. An identifier that already has an owner
|
|
160
|
+
* (another customer, or this one) gets the same answer and no code, so the answer never reveals ownership.
|
|
161
|
+
*/
|
|
162
|
+
async addIdentifier(req, me, res, body) {
|
|
163
|
+
res.setHeader('Cache-Control', 'no-store');
|
|
164
|
+
const id = identify((0, validate_1.parseBody)(addIdentifierSchema, body).identifier, this.cfg.storefront.phoneRegion);
|
|
165
|
+
await this.settings.assertKindEnabled(id.kind);
|
|
166
|
+
// One indexed lookup whatever the outcome; only `deliver` differs and OtpService answers the same either way.
|
|
167
|
+
const owner = await this.db
|
|
168
|
+
.selectFrom('auth_customer_identifiers')
|
|
169
|
+
.select('customer_id')
|
|
170
|
+
.where('kind', '=', id.kind)
|
|
171
|
+
.where('value', '=', id.value)
|
|
172
|
+
.executeTakeFirst();
|
|
173
|
+
const deliver = !owner;
|
|
174
|
+
const out = await this.otp.request({ ...id, purpose: 'verify', ip: req.ip, deliver });
|
|
175
|
+
await this.audit.record({
|
|
176
|
+
type: 'customer.otp_sent',
|
|
177
|
+
...ctxOf(req),
|
|
178
|
+
meta: { kind: id.kind, purpose: 'verify', customerId: me.id, ...(deliver ? {} : { suppressed: true }) },
|
|
179
|
+
});
|
|
180
|
+
return out;
|
|
181
|
+
}
|
|
182
|
+
/** `{ identifier, code }` → the customer with the identifier added, verified. Wrong / no code → 401 invalid_code. */
|
|
183
|
+
async verifyIdentifier(req, me, res, body) {
|
|
184
|
+
res.setHeader('Cache-Control', 'no-store');
|
|
185
|
+
const parsed = (0, validate_1.parseBody)(verifyIdentifierSchema, body);
|
|
186
|
+
const id = identify(parsed.identifier, this.cfg.storefront.phoneRegion);
|
|
187
|
+
await this.settings.assertKindEnabled(id.kind);
|
|
188
|
+
const { limit, windowSec } = this.cfg.rateLimit.loginPerEmail;
|
|
189
|
+
const hit = this.limiter.hit(`customer-idverify:${me.id}`, limit, windowSec);
|
|
190
|
+
if (!hit.ok)
|
|
191
|
+
throw new errors_1.AuthError('rate_limited', 429, 'Too many attempts', { retryAfterSec: hit.retryAfterSec });
|
|
192
|
+
await verifyUniform(this.otp, this.audit, { ...id, purpose: 'verify', code: parsed.code }, ctxOf(req), me.id);
|
|
193
|
+
// Taken between request and verify (or a code issued to another customer's request): 409 identifier_taken
|
|
194
|
+
// only reaches someone who received the code, i.e. who controls the identifier.
|
|
195
|
+
await this.customers.addIdentifier(me.id, id.kind, id.value, true);
|
|
196
|
+
return this.load(me.id);
|
|
197
|
+
}
|
|
198
|
+
/** Removes one of the customer's identifiers; the last verified one → 409 last_identifier; not theirs → 404. */
|
|
199
|
+
async removeIdentifier(me, res, identifierId) {
|
|
200
|
+
res.setHeader('Cache-Control', 'no-store');
|
|
201
|
+
if (!UUID.test(identifierId))
|
|
202
|
+
throw new errors_1.AuthError('not_found', 404, 'Identifier not found');
|
|
203
|
+
return this.customers.removeIdentifier(me.id, identifierId);
|
|
204
|
+
}
|
|
205
|
+
async load(id) {
|
|
206
|
+
const c = await this.customers.findById(id);
|
|
207
|
+
if (!c)
|
|
208
|
+
throw new errors_1.AuthError('unauthenticated', 401, 'Not authenticated');
|
|
209
|
+
return c;
|
|
210
|
+
}
|
|
211
|
+
};
|
|
212
|
+
exports.CustomerAccountController = CustomerAccountController;
|
|
213
|
+
__decorate([
|
|
214
|
+
(0, common_1.Post)('password'),
|
|
215
|
+
(0, common_1.HttpCode)(204),
|
|
216
|
+
__param(0, (0, common_1.Req)()),
|
|
217
|
+
__param(1, (0, customer_auth_decorator_1.CurrentCustomer)()),
|
|
218
|
+
__param(2, (0, common_1.Res)({ passthrough: true })),
|
|
219
|
+
__param(3, (0, common_1.Body)()),
|
|
220
|
+
__metadata("design:type", Function),
|
|
221
|
+
__metadata("design:paramtypes", [Object, Object, Object, Object]),
|
|
222
|
+
__metadata("design:returntype", Promise)
|
|
223
|
+
], CustomerAccountController.prototype, "password", null);
|
|
224
|
+
__decorate([
|
|
225
|
+
(0, common_1.Patch)(),
|
|
226
|
+
__param(0, (0, customer_auth_decorator_1.CurrentCustomer)()),
|
|
227
|
+
__param(1, (0, common_1.Res)({ passthrough: true })),
|
|
228
|
+
__param(2, (0, common_1.Body)()),
|
|
229
|
+
__metadata("design:type", Function),
|
|
230
|
+
__metadata("design:paramtypes", [Object, Object, Object]),
|
|
231
|
+
__metadata("design:returntype", Promise)
|
|
232
|
+
], CustomerAccountController.prototype, "update", null);
|
|
233
|
+
__decorate([
|
|
234
|
+
(0, common_1.Post)('identifiers'),
|
|
235
|
+
(0, common_1.HttpCode)(202),
|
|
236
|
+
__param(0, (0, common_1.Req)()),
|
|
237
|
+
__param(1, (0, customer_auth_decorator_1.CurrentCustomer)()),
|
|
238
|
+
__param(2, (0, common_1.Res)({ passthrough: true })),
|
|
239
|
+
__param(3, (0, common_1.Body)()),
|
|
240
|
+
__metadata("design:type", Function),
|
|
241
|
+
__metadata("design:paramtypes", [Object, Object, Object, Object]),
|
|
242
|
+
__metadata("design:returntype", Promise)
|
|
243
|
+
], CustomerAccountController.prototype, "addIdentifier", null);
|
|
244
|
+
__decorate([
|
|
245
|
+
(0, common_1.Post)('identifiers/verify'),
|
|
246
|
+
(0, common_1.HttpCode)(200),
|
|
247
|
+
__param(0, (0, common_1.Req)()),
|
|
248
|
+
__param(1, (0, customer_auth_decorator_1.CurrentCustomer)()),
|
|
249
|
+
__param(2, (0, common_1.Res)({ passthrough: true })),
|
|
250
|
+
__param(3, (0, common_1.Body)()),
|
|
251
|
+
__metadata("design:type", Function),
|
|
252
|
+
__metadata("design:paramtypes", [Object, Object, Object, Object]),
|
|
253
|
+
__metadata("design:returntype", Promise)
|
|
254
|
+
], CustomerAccountController.prototype, "verifyIdentifier", null);
|
|
255
|
+
__decorate([
|
|
256
|
+
(0, common_1.Delete)('identifiers/:id'),
|
|
257
|
+
__param(0, (0, customer_auth_decorator_1.CurrentCustomer)()),
|
|
258
|
+
__param(1, (0, common_1.Res)({ passthrough: true })),
|
|
259
|
+
__param(2, (0, common_1.Param)('id')),
|
|
260
|
+
__metadata("design:type", Function),
|
|
261
|
+
__metadata("design:paramtypes", [Object, Object, String]),
|
|
262
|
+
__metadata("design:returntype", Promise)
|
|
263
|
+
], CustomerAccountController.prototype, "removeIdentifier", null);
|
|
264
|
+
exports.CustomerAccountController = CustomerAccountController = __decorate([
|
|
265
|
+
(0, customer_auth_decorator_1.CustomerAuth)(),
|
|
266
|
+
(0, common_1.Controller)('api/customer/account'),
|
|
267
|
+
__param(0, (0, common_1.Inject)(constants_1.OAUTH2_CONFIG)),
|
|
268
|
+
__param(1, (0, common_1.Inject)(constants_1.OAUTH2_DB)),
|
|
269
|
+
__param(2, (0, common_1.Inject)(customer_service_1.CustomerService)),
|
|
270
|
+
__param(3, (0, common_1.Inject)(sign_in_settings_service_1.SignInSettingsService)),
|
|
271
|
+
__param(4, (0, common_1.Inject)(otp_service_1.OtpService)),
|
|
272
|
+
__param(5, (0, common_1.Inject)(password_1.PasswordService)),
|
|
273
|
+
__param(6, (0, common_1.Inject)(auth_hooks_1.AuthHookRunner)),
|
|
274
|
+
__param(7, (0, common_1.Inject)(audit_service_1.AuditService)),
|
|
275
|
+
__param(8, (0, common_1.Inject)(constants_1.RATE_LIMITER)),
|
|
276
|
+
__param(9, (0, common_1.Inject)(constants_1.CUSTOMER_SESSIONS)),
|
|
277
|
+
__param(10, (0, common_1.Inject)(customer_sessions_revoker_1.CustomerSessionsRevoker)),
|
|
278
|
+
__metadata("design:paramtypes", [Object, Function, customer_service_1.CustomerService,
|
|
279
|
+
sign_in_settings_service_1.SignInSettingsService,
|
|
280
|
+
otp_service_1.OtpService,
|
|
281
|
+
password_1.PasswordService,
|
|
282
|
+
auth_hooks_1.AuthHookRunner,
|
|
283
|
+
audit_service_1.AuditService, Object, Function, customer_sessions_revoker_1.CustomerSessionsRevoker])
|
|
284
|
+
], CustomerAccountController);
|
|
285
|
+
/**
|
|
286
|
+
* Public password reset (spec "Customer API"): `POST password-reset` sends a `reset` code; `POST
|
|
287
|
+
* password-reset/confirm` sets the new password and ends every session and grant of the customer.
|
|
288
|
+
*
|
|
289
|
+
* Enumeration safety: for an enabled kind the request answers `202` after the same lookup for every identifier;
|
|
290
|
+
* unknown, unverified, password-less and disabled accounts get no code (nothing stored or sent), so confirm then
|
|
291
|
+
* fails `401 invalid_code` exactly like a wrong code. A browser call must come from the site's own Origin or an
|
|
292
|
+
* admin-managed origin allowed with customer scope; a call without an Origin header (a mobile app) is accepted — no
|
|
293
|
+
* ambient credential is used here.
|
|
294
|
+
*/
|
|
295
|
+
let CustomerPasswordResetController = class CustomerPasswordResetController {
|
|
296
|
+
cfg;
|
|
297
|
+
db;
|
|
298
|
+
customers;
|
|
299
|
+
settings;
|
|
300
|
+
otp;
|
|
301
|
+
passwords;
|
|
302
|
+
hooks;
|
|
303
|
+
audit;
|
|
304
|
+
limiter;
|
|
305
|
+
revoker;
|
|
306
|
+
cors;
|
|
307
|
+
constructor(cfg, db, customers, settings, otp, passwords, hooks, audit, limiter, revoker, cors) {
|
|
308
|
+
this.cfg = cfg;
|
|
309
|
+
this.db = db;
|
|
310
|
+
this.customers = customers;
|
|
311
|
+
this.settings = settings;
|
|
312
|
+
this.otp = otp;
|
|
313
|
+
this.passwords = passwords;
|
|
314
|
+
this.hooks = hooks;
|
|
315
|
+
this.audit = audit;
|
|
316
|
+
this.limiter = limiter;
|
|
317
|
+
this.revoker = revoker;
|
|
318
|
+
this.cors = cors;
|
|
319
|
+
}
|
|
320
|
+
async request(req, res, body) {
|
|
321
|
+
await this.begin(req, res);
|
|
322
|
+
const id = identify((0, validate_1.parseBody)(resetSchema, body).identifier, this.cfg.storefront.phoneRegion);
|
|
323
|
+
// Reveals configuration (kind / password off), never accounts.
|
|
324
|
+
await this.settings.assertAllowed(id.kind, 'password');
|
|
325
|
+
const account = await this.lookup(id);
|
|
326
|
+
const deliver = !!account && account.status === 'active' && account.verified && account.hasPassword;
|
|
327
|
+
const out = await this.otp.request({ ...id, purpose: 'reset', ip: req.ip, deliver });
|
|
328
|
+
await this.audit.record({
|
|
329
|
+
type: 'customer.otp_sent',
|
|
330
|
+
...ctxOf(req),
|
|
331
|
+
meta: { kind: id.kind, purpose: 'reset', ...(account ? { customerId: account.id } : {}), ...(deliver ? {} : { suppressed: true }) },
|
|
332
|
+
});
|
|
333
|
+
return out;
|
|
334
|
+
}
|
|
335
|
+
async confirm(req, res, body) {
|
|
336
|
+
await this.begin(req, res);
|
|
337
|
+
const parsed = (0, validate_1.parseBody)(resetConfirmSchema, body);
|
|
338
|
+
const id = identify(parsed.identifier, this.cfg.storefront.phoneRegion);
|
|
339
|
+
await this.settings.assertAllowed(id.kind, 'password');
|
|
340
|
+
this.limit(req, id);
|
|
341
|
+
// Before the code is spent: a weak password must not burn it. Depends only on the request, not on the account.
|
|
342
|
+
validatePassword(this.passwords, parsed.newPassword, [id.value]);
|
|
343
|
+
const ctx = ctxOf(req);
|
|
344
|
+
await verifyUniform(this.otp, this.audit, { ...id, purpose: 'reset', code: parsed.code }, ctx);
|
|
345
|
+
// A code only exists for an active, verified account with a password; re-check (it may have changed since).
|
|
346
|
+
const account = await this.lookup(id);
|
|
347
|
+
if (!account || account.status !== 'active' || !account.verified)
|
|
348
|
+
throw new errors_1.AuthError('invalid_code', 401);
|
|
349
|
+
// Only now (the code proved possession): checking the customer's other identifiers earlier would reveal them.
|
|
350
|
+
const customerIdentifiers = (await this.customers.findById(account.id))?.identifiers.map((i) => i.value) ?? [];
|
|
351
|
+
validatePassword(this.passwords, parsed.newPassword, customerIdentifiers);
|
|
352
|
+
await this.customers.setPassword(account.id, await this.passwords.hash(parsed.newPassword));
|
|
353
|
+
await this.revoker.revokeAll(account.id);
|
|
354
|
+
await this.audit.record({ type: 'customer.password_reset', ...ctx, meta: { customerId: account.id } });
|
|
355
|
+
const customer = await this.customers.findById(account.id);
|
|
356
|
+
if (customer)
|
|
357
|
+
await this.hooks.after('afterPasswordChange', customer, { db: this.db, ...ctx, reason: 'reset' });
|
|
358
|
+
}
|
|
359
|
+
/**
|
|
360
|
+
* 404 while the storefront is off; no-store; a browser (Origin header present) must be the site itself or an origin
|
|
361
|
+
* allowed with customer scope (spec goal 14).
|
|
362
|
+
*/
|
|
363
|
+
async begin(req, res) {
|
|
364
|
+
if (!this.cfg.storefront.enabled)
|
|
365
|
+
throw new errors_1.AuthError('not_found', 404, 'Not found');
|
|
366
|
+
res.setHeader('Cache-Control', 'no-store');
|
|
367
|
+
const raw = req.headers.origin;
|
|
368
|
+
if (raw === undefined)
|
|
369
|
+
return;
|
|
370
|
+
const origin = Array.isArray(raw) ? raw[0] : raw;
|
|
371
|
+
if (origin && (await this.cors.allows(origin, 'customer')))
|
|
372
|
+
return;
|
|
373
|
+
(0, origin_1.assertSameOrigin)(origin, this.cfg.publicUrl);
|
|
374
|
+
}
|
|
375
|
+
/** IP first; the identifier key is only created for an IP that is not limited (as customer sign-in). */
|
|
376
|
+
limit(req, id) {
|
|
377
|
+
const { loginPerEmail, loginPerIp } = this.cfg.rateLimit;
|
|
378
|
+
const byIp = this.limiter.hit(`customer-reset:ip:${req.ip ?? 'unknown'}`, loginPerIp.limit, loginPerIp.windowSec);
|
|
379
|
+
const byId = byIp.ok
|
|
380
|
+
? this.limiter.hit(`customer-reset:id:${id.kind}:${id.value}`, loginPerEmail.limit, loginPerEmail.windowSec)
|
|
381
|
+
: { ok: true, retryAfterSec: 0 };
|
|
382
|
+
if (byIp.ok && byId.ok)
|
|
383
|
+
return;
|
|
384
|
+
throw new errors_1.AuthError('rate_limited', 429, 'Too many attempts', { retryAfterSec: Math.max(byIp.retryAfterSec, byId.retryAfterSec) });
|
|
385
|
+
}
|
|
386
|
+
/** One indexed query whether or not the identifier exists (same cost for known and unknown identifiers). */
|
|
387
|
+
async lookup(id) {
|
|
388
|
+
const row = await this.db
|
|
389
|
+
.selectFrom('auth_customer_identifiers as i')
|
|
390
|
+
.innerJoin('auth_customers as c', 'c.id', 'i.customer_id')
|
|
391
|
+
.select(['c.id', 'c.status', 'c.password_hash', 'i.verified_at'])
|
|
392
|
+
.where('i.kind', '=', id.kind)
|
|
393
|
+
.where('i.value', '=', id.value)
|
|
394
|
+
.executeTakeFirst();
|
|
395
|
+
if (!row)
|
|
396
|
+
return undefined;
|
|
397
|
+
return { id: row.id, status: row.status, hasPassword: row.password_hash !== null, verified: row.verified_at !== null };
|
|
398
|
+
}
|
|
399
|
+
};
|
|
400
|
+
exports.CustomerPasswordResetController = CustomerPasswordResetController;
|
|
401
|
+
__decorate([
|
|
402
|
+
(0, common_1.Post)(),
|
|
403
|
+
(0, common_1.HttpCode)(202),
|
|
404
|
+
__param(0, (0, common_1.Req)()),
|
|
405
|
+
__param(1, (0, common_1.Res)({ passthrough: true })),
|
|
406
|
+
__param(2, (0, common_1.Body)()),
|
|
407
|
+
__metadata("design:type", Function),
|
|
408
|
+
__metadata("design:paramtypes", [Object, Object, Object]),
|
|
409
|
+
__metadata("design:returntype", Promise)
|
|
410
|
+
], CustomerPasswordResetController.prototype, "request", null);
|
|
411
|
+
__decorate([
|
|
412
|
+
(0, common_1.Post)('confirm'),
|
|
413
|
+
(0, common_1.HttpCode)(204),
|
|
414
|
+
__param(0, (0, common_1.Req)()),
|
|
415
|
+
__param(1, (0, common_1.Res)({ passthrough: true })),
|
|
416
|
+
__param(2, (0, common_1.Body)()),
|
|
417
|
+
__metadata("design:type", Function),
|
|
418
|
+
__metadata("design:paramtypes", [Object, Object, Object]),
|
|
419
|
+
__metadata("design:returntype", Promise)
|
|
420
|
+
], CustomerPasswordResetController.prototype, "confirm", null);
|
|
421
|
+
exports.CustomerPasswordResetController = CustomerPasswordResetController = __decorate([
|
|
422
|
+
(0, public_decorator_1.Public)(),
|
|
423
|
+
(0, common_1.Controller)('api/customer/auth/password-reset'),
|
|
424
|
+
__param(0, (0, common_1.Inject)(constants_1.OAUTH2_CONFIG)),
|
|
425
|
+
__param(1, (0, common_1.Inject)(constants_1.OAUTH2_DB)),
|
|
426
|
+
__param(2, (0, common_1.Inject)(customer_service_1.CustomerService)),
|
|
427
|
+
__param(3, (0, common_1.Inject)(sign_in_settings_service_1.SignInSettingsService)),
|
|
428
|
+
__param(4, (0, common_1.Inject)(otp_service_1.OtpService)),
|
|
429
|
+
__param(5, (0, common_1.Inject)(password_1.PasswordService)),
|
|
430
|
+
__param(6, (0, common_1.Inject)(auth_hooks_1.AuthHookRunner)),
|
|
431
|
+
__param(7, (0, common_1.Inject)(audit_service_1.AuditService)),
|
|
432
|
+
__param(8, (0, common_1.Inject)(constants_1.RATE_LIMITER)),
|
|
433
|
+
__param(9, (0, common_1.Inject)(customer_sessions_revoker_1.CustomerSessionsRevoker)),
|
|
434
|
+
__param(10, (0, common_1.Inject)(cors_origins_service_1.CorsOriginsService)),
|
|
435
|
+
__metadata("design:paramtypes", [Object, Function, customer_service_1.CustomerService,
|
|
436
|
+
sign_in_settings_service_1.SignInSettingsService,
|
|
437
|
+
otp_service_1.OtpService,
|
|
438
|
+
password_1.PasswordService,
|
|
439
|
+
auth_hooks_1.AuthHookRunner,
|
|
440
|
+
audit_service_1.AuditService, Object, customer_sessions_revoker_1.CustomerSessionsRevoker,
|
|
441
|
+
cors_origins_service_1.CorsOriginsService])
|
|
442
|
+
], CustomerPasswordResetController);
|
|
443
|
+
//# sourceMappingURL=account.controller.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"account.controller.js","sourceRoot":"","sources":["../../src/customers/account.controller.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,2CAA0G;AAG1G,6BAAwB;AACxB,0DAAsD;AAGtD,4CAAyF;AAEzF,sCAAsC;AACtC,8EAAuG;AAEvG,gEAAmD;AACnD,oDAAkE;AAElE,uEAAkE;AAClE,+CAAsD;AACtD,mDAAuD;AAEvD,mDAAiD;AACjD,6CAA8C;AAC9C,2EAAsE;AACtE,yDAAoE;AACpE,6CAAwE;AACxE,yEAAmE;AAEnE,MAAM,UAAU,GAAG,OAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;AAC9C,yHAAyH;AACzH,MAAM,QAAQ,GAAG,OAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;AACtC,MAAM,IAAI,GAAG,OAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;AAEvC,MAAM,cAAc,GAAG,OAAC,CAAC,MAAM,CAAC,EAAE,eAAe,EAAE,QAAQ,CAAC,QAAQ,EAAE,EAAE,WAAW,EAAE,QAAQ,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC;AAC1G,MAAM,WAAW,GAAG,OAAC,CAAC,MAAM,CAAC,EAAE,UAAU,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC;AACtD,MAAM,kBAAkB,GAAG,OAAC,CAAC,MAAM,CAAC,EAAE,UAAU,EAAE,IAA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
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import type { Kysely } from 'kysely';
|
|
2
|
+
import type { Customer } from './customer.service';
|
|
3
|
+
import type { IdentifierKind } from './identifier';
|
|
4
|
+
export interface AuthHookContext {
|
|
5
|
+
db: Kysely<any>;
|
|
6
|
+
ip?: string;
|
|
7
|
+
userAgent?: string;
|
|
8
|
+
}
|
|
9
|
+
export interface SignUpInput {
|
|
10
|
+
identifier: {
|
|
11
|
+
kind: IdentifierKind;
|
|
12
|
+
value: string;
|
|
13
|
+
};
|
|
14
|
+
name?: string;
|
|
15
|
+
}
|
|
16
|
+
export interface AuthHooks {
|
|
17
|
+
/** May return a (partial) replacement input; throw `AuthHookError` to reject the sign-up. */
|
|
18
|
+
beforeSignUp?(input: SignUpInput, ctx: AuthHookContext): unknown;
|
|
19
|
+
afterSignUp?(customer: Customer, ctx: AuthHookContext): unknown;
|
|
20
|
+
afterSignIn?(customer: Customer, ctx: AuthHookContext & {
|
|
21
|
+
method: 'otp' | 'password';
|
|
22
|
+
clientId: string;
|
|
23
|
+
}): unknown;
|
|
24
|
+
afterSignOut?(customer: Customer, ctx: AuthHookContext & {
|
|
25
|
+
clientId: string;
|
|
26
|
+
}): unknown;
|
|
27
|
+
afterPasswordChange?(customer: Customer, ctx: AuthHookContext & {
|
|
28
|
+
reason: 'set' | 'change' | 'reset';
|
|
29
|
+
}): unknown;
|
|
30
|
+
}
|
|
31
|
+
export declare const defineAuthHooks: (h: AuthHooks) => AuthHooks;
|
|
32
|
+
/** Thrown from `beforeSignUp` to reject; surfaces as `AuthError(code, 422, message)`. */
|
|
33
|
+
export declare class AuthHookError extends Error {
|
|
34
|
+
readonly code: string;
|
|
35
|
+
constructor(code: string, message: string);
|
|
36
|
+
}
|
|
37
|
+
type AfterName = Exclude<keyof AuthHooks, 'beforeSignUp'>;
|
|
38
|
+
export declare class AuthHookRunner {
|
|
39
|
+
private readonly hooks;
|
|
40
|
+
private readonly logger;
|
|
41
|
+
constructor(hooks: AuthHooks[]);
|
|
42
|
+
/** Runs each `beforeSignUp` in order; a returned object is merged into the input seen by the next hook. */
|
|
43
|
+
beforeSignUp(input: SignUpInput, ctx: AuthHookContext): Promise<SignUpInput>;
|
|
44
|
+
/** Runs every hook's `name` in order; failures are logged, never thrown. */
|
|
45
|
+
after<N extends AfterName>(name: N, ...args: Parameters<NonNullable<AuthHooks[N]>>): Promise<void>;
|
|
46
|
+
}
|
|
47
|
+
export {};
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
12
|
+
return function (target, key) { decorator(target, key, paramIndex); }
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.AuthHookRunner = exports.AuthHookError = exports.defineAuthHooks = void 0;
|
|
16
|
+
const common_1 = require("@nestjs/common");
|
|
17
|
+
const constants_1 = require("../constants");
|
|
18
|
+
const errors_1 = require("../errors");
|
|
19
|
+
const defineAuthHooks = (h) => h;
|
|
20
|
+
exports.defineAuthHooks = defineAuthHooks;
|
|
21
|
+
/** Thrown from `beforeSignUp` to reject; surfaces as `AuthError(code, 422, message)`. */
|
|
22
|
+
class AuthHookError extends Error {
|
|
23
|
+
code;
|
|
24
|
+
constructor(code, message) {
|
|
25
|
+
super(message);
|
|
26
|
+
this.code = code;
|
|
27
|
+
this.name = 'AuthHookError';
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
exports.AuthHookError = AuthHookError;
|
|
31
|
+
let AuthHookRunner = class AuthHookRunner {
|
|
32
|
+
hooks;
|
|
33
|
+
logger = new common_1.Logger('AuthHooks');
|
|
34
|
+
constructor(hooks) {
|
|
35
|
+
this.hooks = hooks;
|
|
36
|
+
}
|
|
37
|
+
/** Runs each `beforeSignUp` in order; a returned object is merged into the input seen by the next hook. */
|
|
38
|
+
async beforeSignUp(input, ctx) {
|
|
39
|
+
let cur = input;
|
|
40
|
+
for (const h of this.hooks) {
|
|
41
|
+
if (!h.beforeSignUp)
|
|
42
|
+
continue;
|
|
43
|
+
try {
|
|
44
|
+
const out = await h.beforeSignUp(cur, ctx);
|
|
45
|
+
if (out && typeof out === 'object') {
|
|
46
|
+
const o = out;
|
|
47
|
+
cur = { ...cur, ...o, identifier: o.identifier ? { ...cur.identifier, ...o.identifier } : cur.identifier };
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
catch (e) {
|
|
51
|
+
if (e instanceof AuthHookError)
|
|
52
|
+
throw new errors_1.AuthError(e.code, 422, e.message);
|
|
53
|
+
throw e;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
return cur;
|
|
57
|
+
}
|
|
58
|
+
/** Runs every hook's `name` in order; failures are logged, never thrown. */
|
|
59
|
+
async after(name, ...args) {
|
|
60
|
+
for (const h of this.hooks) {
|
|
61
|
+
const fn = h[name];
|
|
62
|
+
if (!fn)
|
|
63
|
+
continue;
|
|
64
|
+
try {
|
|
65
|
+
await fn.apply(h, args);
|
|
66
|
+
}
|
|
67
|
+
catch (e) {
|
|
68
|
+
this.logger.error(`${name} hook failed: ${e instanceof Error ? e.message : String(e)}`, e instanceof Error ? e.stack : undefined);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
exports.AuthHookRunner = AuthHookRunner;
|
|
74
|
+
exports.AuthHookRunner = AuthHookRunner = __decorate([
|
|
75
|
+
(0, common_1.Injectable)(),
|
|
76
|
+
__param(0, (0, common_1.Inject)(constants_1.AUTH_HOOKS)),
|
|
77
|
+
__metadata("design:paramtypes", [Array])
|
|
78
|
+
], AuthHookRunner);
|
|
79
|
+
//# sourceMappingURL=auth-hooks.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auth-hooks.js","sourceRoot":"","sources":["../../src/customers/auth-hooks.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,2CAA4D;AAE5D,4CAA0C;AAC1C,sCAAsC;AAwB/B,MAAM,eAAe,GAAG,CAAC,CAAY,EAAa,EAAE,CAAC,CAAC,CAAC;AAAjD,QAAA,eAAe,mBAAkC;AAE9D,yFAAyF;AACzF,MAAa,aAAc,SAAQ,KAAK;IACV;IAA5B,YAA4B,IAAY,EAAE,OAAe;QACvD,KAAK,CAAC,OAAO,CAAC,CAAC;QADW,SAAI,GAAJ,IAAI,CAAQ;QAEtC,IAAI,CAAC,IAAI,GAAG,eAAe,CAAC;IAC9B,CAAC;CACF;AALD,sCAKC;AAKM,IAAM,cAAc,GAApB,MAAM,cAAc;IAGwB;IAFhC,MAAM,GAAG,IAAI,eAAM,CAAC,WAAW,CAAC,CAAC;IAElD,YAAiD,KAAkB;QAAlB,UAAK,GAAL,KAAK,CAAa;IAAG,CAAC;IAEvE,2GAA2G;IAC3G,KAAK,CAAC,YAAY,CAAC,KAAkB,EAAE,GAAoB;QACzD,IAAI,GAAG,GAAG,KAAK,CAAC;QAChB,KAAK,MAAM,CAAC,IAAI,IAAI,CAAC,KAAK,EAAE,CAAC;YAC3B,IAAI,CAAC,CAAC,CAAC,YAAY;gBAAE,SAAS;YAC9B,IAAI,CAAC;gBACH,MAAM,GA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