@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,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.parseBody = parseBody;
|
|
4
|
+
const errors_1 = require("../errors");
|
|
5
|
+
/** Validates a request body with zod; failure -> `422 validation_failed` with a short `path: message` list. */
|
|
6
|
+
function parseBody(schema, body) {
|
|
7
|
+
const r = schema.safeParse(body);
|
|
8
|
+
if (!r.success) {
|
|
9
|
+
const msg = r.error.issues.map((i) => `${i.path.join('.') || 'body'}: ${i.message}`).join('; ');
|
|
10
|
+
throw new errors_1.AuthError('validation_failed', 422, msg);
|
|
11
|
+
}
|
|
12
|
+
return r.data;
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=validate.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validate.js","sourceRoot":"","sources":["../../src/security/validate.ts"],"names":[],"mappings":";;AAIA,8BAOC;AAVD,sCAAsC;AAEtC,+GAA+G;AAC/G,SAAgB,SAAS,CAAI,MAA4B,EAAE,IAAa;IACtE,MAAM,CAAC,GAAG,MAAM,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;IACjC,IAAI,CAAC,CAAC,CAAC,OAAO,EAAE,CAAC;QACf,MAAM,GAAG,GAAG,CAAC,CAAC,KAAK,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,MAAM,KAAK,CAAC,CAAC,OAAO,EAAE,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAChG,MAAM,IAAI,kBAAS,CAAC,mBAAmB,EAAE,GAAG,EAAE,GAAG,CAAC,CAAC;IACrD,CAAC;IACD,OAAO,CAAC,CAAC,IAAI,CAAC;AAChB,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { OAuth2Config, Ttls } from '../config/schema';
|
|
2
|
+
export interface AuthSettingsProvider {
|
|
3
|
+
getTtls(): Promise<Ttls>;
|
|
4
|
+
}
|
|
5
|
+
export declare class ConfigAuthSettingsProvider implements AuthSettingsProvider {
|
|
6
|
+
private readonly ttls;
|
|
7
|
+
constructor(config: Pick<OAuth2Config, 'ttl'>, logger?: {
|
|
8
|
+
warn(msg: string): void;
|
|
9
|
+
});
|
|
10
|
+
getTtls(): Promise<Ttls>;
|
|
11
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ConfigAuthSettingsProvider = void 0;
|
|
4
|
+
const common_1 = require("@nestjs/common");
|
|
5
|
+
class ConfigAuthSettingsProvider {
|
|
6
|
+
ttls;
|
|
7
|
+
constructor(config, logger = new common_1.Logger('OAuth2')) {
|
|
8
|
+
const ttl = { ...config.ttl };
|
|
9
|
+
if (ttl.refreshToken > ttl.sessionAbsolute) {
|
|
10
|
+
logger.warn(`auth refreshToken TTL (${ttl.refreshToken}s) exceeds sessionAbsolute (${ttl.sessionAbsolute}s); using ${ttl.sessionAbsolute}s`);
|
|
11
|
+
ttl.refreshToken = ttl.sessionAbsolute;
|
|
12
|
+
}
|
|
13
|
+
this.ttls = ttl;
|
|
14
|
+
}
|
|
15
|
+
async getTtls() {
|
|
16
|
+
return { ...this.ttls };
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
exports.ConfigAuthSettingsProvider = ConfigAuthSettingsProvider;
|
|
20
|
+
//# sourceMappingURL=settings.provider.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"settings.provider.js","sourceRoot":"","sources":["../../src/settings/settings.provider.ts"],"names":[],"mappings":";;;AAAA,2CAAwC;AAOxC,MAAa,0BAA0B;IACpB,IAAI,CAAO;IAE5B,YAAY,MAAiC,EAAE,SAAsC,IAAI,eAAM,CAAC,QAAQ,CAAC;QACvG,MAAM,GAAG,GAAG,EAAE,GAAG,MAAM,CAAC,GAAG,EAAE,CAAC;QAC9B,IAAI,GAAG,CAAC,YAAY,GAAG,GAAG,CAAC,eAAe,EAAE,CAAC;YAC3C,MAAM,CAAC,IAAI,CACT,0BAA0B,GAAG,CAAC,YAAY,+BAA+B,GAAG,CAAC,eAAe,aAAa,GAAG,CAAC,eAAe,GAAG,CAChI,CAAC;YACF,GAAG,CAAC,YAAY,GAAG,GAAG,CAAC,eAAe,CAAC;QACzC,CAAC;QACD,IAAI,CAAC,IAAI,GAAG,GAAG,CAAC;IAClB,CAAC;IAED,KAAK,CAAC,OAAO;QACX,OAAO,EAAE,GAAG,IAAI,CAAC,IAAI,EAAE,CAAC;IAC1B,CAAC;CACF;AAjBD,gEAiBC"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { AuditService } from '../audit/audit.service';
|
|
2
|
+
import type { OAuth2Config } from '../config/schema';
|
|
3
|
+
import { PasswordService } from '../security/password';
|
|
4
|
+
import { UserService } from '../users/user.service';
|
|
5
|
+
export declare class BootstrapError extends Error {
|
|
6
|
+
constructor(message: string);
|
|
7
|
+
}
|
|
8
|
+
export interface BootstrapLogger {
|
|
9
|
+
log(msg: string): void;
|
|
10
|
+
warn(msg: string): void;
|
|
11
|
+
}
|
|
12
|
+
export declare class BootstrapService {
|
|
13
|
+
private readonly cfg;
|
|
14
|
+
private readonly users;
|
|
15
|
+
private readonly passwords;
|
|
16
|
+
private readonly audit;
|
|
17
|
+
private readonly logger;
|
|
18
|
+
constructor(cfg: OAuth2Config, users: UserService, passwords: PasswordService, audit: AuditService, logger?: BootstrapLogger);
|
|
19
|
+
/** Spec §6.1 steps 4-6. Throws BootstrapError to refuse startup. */
|
|
20
|
+
run(): Promise<void>;
|
|
21
|
+
private wrap;
|
|
22
|
+
private seed;
|
|
23
|
+
private forceReset;
|
|
24
|
+
}
|
|
@@ -0,0 +1,117 @@
|
|
|
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.BootstrapService = exports.BootstrapError = void 0;
|
|
16
|
+
const common_1 = require("@nestjs/common");
|
|
17
|
+
const kysely_1 = require("kysely");
|
|
18
|
+
const audit_service_1 = require("../audit/audit.service");
|
|
19
|
+
const constants_1 = require("../constants");
|
|
20
|
+
const errors_1 = require("../errors");
|
|
21
|
+
const email_1 = require("../security/email");
|
|
22
|
+
const password_1 = require("../security/password");
|
|
23
|
+
const permissions_1 = require("../permissions");
|
|
24
|
+
const user_service_1 = require("../users/user.service");
|
|
25
|
+
class BootstrapError extends Error {
|
|
26
|
+
constructor(message) {
|
|
27
|
+
super(message);
|
|
28
|
+
this.name = 'BootstrapError';
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
exports.BootstrapError = BootstrapError;
|
|
32
|
+
let BootstrapService = class BootstrapService {
|
|
33
|
+
cfg;
|
|
34
|
+
users;
|
|
35
|
+
passwords;
|
|
36
|
+
audit;
|
|
37
|
+
logger;
|
|
38
|
+
constructor(cfg, users, passwords, audit, logger) {
|
|
39
|
+
this.cfg = cfg;
|
|
40
|
+
this.users = users;
|
|
41
|
+
this.passwords = passwords;
|
|
42
|
+
this.audit = audit;
|
|
43
|
+
this.logger = logger ?? new common_1.Logger('OAuth2');
|
|
44
|
+
}
|
|
45
|
+
/** Spec §6.1 steps 4-6. Throws BootstrapError to refuse startup. */
|
|
46
|
+
async run() {
|
|
47
|
+
const { email, password, forceReset } = this.cfg.admin;
|
|
48
|
+
if (email && password) {
|
|
49
|
+
if (forceReset)
|
|
50
|
+
await this.forceReset((0, email_1.normalizeEmail)(email), password);
|
|
51
|
+
else
|
|
52
|
+
await this.seed((0, email_1.normalizeEmail)(email), password);
|
|
53
|
+
}
|
|
54
|
+
if ((await this.users.countUsers()) === 0) {
|
|
55
|
+
this.logger.warn(`Chưa có tài khoản admin. Mở ${this.cfg.publicUrl}/admin/setup để tạo. Bất kỳ ai truy cập được URL này trước sẽ trở thành admin.`);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
wrap(e) {
|
|
59
|
+
if (e instanceof errors_1.AuthError)
|
|
60
|
+
throw new BootstrapError(`Admin bootstrap failed (${e.code}): ${e.message}`);
|
|
61
|
+
throw e;
|
|
62
|
+
}
|
|
63
|
+
async seed(email, password) {
|
|
64
|
+
let seeded = false;
|
|
65
|
+
try {
|
|
66
|
+
await this.users.withSetupLock(async (trx) => {
|
|
67
|
+
if ((await this.users.countUsers(trx)) > 0)
|
|
68
|
+
return;
|
|
69
|
+
const u = await this.users.create({ email, name: this.cfg.admin.name ?? 'Admin', password }, trx);
|
|
70
|
+
await this.audit.record({ type: 'admin_seeded_from_env', userId: u.id, meta: { email } }, trx);
|
|
71
|
+
seeded = true;
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
catch (e) {
|
|
75
|
+
this.wrap(e);
|
|
76
|
+
}
|
|
77
|
+
if (seeded)
|
|
78
|
+
this.logger.log(`Seeded admin ${email} from environment.`);
|
|
79
|
+
else
|
|
80
|
+
this.logger.log('OPENCLOUDCMS_ADMIN_EMAIL/OPENCLOUDCMS_ADMIN_PASSWORD ignored: users already exist.');
|
|
81
|
+
}
|
|
82
|
+
async forceReset(email, password) {
|
|
83
|
+
try {
|
|
84
|
+
await this.users.withSetupLock(async (trx) => {
|
|
85
|
+
const user = await this.users.findByEmail(email, trx);
|
|
86
|
+
if (!user)
|
|
87
|
+
throw new BootstrapError(`OPENCLOUDCMS_ADMIN_FORCE_RESET: user ${email} does not exist`);
|
|
88
|
+
await this.users.setPassword(user.id, password, trx);
|
|
89
|
+
await trx
|
|
90
|
+
.updateTable('auth_users')
|
|
91
|
+
.set({ status: 'active', updated_at: new Date() })
|
|
92
|
+
.where('id', '=', user.id)
|
|
93
|
+
.execute();
|
|
94
|
+
await (0, kysely_1.sql) `insert into auth_user_groups (user_id, group_id) select ${user.id}, id from auth_groups where key = ${permissions_1.SUPER_ADMIN_GROUP} on conflict do nothing`.execute(trx);
|
|
95
|
+
await this.users.revokeAll(user.id, undefined, trx);
|
|
96
|
+
await this.audit.record({ type: 'admin_force_reset', userId: user.id, meta: { email } }, trx);
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
catch (e) {
|
|
100
|
+
this.wrap(e);
|
|
101
|
+
}
|
|
102
|
+
this.logger.warn(`Admin ${email} was force-reset from environment. Remove OPENCLOUDCMS_ADMIN_FORCE_RESET (and the password variable) now, or it will reset on every boot.`);
|
|
103
|
+
}
|
|
104
|
+
};
|
|
105
|
+
exports.BootstrapService = BootstrapService;
|
|
106
|
+
exports.BootstrapService = BootstrapService = __decorate([
|
|
107
|
+
(0, common_1.Injectable)(),
|
|
108
|
+
__param(0, (0, common_1.Inject)(constants_1.OAUTH2_CONFIG)),
|
|
109
|
+
__param(1, (0, common_1.Inject)(user_service_1.UserService)),
|
|
110
|
+
__param(2, (0, common_1.Inject)(password_1.PasswordService)),
|
|
111
|
+
__param(3, (0, common_1.Inject)(audit_service_1.AuditService)),
|
|
112
|
+
__param(4, (0, common_1.Optional)()),
|
|
113
|
+
__metadata("design:paramtypes", [Object, user_service_1.UserService,
|
|
114
|
+
password_1.PasswordService,
|
|
115
|
+
audit_service_1.AuditService, Object])
|
|
116
|
+
], BootstrapService);
|
|
117
|
+
//# sourceMappingURL=bootstrap.service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bootstrap.service.js","sourceRoot":"","sources":["../../src/setup/bootstrap.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,2CAAsE;AACtE,mCAA6B;AAC7B,0DAAsD;AAEtD,4CAA6C;AAC7C,sCAAsC;AACtC,6CAAmD;AACnD,mDAAuD;AACvD,gDAAmD;AACnD,wDAAoD;AAEpD,MAAa,cAAe,SAAQ,KAAK;IACvC,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,gBAAgB,CAAC;IAC/B,CAAC;CACF;AALD,wCAKC;AAQM,IAAM,gBAAgB,GAAtB,MAAM,gBAAgB;IAIe;IACF;IACI;IACH;IANxB,MAAM,CAAkB;IAEzC,YAC0C,GAAiB,EACnB,KAAkB,EACd,SAA0B,EAC7B,KAAmB,EAC9C,MAAwB;QAJI,QAAG,GAAH,GAAG,CAAc;QACnB,UAAK,GAAL,KAAK,CAAa;QACd,cAAS,GAAT,SAAS,CAAiB;QAC7B,UAAK,GAAL,KAAK,CAAc;QAG1D,IAAI,CAAC,MAAM,GAAG,MAAM,IAAI,IAAI,eAAM,CAAC,QAAQ,CAAC,CAAC;IAC/C,CAAC;IAED,oEAAoE;IACpE,KAAK,CAAC,GAAG;QACP,MAAM,EAAE,KAAK,EAAE,QAAQ,EAAE,UAAU,EAAE,GAAG,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC;QACvD,IAAI,KAAK,IAAI,QAAQ,EAAE,CAAC;YACtB,IAAI,UAAU;gBAAE,MAAM,IAAI,CAAC,UAAU,CAAC,IAAA,sBAAc,EAAC,KAAK,CAAC,EAAE,QAAQ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EAAE,mBAAmB,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,EAAE,IAAI,EAAE,EAAE,KAAK,EAAE,EAAE,EAAE,GAAG,CAAC,CAAC;YAChG,CAAC,CAAC,CAAC;QACL,CAAC;QAAC,OAAO,CAAC,EAAE,CAAC;YACX,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QACf,CAAC;QACD,IAAI,CAAC,MAAM,CAAC,IAAI,CACd,SAAS,KAAK,2IAA2I,CAC1J,CAAC;IACJ,CAAC;CACF,CAAA;AA3EY,4CAAgB;2BAAhB,gBAAgB;IAD5B,IAAA,mBAAU,GAAE;IAKR,WAAA,IAAA,eAAM,EAAC,yBAAa,CAAC,CAAA;IACrB,WAAA,IAAA,eAAM,EAAC,0BAAW,CAAC,CAAA;IACnB,WAAA,IAAA,eAAM,EAAC,0BAAe,CAAC,CAAA;IACvB,WAAA,IAAA,eAAM,EAAC,4BAAY,CAAC,CAAA;IACpB,WAAA,IAAA,iBAAQ,GAAE,CAAA;6CAHkC,0BAAW;QACH,0BAAe;QACtB,4BAAY;GAPjD,gBAAgB,CA2E5B"}
|
|
@@ -0,0 +1,42 @@
|
|
|
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.SetupState = void 0;
|
|
16
|
+
const common_1 = require("@nestjs/common");
|
|
17
|
+
const user_service_1 = require("../users/user.service");
|
|
18
|
+
let SetupState = class SetupState {
|
|
19
|
+
users;
|
|
20
|
+
completed = false;
|
|
21
|
+
constructor(users) {
|
|
22
|
+
this.users = users;
|
|
23
|
+
}
|
|
24
|
+
async isRequired() {
|
|
25
|
+
if (this.completed)
|
|
26
|
+
return false;
|
|
27
|
+
const required = (await this.users.countUsers()) === 0;
|
|
28
|
+
if (!required)
|
|
29
|
+
this.completed = true;
|
|
30
|
+
return required;
|
|
31
|
+
}
|
|
32
|
+
markCompleted() {
|
|
33
|
+
this.completed = true;
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
exports.SetupState = SetupState;
|
|
37
|
+
exports.SetupState = SetupState = __decorate([
|
|
38
|
+
(0, common_1.Injectable)(),
|
|
39
|
+
__param(0, (0, common_1.Inject)(user_service_1.UserService)),
|
|
40
|
+
__metadata("design:paramtypes", [user_service_1.UserService])
|
|
41
|
+
], SetupState);
|
|
42
|
+
//# sourceMappingURL=setup-state.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"setup-state.js","sourceRoot":"","sources":["../../src/setup/setup-state.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,2CAAoD;AACpD,wDAAoD;AAG7C,IAAM,UAAU,GAAhB,MAAM,UAAU;IAG6B;IAF1C,SAAS,GAAG,KAAK,CAAC;IAE1B,YAAkD,KAAkB;QAAlB,UAAK,GAAL,KAAK,CAAa;IAAG,CAAC;IAExE,KAAK,CAAC,UAAU;QACd,IAAI,IAAI,CAAC,SAAS;YAAE,OAAO,KAAK,CAAC;QACjC,MAAM,QAAQ,GAAG,CAAC,MAAM,IAAI,CAAC,KAAK,CAAC,UAAU,EAAE,CAAC,KAAK,CAAC,CAAC;QACvD,IAAI,CAAC,QAAQ;YAAE,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC;QACrC,OAAO,QAAQ,CAAC;IAClB,CAAC;IAED,aAAa;QACX,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC;IACxB,CAAC;CACF,CAAA;AAfY,gCAAU;qBAAV,UAAU;IADtB,IAAA,mBAAU,GAAE;IAIE,WAAA,IAAA,eAAM,EAAC,0BAAW,CAAC,CAAA;qCAAyB,0BAAW;GAHzD,UAAU,CAetB"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { AuditService } from '../audit/audit.service';
|
|
2
|
+
import type { OAuth2Config } from '../config/schema';
|
|
3
|
+
import type { RateLimiter } from '../security/rate-limiter';
|
|
4
|
+
import { UserService } from '../users/user.service';
|
|
5
|
+
import { SetupState } from './setup-state';
|
|
6
|
+
export declare class SetupController {
|
|
7
|
+
private readonly cfg;
|
|
8
|
+
private readonly users;
|
|
9
|
+
private readonly audit;
|
|
10
|
+
private readonly limiter;
|
|
11
|
+
private readonly state;
|
|
12
|
+
constructor(cfg: OAuth2Config, users: UserService, audit: AuditService, limiter: RateLimiter, state: SetupState);
|
|
13
|
+
status(): Promise<{
|
|
14
|
+
required: boolean;
|
|
15
|
+
}>;
|
|
16
|
+
setup(req: {
|
|
17
|
+
headers: Record<string, string | string[] | undefined>;
|
|
18
|
+
ip?: string;
|
|
19
|
+
}, body: unknown): Promise<{
|
|
20
|
+
id: string;
|
|
21
|
+
email: string;
|
|
22
|
+
}>;
|
|
23
|
+
}
|
|
@@ -0,0 +1,96 @@
|
|
|
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.SetupController = 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 public_decorator_1 = require("../guard/public.decorator");
|
|
22
|
+
const origin_1 = require("../security/origin");
|
|
23
|
+
const email_1 = require("../security/email");
|
|
24
|
+
const validate_1 = require("../security/validate");
|
|
25
|
+
const user_service_1 = require("../users/user.service");
|
|
26
|
+
const setup_state_1 = require("./setup-state");
|
|
27
|
+
const bodySchema = zod_1.z.object({
|
|
28
|
+
email: zod_1.z.string().transform(email_1.normalizeEmail).pipe(zod_1.z.string().email().max(320)),
|
|
29
|
+
name: zod_1.z.string().min(1).max(255),
|
|
30
|
+
password: zod_1.z.string(),
|
|
31
|
+
});
|
|
32
|
+
let SetupController = class SetupController {
|
|
33
|
+
cfg;
|
|
34
|
+
users;
|
|
35
|
+
audit;
|
|
36
|
+
limiter;
|
|
37
|
+
state;
|
|
38
|
+
constructor(cfg, users, audit, limiter, state) {
|
|
39
|
+
this.cfg = cfg;
|
|
40
|
+
this.users = users;
|
|
41
|
+
this.audit = audit;
|
|
42
|
+
this.limiter = limiter;
|
|
43
|
+
this.state = state;
|
|
44
|
+
}
|
|
45
|
+
async status() {
|
|
46
|
+
return { required: await this.state.isRequired() };
|
|
47
|
+
}
|
|
48
|
+
async setup(req, body) {
|
|
49
|
+
const origin = req.headers.origin;
|
|
50
|
+
(0, origin_1.assertSameOrigin)(Array.isArray(origin) ? origin[0] : origin, this.cfg.publicUrl);
|
|
51
|
+
const { limit, windowSec } = this.cfg.rateLimit.loginPerIp;
|
|
52
|
+
const hit = this.limiter.hit(`setup:${req.ip ?? 'unknown'}`, limit, windowSec);
|
|
53
|
+
if (!hit.ok)
|
|
54
|
+
throw new errors_1.AuthError('rate_limited', 429, 'Too many attempts', { retryAfterSec: hit.retryAfterSec });
|
|
55
|
+
const { email, name, password } = (0, validate_1.parseBody)(bodySchema, body);
|
|
56
|
+
const user = await this.users.withSetupLock(async (trx) => {
|
|
57
|
+
if ((await this.users.countUsers(trx)) > 0) {
|
|
58
|
+
throw new errors_1.AuthError('setup_already_completed', 409, 'Setup has already been completed');
|
|
59
|
+
}
|
|
60
|
+
const u = await this.users.create({ email, name, password }, trx);
|
|
61
|
+
await this.audit.record({ type: 'setup_completed', userId: u.id, ip: req.ip, meta: { email } }, trx);
|
|
62
|
+
return u;
|
|
63
|
+
});
|
|
64
|
+
this.state.markCompleted();
|
|
65
|
+
return { id: user.id, email: user.email };
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
exports.SetupController = SetupController;
|
|
69
|
+
__decorate([
|
|
70
|
+
(0, public_decorator_1.Public)(),
|
|
71
|
+
(0, common_1.Get)(),
|
|
72
|
+
__metadata("design:type", Function),
|
|
73
|
+
__metadata("design:paramtypes", []),
|
|
74
|
+
__metadata("design:returntype", Promise)
|
|
75
|
+
], SetupController.prototype, "status", null);
|
|
76
|
+
__decorate([
|
|
77
|
+
(0, public_decorator_1.Public)(),
|
|
78
|
+
(0, common_1.Post)(),
|
|
79
|
+
(0, common_1.HttpCode)(201),
|
|
80
|
+
__param(0, (0, common_1.Req)()),
|
|
81
|
+
__param(1, (0, common_1.Body)()),
|
|
82
|
+
__metadata("design:type", Function),
|
|
83
|
+
__metadata("design:paramtypes", [Object, Object]),
|
|
84
|
+
__metadata("design:returntype", Promise)
|
|
85
|
+
], SetupController.prototype, "setup", null);
|
|
86
|
+
exports.SetupController = SetupController = __decorate([
|
|
87
|
+
(0, common_1.Controller)('api/auth/setup'),
|
|
88
|
+
__param(0, (0, common_1.Inject)(constants_1.OAUTH2_CONFIG)),
|
|
89
|
+
__param(1, (0, common_1.Inject)(user_service_1.UserService)),
|
|
90
|
+
__param(2, (0, common_1.Inject)(audit_service_1.AuditService)),
|
|
91
|
+
__param(3, (0, common_1.Inject)(constants_1.RATE_LIMITER)),
|
|
92
|
+
__param(4, (0, common_1.Inject)(setup_state_1.SetupState)),
|
|
93
|
+
__metadata("design:paramtypes", [Object, user_service_1.UserService,
|
|
94
|
+
audit_service_1.AuditService, Object, setup_state_1.SetupState])
|
|
95
|
+
], SetupController);
|
|
96
|
+
//# sourceMappingURL=setup.controller.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"setup.controller.js","sourceRoot":"","sources":["../../src/setup/setup.controller.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,2CAAoF;AACpF,6BAAwB;AACxB,0DAAsD;AAEtD,4CAA2D;AAC3D,sCAAsC;AACtC,gEAAmD;AACnD,+CAAsD;AAEtD,6CAAmD;AACnD,mDAAiD;AACjD,wDAAoD;AACpD,+CAA2C;AAE3C,MAAM,UAAU,GAAG,OAAC,CAAC,MAAM,CAAC;IAC1B,KAAK,EAAE,OAAC,CAAC,MAAM,EAAE,CAAC,SAAS,CAAC,sBAAc,CAAC,CAAC,IAAI,CAAC,OAAC,CAAC,MAAM,EAAE,CAAC,KAAK,EAAE,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;IAC7E,IAAI,EAAE,OAAC,CAAC,MAAM,EAAE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U,eAAe;IAD3B,IAAA,mBAAU,EAAC,gBAAgB,CAAC;IAGxB,WAAA,IAAA,eAAM,EAAC,yBAAa,CAAC,CAAA;IACrB,WAAA,IAAA,eAAM,EAAC,0BAAW,CAAC,CAAA;IACnB,WAAA,IAAA,eAAM,EAAC,4BAAY,CAAC,CAAA;IACpB,WAAA,IAAA,eAAM,EAAC,wBAAY,CAAC,CAAA;IACpB,WAAA,IAAA,eAAM,EAAC,wBAAU,CAAC,CAAA;6CAH0B,0BAAW;QACV,4BAAY,UAEd,wBAAU;GAN7C,eAAe,CAyC3B"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { AuditService } from '../audit/audit.service';
|
|
2
|
+
import { SessionStore } from '../bff/session.store';
|
|
3
|
+
import type { OAuth2Config } from '../config/schema';
|
|
4
|
+
import { type RequestUser } from '../guard/current-user.decorator';
|
|
5
|
+
import type { AuthenticatedRequest } from '../guard/session-auth.service';
|
|
6
|
+
import { PasswordService } from '../security/password';
|
|
7
|
+
import type { RateLimiter } from '../security/rate-limiter';
|
|
8
|
+
import { UserService } from './user.service';
|
|
9
|
+
export declare class PasswordController {
|
|
10
|
+
private readonly cfg;
|
|
11
|
+
private readonly users;
|
|
12
|
+
private readonly passwords;
|
|
13
|
+
private readonly audit;
|
|
14
|
+
private readonly limiter;
|
|
15
|
+
private readonly sessions;
|
|
16
|
+
constructor(cfg: OAuth2Config, users: UserService, passwords: PasswordService, audit: AuditService, limiter: RateLimiter, sessions: SessionStore);
|
|
17
|
+
/** Any authenticated user (no role required): change own password, keep this session, drop the others. */
|
|
18
|
+
change(body: unknown, me: RequestUser, req: AuthenticatedRequest): Promise<void>;
|
|
19
|
+
}
|
|
@@ -0,0 +1,87 @@
|
|
|
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.PasswordController = 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 session_store_1 = require("../bff/session.store");
|
|
20
|
+
const constants_1 = require("../constants");
|
|
21
|
+
const errors_1 = require("../errors");
|
|
22
|
+
const current_user_decorator_1 = require("../guard/current-user.decorator");
|
|
23
|
+
const password_1 = require("../security/password");
|
|
24
|
+
const validate_1 = require("../security/validate");
|
|
25
|
+
const user_service_1 = require("./user.service");
|
|
26
|
+
const bodySchema = zod_1.z.object({ currentPassword: zod_1.z.string(), newPassword: zod_1.z.string() }).strict();
|
|
27
|
+
let PasswordController = class PasswordController {
|
|
28
|
+
cfg;
|
|
29
|
+
users;
|
|
30
|
+
passwords;
|
|
31
|
+
audit;
|
|
32
|
+
limiter;
|
|
33
|
+
sessions;
|
|
34
|
+
constructor(cfg, users, passwords, audit, limiter, sessions) {
|
|
35
|
+
this.cfg = cfg;
|
|
36
|
+
this.users = users;
|
|
37
|
+
this.passwords = passwords;
|
|
38
|
+
this.audit = audit;
|
|
39
|
+
this.limiter = limiter;
|
|
40
|
+
this.sessions = sessions;
|
|
41
|
+
}
|
|
42
|
+
/** Any authenticated user (no role required): change own password, keep this session, drop the others. */
|
|
43
|
+
async change(body, me, req) {
|
|
44
|
+
const { limit, windowSec } = this.cfg.rateLimit.loginPerEmail;
|
|
45
|
+
const hit = this.limiter.hit(`pwchange:${me.id}`, limit, windowSec);
|
|
46
|
+
if (!hit.ok)
|
|
47
|
+
throw new errors_1.AuthError('rate_limited', 429, 'Too many attempts', { retryAfterSec: hit.retryAfterSec });
|
|
48
|
+
const { currentPassword, newPassword } = (0, validate_1.parseBody)(bodySchema, body);
|
|
49
|
+
const user = await this.users.findById(me.id);
|
|
50
|
+
if (!user)
|
|
51
|
+
throw new errors_1.AuthError('unauthenticated', 401, 'Not authenticated');
|
|
52
|
+
const ok = user.passwordHash
|
|
53
|
+
? await this.passwords.verify(user.passwordHash, currentPassword)
|
|
54
|
+
: await this.passwords.verifyDummy(currentPassword);
|
|
55
|
+
if (!ok)
|
|
56
|
+
throw new errors_1.AuthError('invalid_credentials', 401, 'Invalid credentials');
|
|
57
|
+
await this.users.setPassword(me.id, newPassword);
|
|
58
|
+
const exceptSessionId = req.authSession?.idHash;
|
|
59
|
+
const exceptGrantId = exceptSessionId ? await this.sessions.grantIdOf(exceptSessionId) : undefined;
|
|
60
|
+
await this.users.revokeAll(me.id, { exceptSessionId, exceptGrantId });
|
|
61
|
+
await this.audit.record({ type: 'password_changed', userId: me.id, actorId: me.id });
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
exports.PasswordController = PasswordController;
|
|
65
|
+
__decorate([
|
|
66
|
+
(0, common_1.Post)(),
|
|
67
|
+
(0, common_1.HttpCode)(204),
|
|
68
|
+
__param(0, (0, common_1.Body)()),
|
|
69
|
+
__param(1, (0, current_user_decorator_1.CurrentUser)()),
|
|
70
|
+
__param(2, (0, common_1.Req)()),
|
|
71
|
+
__metadata("design:type", Function),
|
|
72
|
+
__metadata("design:paramtypes", [Object, Object, Object]),
|
|
73
|
+
__metadata("design:returntype", Promise)
|
|
74
|
+
], PasswordController.prototype, "change", null);
|
|
75
|
+
exports.PasswordController = PasswordController = __decorate([
|
|
76
|
+
(0, common_1.Controller)('api/auth/password'),
|
|
77
|
+
__param(0, (0, common_1.Inject)(constants_1.OAUTH2_CONFIG)),
|
|
78
|
+
__param(1, (0, common_1.Inject)(user_service_1.UserService)),
|
|
79
|
+
__param(2, (0, common_1.Inject)(password_1.PasswordService)),
|
|
80
|
+
__param(3, (0, common_1.Inject)(audit_service_1.AuditService)),
|
|
81
|
+
__param(4, (0, common_1.Inject)(constants_1.RATE_LIMITER)),
|
|
82
|
+
__param(5, (0, common_1.Inject)(session_store_1.SessionStore)),
|
|
83
|
+
__metadata("design:paramtypes", [Object, user_service_1.UserService,
|
|
84
|
+
password_1.PasswordService,
|
|
85
|
+
audit_service_1.AuditService, Object, session_store_1.SessionStore])
|
|
86
|
+
], PasswordController);
|
|
87
|
+
//# sourceMappingURL=password.controller.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"password.controller.js","sourceRoot":"","sources":["../../src/users/password.controller.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,2CAA+E;AAC/E,6BAAwB;AACxB,0DAAsD;AACtD,wDAAoD;AAEpD,4CAA2D;AAC3D,sCAAsC;AACtC,4EAAgF;AAEhF,mDAAuD;AAEvD,mDAAiD;AACjD,iDAA6C;AAE7C,MAAM,UAAU,GAAG,OAAC,CAAC,MAAM,CAAC,EAAE,eAAe,EAAE,OAAC,CAAC,MAAM,EAAE,EAAE,WAAW,EAAE,OAAC,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC;AAGxF,IAAM,kBAAkB,GAAxB,MAAM,kBAAkB;IAEa;IACF;IACI;IACH;IACA;IACA;IANzC,YAC0C,GAAiB,EACnB,KAAkB,EACd,SAA0B,EAC7B,KAAmB,EACnB,OAAoB,EACpB,QAAsB;QALrB,QAAG,GAAH,GAAG,CAAc;QACnB,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AkB,CAiC9B"}
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import { type Locale } from '@opencloudcms/schema';
|
|
2
|
+
import { type Kysely, type Transaction } from 'kysely';
|
|
3
|
+
import { AuditService } from '../audit/audit.service';
|
|
4
|
+
import type { AuthTables } from '../db/types';
|
|
5
|
+
import { PasswordService } from '../security/password';
|
|
6
|
+
import { type Permission } from '../permissions';
|
|
7
|
+
export type Trx = Transaction<AuthTables>;
|
|
8
|
+
export type AuthUser = {
|
|
9
|
+
id: string;
|
|
10
|
+
email: string;
|
|
11
|
+
name: string;
|
|
12
|
+
status: 'active' | 'disabled';
|
|
13
|
+
/** Sorted by key. */
|
|
14
|
+
groups: {
|
|
15
|
+
key: string;
|
|
16
|
+
name: string;
|
|
17
|
+
}[];
|
|
18
|
+
permissions: Permission[];
|
|
19
|
+
isSuperAdmin: boolean;
|
|
20
|
+
passwordHash: string | null;
|
|
21
|
+
lastLoginAt: Date | null;
|
|
22
|
+
locale: Locale | null;
|
|
23
|
+
};
|
|
24
|
+
export interface GrantRevoker {
|
|
25
|
+
/** Destroys the user's Grants (and their codes/tokens) except `exceptGrantId`, and all provider Sessions. */
|
|
26
|
+
revokeAllGrants(userId: string, opts?: {
|
|
27
|
+
exceptGrantId?: string;
|
|
28
|
+
}): Promise<void>;
|
|
29
|
+
/** Destroys the user's provider Sessions only (logout, BFF session expiry). */
|
|
30
|
+
destroyProviderSessions(userId: string): Promise<void>;
|
|
31
|
+
}
|
|
32
|
+
/** Who performs a user-management write (from the request's `RequestUser`). */
|
|
33
|
+
export interface UserActor {
|
|
34
|
+
id: string;
|
|
35
|
+
isSuperAdmin: boolean;
|
|
36
|
+
permissions: readonly Permission[];
|
|
37
|
+
}
|
|
38
|
+
export declare class UserService {
|
|
39
|
+
private readonly db;
|
|
40
|
+
private readonly passwords;
|
|
41
|
+
private readonly audit;
|
|
42
|
+
private readonly revoker;
|
|
43
|
+
constructor(db: Kysely<AuthTables>, passwords: PasswordService, audit: AuditService, revoker: GrantRevoker);
|
|
44
|
+
countUsers(trx?: Trx): Promise<number>;
|
|
45
|
+
findById(id: string, trx?: Trx): Promise<AuthUser | undefined>;
|
|
46
|
+
findByEmail(email: string, trx?: Trx): Promise<AuthUser | undefined>;
|
|
47
|
+
private find;
|
|
48
|
+
/**
|
|
49
|
+
* Creates a user. Without `groupIds` the user joins `super-admin` (setup wizard, env bootstrap); the users API
|
|
50
|
+
* always passes `groupIds` (≥ 1, validated by the controller) and `actor`, whose groups are then limited by
|
|
51
|
+
* ruling R7(a) → 403 `forbidden`. Internal callers without `actor` are trusted. Unknown group id → 422.
|
|
52
|
+
*/
|
|
53
|
+
create(input: {
|
|
54
|
+
email: string;
|
|
55
|
+
name: string;
|
|
56
|
+
password?: string;
|
|
57
|
+
actorId?: string;
|
|
58
|
+
groupIds?: string[];
|
|
59
|
+
actor?: UserActor;
|
|
60
|
+
}, trx?: Trx): Promise<AuthUser>;
|
|
61
|
+
/** Sets (or clears with null) the user's admin UI language. */
|
|
62
|
+
setLocale(userId: string, locale: Locale | null, ctx?: {
|
|
63
|
+
ip?: string;
|
|
64
|
+
userAgent?: string;
|
|
65
|
+
}): Promise<void>;
|
|
66
|
+
setPassword(userId: string, password: string, trx?: Trx): Promise<void>;
|
|
67
|
+
withSetupLock<T>(fn: (trx: Trx) => Promise<T>): Promise<T>;
|
|
68
|
+
/** Number of active users in `super-admin`. */
|
|
69
|
+
private activeSuperAdmins;
|
|
70
|
+
/** True when `userId` is an active super admin and no other active super admin exists. */
|
|
71
|
+
private isLastActiveSuperAdmin;
|
|
72
|
+
/**
|
|
73
|
+
* De-duplicated groups of `ids`, sorted by key, share-locked so a concurrent group delete waits for this
|
|
74
|
+
* transaction; any unknown (or malformed) id → 422 `validation_failed`.
|
|
75
|
+
*/
|
|
76
|
+
private resolveGroups;
|
|
77
|
+
/**
|
|
78
|
+
* Applies `patch` to the user in one transaction under the setup advisory lock (the lock every path that can
|
|
79
|
+
* shrink the set of active super admins takes: groups, status, delete), so two concurrent requests cannot both
|
|
80
|
+
* remove the last super admins. A change that takes the number of active `super-admin` members to 0 rolls
|
|
81
|
+
* back with 409 `last_super_admin` (spec B §3.3). Ruling R7 (403 `forbidden`) is checked first, against the
|
|
82
|
+
* locked target: a non-super-admin may not modify a super admin at all, any field (R7b), and may only add or
|
|
83
|
+
* remove groups within their own permissions (R7a, every group of the symmetric difference current/next).
|
|
84
|
+
*/
|
|
85
|
+
update(userId: string, patch: {
|
|
86
|
+
name?: string;
|
|
87
|
+
status?: 'active' | 'disabled';
|
|
88
|
+
groupIds?: string[];
|
|
89
|
+
}, actor: UserActor): Promise<void>;
|
|
90
|
+
setStatus(userId: string, status: 'active' | 'disabled', actor: UserActor): Promise<void>;
|
|
91
|
+
/** Locks the target user row (404 if missing) and returns their groups. */
|
|
92
|
+
private lockTarget;
|
|
93
|
+
/**
|
|
94
|
+
* Admin password reset: sets the password and revokes every session/grant of the target, audited. A
|
|
95
|
+
* non-super-admin may not reset a super admin's password (R7b, checked against the locked target).
|
|
96
|
+
*/
|
|
97
|
+
resetPassword(userId: string, password: string, actor: UserActor): Promise<void>;
|
|
98
|
+
/**
|
|
99
|
+
* Unlinks one IdP identity of the user (404 when it belongs to someone else), audited. A non-super-admin may
|
|
100
|
+
* not unlink a super admin's identity (R7b: an SSO-only super admin would be locked out).
|
|
101
|
+
*/
|
|
102
|
+
unlinkIdentity(userId: string, identityId: string, actor: UserActor): Promise<void>;
|
|
103
|
+
delete(userId: string, actor: UserActor): Promise<void>;
|
|
104
|
+
/**
|
|
105
|
+
* Deletes the user's BFF sessions and revokes their provider grants. To keep one session working
|
|
106
|
+
* (own password change) pass both its id and its grant (`SessionStore.grantIdOf`): without the grant
|
|
107
|
+
* the kept session would lose its refresh token at the next refresh.
|
|
108
|
+
*/
|
|
109
|
+
revokeAll(userId: string, opts?: {
|
|
110
|
+
exceptSessionId?: string;
|
|
111
|
+
exceptGrantId?: string;
|
|
112
|
+
}, trx?: Trx): Promise<void>;
|
|
113
|
+
touchLogin(userId: string): Promise<void>;
|
|
114
|
+
}
|