@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.
Files changed (213) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +397 -2
  3. package/dist/audit/audit.service.d.ts +18 -0
  4. package/dist/audit/audit.service.js +61 -0
  5. package/dist/audit/audit.service.js.map +1 -0
  6. package/dist/bff/auth.controller.d.ts +41 -0
  7. package/dist/bff/auth.controller.js +269 -0
  8. package/dist/bff/auth.controller.js.map +1 -0
  9. package/dist/bff/cookies.d.ts +11 -0
  10. package/dist/bff/cookies.js +43 -0
  11. package/dist/bff/cookies.js.map +1 -0
  12. package/dist/bff/oidc-client.d.ts +73 -0
  13. package/dist/bff/oidc-client.js +158 -0
  14. package/dist/bff/oidc-client.js.map +1 -0
  15. package/dist/bff/session-refresher.d.ts +27 -0
  16. package/dist/bff/session-refresher.js +95 -0
  17. package/dist/bff/session-refresher.js.map +1 -0
  18. package/dist/bff/session.store.d.ts +88 -0
  19. package/dist/bff/session.store.js +167 -0
  20. package/dist/bff/session.store.js.map +1 -0
  21. package/dist/clients/clients.d.ts +37 -0
  22. package/dist/clients/clients.js +107 -0
  23. package/dist/clients/clients.js.map +1 -0
  24. package/dist/config/schema.d.ts +91 -0
  25. package/dist/config/schema.js +129 -0
  26. package/dist/config/schema.js.map +1 -0
  27. package/dist/constants.d.ts +45 -0
  28. package/dist/constants.js +42 -0
  29. package/dist/constants.js.map +1 -0
  30. package/dist/cors/cors-origins.controller.d.ts +19 -0
  31. package/dist/cors/cors-origins.controller.js +122 -0
  32. package/dist/cors/cors-origins.controller.js.map +1 -0
  33. package/dist/cors/cors-origins.service.d.ts +73 -0
  34. package/dist/cors/cors-origins.service.js +287 -0
  35. package/dist/cors/cors-origins.service.js.map +1 -0
  36. package/dist/cors/customer-cors.middleware.d.ts +22 -0
  37. package/dist/cors/customer-cors.middleware.js +84 -0
  38. package/dist/cors/customer-cors.middleware.js.map +1 -0
  39. package/dist/customers/account.controller.d.ts +91 -0
  40. package/dist/customers/account.controller.js +443 -0
  41. package/dist/customers/account.controller.js.map +1 -0
  42. package/dist/customers/auth-hooks.d.ts +47 -0
  43. package/dist/customers/auth-hooks.js +79 -0
  44. package/dist/customers/auth-hooks.js.map +1 -0
  45. package/dist/customers/customer-auth.controller.d.ts +54 -0
  46. package/dist/customers/customer-auth.controller.js +287 -0
  47. package/dist/customers/customer-auth.controller.js.map +1 -0
  48. package/dist/customers/customer-sessions.revoker.d.ts +21 -0
  49. package/dist/customers/customer-sessions.revoker.js +47 -0
  50. package/dist/customers/customer-sessions.revoker.js.map +1 -0
  51. package/dist/customers/customer.service.d.ts +53 -0
  52. package/dist/customers/customer.service.js +229 -0
  53. package/dist/customers/customer.service.js.map +1 -0
  54. package/dist/customers/customers-admin.controller.d.ts +21 -0
  55. package/dist/customers/customers-admin.controller.js +134 -0
  56. package/dist/customers/customers-admin.controller.js.map +1 -0
  57. package/dist/customers/identifier.d.ts +6 -0
  58. package/dist/customers/identifier.js +27 -0
  59. package/dist/customers/identifier.js.map +1 -0
  60. package/dist/customers/sign-in-settings.controller.d.ts +27 -0
  61. package/dist/customers/sign-in-settings.controller.js +112 -0
  62. package/dist/customers/sign-in-settings.controller.js.map +1 -0
  63. package/dist/customers/sign-in-settings.service.d.ts +35 -0
  64. package/dist/customers/sign-in-settings.service.js +130 -0
  65. package/dist/customers/sign-in-settings.service.js.map +1 -0
  66. package/dist/db/migrations/index.d.ts +2 -0
  67. package/dist/db/migrations/index.js +14 -0
  68. package/dist/db/migrations/index.js.map +1 -0
  69. package/dist/db/migrations/oauth2_0001_init.d.ts +2 -0
  70. package/dist/db/migrations/oauth2_0001_init.js +127 -0
  71. package/dist/db/migrations/oauth2_0001_init.js.map +1 -0
  72. package/dist/db/migrations/oauth2_0002_user_locale.d.ts +3 -0
  73. package/dist/db/migrations/oauth2_0002_user_locale.js +13 -0
  74. package/dist/db/migrations/oauth2_0002_user_locale.js.map +1 -0
  75. package/dist/db/migrations/oauth2_0003_groups.d.ts +6 -0
  76. package/dist/db/migrations/oauth2_0003_groups.js +46 -0
  77. package/dist/db/migrations/oauth2_0003_groups.js.map +1 -0
  78. package/dist/db/migrations/oauth2_0004_customers.d.ts +3 -0
  79. package/dist/db/migrations/oauth2_0004_customers.js +108 -0
  80. package/dist/db/migrations/oauth2_0004_customers.js.map +1 -0
  81. package/dist/db/types.d.ts +176 -0
  82. package/dist/db/types.js +3 -0
  83. package/dist/db/types.js.map +1 -0
  84. package/dist/errors.d.ts +28 -0
  85. package/dist/errors.js +115 -0
  86. package/dist/errors.js.map +1 -0
  87. package/dist/groups/groups.controller.d.ts +28 -0
  88. package/dist/groups/groups.controller.js +126 -0
  89. package/dist/groups/groups.controller.js.map +1 -0
  90. package/dist/groups/groups.service.d.ts +38 -0
  91. package/dist/groups/groups.service.js +134 -0
  92. package/dist/groups/groups.service.js.map +1 -0
  93. package/dist/guard/auth.guard.d.ts +29 -0
  94. package/dist/guard/auth.guard.js +119 -0
  95. package/dist/guard/auth.guard.js.map +1 -0
  96. package/dist/guard/current-user.decorator.d.ts +33 -0
  97. package/dist/guard/current-user.decorator.js +16 -0
  98. package/dist/guard/current-user.decorator.js.map +1 -0
  99. package/dist/guard/customer-auth.decorator.d.ts +26 -0
  100. package/dist/guard/customer-auth.decorator.js +16 -0
  101. package/dist/guard/customer-auth.decorator.js.map +1 -0
  102. package/dist/guard/customer-authenticator.d.ts +58 -0
  103. package/dist/guard/customer-authenticator.js +215 -0
  104. package/dist/guard/customer-authenticator.js.map +1 -0
  105. package/dist/guard/public.decorator.d.ts +2 -0
  106. package/dist/guard/public.decorator.js +8 -0
  107. package/dist/guard/public.decorator.js.map +1 -0
  108. package/dist/guard/session-auth.service.d.ts +28 -0
  109. package/dist/guard/session-auth.service.js +125 -0
  110. package/dist/guard/session-auth.service.js.map +1 -0
  111. package/dist/idp/identity-linker.d.ts +19 -0
  112. package/dist/idp/identity-linker.js +93 -0
  113. package/dist/idp/identity-linker.js.map +1 -0
  114. package/dist/idp/identity-provider.d.ts +54 -0
  115. package/dist/idp/identity-provider.js +36 -0
  116. package/dist/idp/identity-provider.js.map +1 -0
  117. package/dist/idp/idp.controller.d.ts +36 -0
  118. package/dist/idp/idp.controller.js +232 -0
  119. package/dist/idp/idp.controller.js.map +1 -0
  120. package/dist/idp/oidc.identity-provider.d.ts +42 -0
  121. package/dist/idp/oidc.identity-provider.js +96 -0
  122. package/dist/idp/oidc.identity-provider.js.map +1 -0
  123. package/dist/index.d.ts +50 -0
  124. package/dist/index.js +98 -0
  125. package/dist/index.js.map +1 -0
  126. package/dist/interaction/customer-interaction.controller.d.ts +64 -0
  127. package/dist/interaction/customer-interaction.controller.js +336 -0
  128. package/dist/interaction/customer-interaction.controller.js.map +1 -0
  129. package/dist/interaction/interaction.controller.d.ts +36 -0
  130. package/dist/interaction/interaction.controller.js +175 -0
  131. package/dist/interaction/interaction.controller.js.map +1 -0
  132. package/dist/interaction/interaction.service.d.ts +40 -0
  133. package/dist/interaction/interaction.service.js +102 -0
  134. package/dist/interaction/interaction.service.js.map +1 -0
  135. package/dist/maintenance/cleanup.service.d.ts +22 -0
  136. package/dist/maintenance/cleanup.service.js +77 -0
  137. package/dist/maintenance/cleanup.service.js.map +1 -0
  138. package/dist/oauth2.module.d.ts +37 -0
  139. package/dist/oauth2.module.js +214 -0
  140. package/dist/oauth2.module.js.map +1 -0
  141. package/dist/otp/otp-guard.d.ts +7 -0
  142. package/dist/otp/otp-guard.js +27 -0
  143. package/dist/otp/otp-guard.js.map +1 -0
  144. package/dist/otp/otp.service.d.ts +57 -0
  145. package/dist/otp/otp.service.js +202 -0
  146. package/dist/otp/otp.service.js.map +1 -0
  147. package/dist/otp/otp.types.d.ts +36 -0
  148. package/dist/otp/otp.types.js +34 -0
  149. package/dist/otp/otp.types.js.map +1 -0
  150. package/dist/otp/storefront-boot-check.d.ts +13 -0
  151. package/dist/otp/storefront-boot-check.js +53 -0
  152. package/dist/otp/storefront-boot-check.js.map +1 -0
  153. package/dist/permissions.d.ts +12 -0
  154. package/dist/permissions.js +24 -0
  155. package/dist/permissions.js.map +1 -0
  156. package/dist/provider/kysely.adapter.d.ts +27 -0
  157. package/dist/provider/kysely.adapter.js +79 -0
  158. package/dist/provider/kysely.adapter.js.map +1 -0
  159. package/dist/provider/provider.factory.d.ts +101 -0
  160. package/dist/provider/provider.factory.js +377 -0
  161. package/dist/provider/provider.factory.js.map +1 -0
  162. package/dist/provider/provider.service.d.ts +60 -0
  163. package/dist/provider/provider.service.js +200 -0
  164. package/dist/provider/provider.service.js.map +1 -0
  165. package/dist/provider/signing-keys.d.ts +19 -0
  166. package/dist/provider/signing-keys.js +41 -0
  167. package/dist/provider/signing-keys.js.map +1 -0
  168. package/dist/register-migrations.d.ts +1 -0
  169. package/dist/register-migrations.js +7 -0
  170. package/dist/register-migrations.js.map +1 -0
  171. package/dist/security/crypto.d.ts +6 -0
  172. package/dist/security/crypto.js +29 -0
  173. package/dist/security/crypto.js.map +1 -0
  174. package/dist/security/email.d.ts +1 -0
  175. package/dist/security/email.js +7 -0
  176. package/dist/security/email.js.map +1 -0
  177. package/dist/security/origin.d.ts +1 -0
  178. package/dist/security/origin.js +15 -0
  179. package/dist/security/origin.js.map +1 -0
  180. package/dist/security/password.d.ts +12 -0
  181. package/dist/security/password.js +92 -0
  182. package/dist/security/password.js.map +1 -0
  183. package/dist/security/rate-limiter.d.ts +25 -0
  184. package/dist/security/rate-limiter.js +52 -0
  185. package/dist/security/rate-limiter.js.map +1 -0
  186. package/dist/security/return-to.d.ts +6 -0
  187. package/dist/security/return-to.js +33 -0
  188. package/dist/security/return-to.js.map +1 -0
  189. package/dist/security/validate.d.ts +3 -0
  190. package/dist/security/validate.js +14 -0
  191. package/dist/security/validate.js.map +1 -0
  192. package/dist/settings/settings.provider.d.ts +11 -0
  193. package/dist/settings/settings.provider.js +20 -0
  194. package/dist/settings/settings.provider.js.map +1 -0
  195. package/dist/setup/bootstrap.service.d.ts +24 -0
  196. package/dist/setup/bootstrap.service.js +117 -0
  197. package/dist/setup/bootstrap.service.js.map +1 -0
  198. package/dist/setup/setup-state.d.ts +8 -0
  199. package/dist/setup/setup-state.js +42 -0
  200. package/dist/setup/setup-state.js.map +1 -0
  201. package/dist/setup/setup.controller.d.ts +23 -0
  202. package/dist/setup/setup.controller.js +96 -0
  203. package/dist/setup/setup.controller.js.map +1 -0
  204. package/dist/users/password.controller.d.ts +19 -0
  205. package/dist/users/password.controller.js +87 -0
  206. package/dist/users/password.controller.js.map +1 -0
  207. package/dist/users/user.service.d.ts +114 -0
  208. package/dist/users/user.service.js +336 -0
  209. package/dist/users/user.service.js.map +1 -0
  210. package/dist/users/users.controller.d.ts +43 -0
  211. package/dist/users/users.controller.js +188 -0
  212. package/dist/users/users.controller.js.map +1 -0
  213. package/package.json +75 -3
@@ -0,0 +1,64 @@
1
+ import type { Request, Response } from 'express';
2
+ import type { Kysely } from 'kysely';
3
+ import { AuditService } from '../audit/audit.service';
4
+ import type { OAuth2Config } from '../config/schema';
5
+ import { AuthHookRunner } from '../customers/auth-hooks';
6
+ import { CustomerService } from '../customers/customer.service';
7
+ import { SignInSettingsService } from '../customers/sign-in-settings.service';
8
+ import type { AuthTables } from '../db/types';
9
+ import { OtpService } from '../otp/otp.service';
10
+ import { PasswordService } from '../security/password';
11
+ import type { RateLimiter } from '../security/rate-limiter';
12
+ import { InteractionService } from './interaction.service';
13
+ /**
14
+ * Spec "Interaction routes (customer clients only)". Customer sign-in for interactions of the storefront clients;
15
+ * an interaction of any other client answers 404 (and the admin `:uid/login` refuses customer interactions).
16
+ *
17
+ * The account always comes from the verified identifier: the interaction's own session/account (which may belong
18
+ * to the admin realm or to a previous customer in the same browser) is never read.
19
+ */
20
+ export declare class CustomerInteractionController {
21
+ private readonly cfg;
22
+ private readonly db;
23
+ private readonly interactions;
24
+ private readonly customers;
25
+ private readonly settings;
26
+ private readonly otp;
27
+ private readonly hooks;
28
+ private readonly passwords;
29
+ private readonly audit;
30
+ private readonly limiter;
31
+ private readonly logger;
32
+ constructor(cfg: OAuth2Config, db: Kysely<AuthTables>, interactions: InteractionService, customers: CustomerService, settings: SignInSettingsService, otp: OtpService, hooks: AuthHookRunner, passwords: PasswordService, audit: AuditService, limiter: RateLimiter);
33
+ /** `POST otp` `{ identifier }` → `202 { resendAfterSec }` for known, unknown and disabled accounts alike. */
34
+ requestOtp(req: Request, res: Response, uid: string, body: unknown): Promise<void>;
35
+ /** `POST otp/verify` `{ identifier, code, name? }` → `{ redirectTo }`; unknown identifiers sign up. */
36
+ verifyOtp(req: Request, res: Response, uid: string, body: unknown): Promise<{
37
+ redirectTo: string;
38
+ }>;
39
+ /** `POST password` `{ identifier, password }` → `{ redirectTo }`; verified identifiers only. */
40
+ password(req: Request, res: Response, uid: string, body: unknown): Promise<{
41
+ redirectTo: string;
42
+ }>;
43
+ /**
44
+ * The account behind an identifier in one indexed query, whether or not it exists (CustomerService.findByIdentifier
45
+ * runs a second query for known identifiers only, which would make known identifiers measurably slower).
46
+ */
47
+ private lookup;
48
+ private expired;
49
+ /**
50
+ * no-store, same-origin check, then the interaction: expired → `{ redirectTo }`; not a customer client → 404.
51
+ */
52
+ private begin;
53
+ private identify;
54
+ /** IP first; the identifier key is only created for an IP that is not limited (as admin login, M4). */
55
+ private limit;
56
+ private failed;
57
+ /**
58
+ * Sign-up after a verified OTP: `beforeSignUp` and the insert share one transaction (hooks get it as `ctx.db`), so
59
+ * a rejecting hook or a failing insert leaves no customer. Hooks may set the name only: the identifier is always the
60
+ * one the code was just verified for, stored verified (a different identifier from a hook is ignored and logged).
61
+ */
62
+ private signUp;
63
+ private finish;
64
+ }
@@ -0,0 +1,336 @@
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.CustomerInteractionController = 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 clients_1 = require("../clients/clients");
20
+ const constants_1 = require("../constants");
21
+ const auth_hooks_1 = require("../customers/auth-hooks");
22
+ const customer_service_1 = require("../customers/customer.service");
23
+ const identifier_1 = require("../customers/identifier");
24
+ const sign_in_settings_service_1 = require("../customers/sign-in-settings.service");
25
+ const errors_1 = require("../errors");
26
+ const public_decorator_1 = require("../guard/public.decorator");
27
+ const otp_service_1 = require("../otp/otp.service");
28
+ const origin_1 = require("../security/origin");
29
+ const password_1 = require("../security/password");
30
+ const validate_1 = require("../security/validate");
31
+ const interaction_service_1 = require("./interaction.service");
32
+ const identifier = zod_1.z.string().min(1).max(320);
33
+ const otpSchema = zod_1.z.object({ identifier });
34
+ const verifySchema = zod_1.z.object({
35
+ identifier,
36
+ code: zod_1.z.string().min(1).max(16),
37
+ name: zod_1.z.string().trim().min(1).max(200).optional(),
38
+ });
39
+ const passwordSchema = zod_1.z.object({
40
+ identifier,
41
+ // Never trimmed: leading/trailing spaces are part of the password.
42
+ password: zod_1.z.string().min(1).max(1024),
43
+ });
44
+ const AMR = { otp: 'otp', password: 'pwd' };
45
+ /**
46
+ * Spec "Interaction routes (customer clients only)". Customer sign-in for interactions of the storefront clients;
47
+ * an interaction of any other client answers 404 (and the admin `:uid/login` refuses customer interactions).
48
+ *
49
+ * The account always comes from the verified identifier: the interaction's own session/account (which may belong
50
+ * to the admin realm or to a previous customer in the same browser) is never read.
51
+ */
52
+ let CustomerInteractionController = class CustomerInteractionController {
53
+ cfg;
54
+ db;
55
+ interactions;
56
+ customers;
57
+ settings;
58
+ otp;
59
+ hooks;
60
+ passwords;
61
+ audit;
62
+ limiter;
63
+ logger = new common_1.Logger('CustomerInteraction');
64
+ constructor(cfg, db, interactions, customers, settings, otp, hooks, passwords, audit, limiter) {
65
+ this.cfg = cfg;
66
+ this.db = db;
67
+ this.interactions = interactions;
68
+ this.customers = customers;
69
+ this.settings = settings;
70
+ this.otp = otp;
71
+ this.hooks = hooks;
72
+ this.passwords = passwords;
73
+ this.audit = audit;
74
+ this.limiter = limiter;
75
+ }
76
+ /** `POST otp` `{ identifier }` → `202 { resendAfterSec }` for known, unknown and disabled accounts alike. */
77
+ async requestOtp(req, res, uid, body) {
78
+ const ctx = await this.begin(req, res, uid);
79
+ if ('redirectTo' in ctx) {
80
+ res.status(200).json(ctx);
81
+ return;
82
+ }
83
+ const id = this.identify((0, validate_1.parseBody)(otpSchema, body).identifier);
84
+ // Reveals configuration (kind / method off), never accounts.
85
+ await this.settings.assertAllowed(id.kind, 'otp');
86
+ // The same lookup runs for every identifier; only `deliver` differs, and OtpService answers the same either way.
87
+ const existing = await this.lookup(id);
88
+ const deliver = !existing || existing.status === 'active';
89
+ const out = await this.otp.request({ ...id, purpose: 'login', ip: ctx.ip, deliver });
90
+ await this.audit.record({
91
+ type: 'customer.otp_sent',
92
+ ip: ctx.ip,
93
+ userAgent: ctx.userAgent,
94
+ meta: { kind: id.kind, purpose: 'login', ...(existing ? { customerId: existing.id } : {}), ...(deliver ? {} : { suppressed: true }) },
95
+ });
96
+ res.status(202).json(out);
97
+ }
98
+ /** `POST otp/verify` `{ identifier, code, name? }` → `{ redirectTo }`; unknown identifiers sign up. */
99
+ async verifyOtp(req, res, uid, body) {
100
+ const ctx = await this.begin(req, res, uid);
101
+ if ('redirectTo' in ctx)
102
+ return ctx;
103
+ const parsed = (0, validate_1.parseBody)(verifySchema, body);
104
+ const id = this.identify(parsed.identifier);
105
+ await this.settings.assertAllowed(id.kind, 'otp');
106
+ await this.limit(ctx, id, 'otp');
107
+ try {
108
+ // Uniform answer: a disabled account (never given a code) must look like an expired / used-up code.
109
+ await this.otp.verify({ ...id, purpose: 'login', code: parsed.code }, { uniformErrors: true });
110
+ }
111
+ catch (e) {
112
+ if (e instanceof otp_service_1.OtpRejectedError) {
113
+ await this.failed(ctx, 'otp', e.reason === 'expired' || e.reason === 'exhausted' ? 'code_expired' : 'invalid_code');
114
+ }
115
+ throw e;
116
+ }
117
+ // The code proves possession of the identifier; from here on the account is the identifier's.
118
+ const existing = await this.lookup(id);
119
+ let customerId;
120
+ if (existing) {
121
+ if (existing.status !== 'active') {
122
+ await this.failed(ctx, 'otp', 'account_disabled', existing.id);
123
+ throw new errors_1.AuthError('account_disabled', 403, 'Account is disabled');
124
+ }
125
+ if (!existing.verified)
126
+ await this.customers.markVerified(existing.identifierId);
127
+ customerId = existing.id;
128
+ }
129
+ else {
130
+ customerId = (await this.signUp(id, parsed.name, ctx)).id;
131
+ }
132
+ return this.finish(req, res, uid, customerId, 'otp', ctx);
133
+ }
134
+ /** `POST password` `{ identifier, password }` → `{ redirectTo }`; verified identifiers only. */
135
+ async password(req, res, uid, body) {
136
+ const ctx = await this.begin(req, res, uid);
137
+ if ('redirectTo' in ctx)
138
+ return ctx;
139
+ const parsed = (0, validate_1.parseBody)(passwordSchema, body);
140
+ const id = this.identify(parsed.identifier);
141
+ await this.settings.assertAllowed(id.kind, 'password');
142
+ await this.limit(ctx, id, 'password');
143
+ const invalid = () => new errors_1.AuthError('invalid_credentials', 401, 'Invalid identifier or password');
144
+ const customer = await this.lookup(id);
145
+ if (!customer || !customer.passwordHash || !customer.verified) {
146
+ // Same cost as a real verification, so unknown / unverified / password-less identifiers are not distinguishable.
147
+ await this.passwords.verifyDummy(parsed.password);
148
+ await this.failed(ctx, 'password', 'invalid_credentials', customer?.id);
149
+ throw invalid();
150
+ }
151
+ if (!(await this.passwords.verify(customer.passwordHash, parsed.password))) {
152
+ await this.failed(ctx, 'password', 'invalid_credentials', customer.id);
153
+ throw invalid();
154
+ }
155
+ if (customer.status !== 'active') {
156
+ await this.failed(ctx, 'password', 'account_disabled', customer.id);
157
+ throw new errors_1.AuthError('account_disabled', 403, 'Account is disabled');
158
+ }
159
+ return this.finish(req, res, uid, customer.id, 'password', ctx);
160
+ }
161
+ /**
162
+ * The account behind an identifier in one indexed query, whether or not it exists (CustomerService.findByIdentifier
163
+ * runs a second query for known identifiers only, which would make known identifiers measurably slower).
164
+ */
165
+ async lookup(id) {
166
+ const row = await this.db
167
+ .selectFrom('auth_customer_identifiers as i')
168
+ .innerJoin('auth_customers as c', 'c.id', 'i.customer_id')
169
+ .select(['c.id', 'c.status', 'c.password_hash', 'i.id as identifier_id', 'i.verified_at'])
170
+ .where('i.kind', '=', id.kind)
171
+ .where('i.value', '=', id.value)
172
+ .executeTakeFirst();
173
+ if (!row)
174
+ return undefined;
175
+ return {
176
+ id: row.id,
177
+ status: row.status,
178
+ passwordHash: row.password_hash,
179
+ identifierId: row.identifier_id,
180
+ verified: row.verified_at !== null,
181
+ };
182
+ }
183
+ expired() {
184
+ const path = this.cfg.storefront.loginPath;
185
+ return { redirectTo: `${path}${path.includes('?') ? '&' : '?'}error=login_expired` };
186
+ }
187
+ /**
188
+ * no-store, same-origin check, then the interaction: expired → `{ redirectTo }`; not a customer client → 404.
189
+ */
190
+ async begin(req, res, uid) {
191
+ res.setHeader('Cache-Control', 'no-store');
192
+ const origin = req.headers.origin;
193
+ (0, origin_1.assertSameOrigin)(Array.isArray(origin) ? origin[0] : origin, this.cfg.publicUrl);
194
+ let clientId;
195
+ try {
196
+ clientId = await this.interactions.clientIdOf(req, res, uid);
197
+ }
198
+ catch (e) {
199
+ if (e instanceof interaction_service_1.InteractionExpired)
200
+ return this.expired();
201
+ throw e;
202
+ }
203
+ if ((0, clients_1.realmOf)(clientId) !== 'customer')
204
+ throw new errors_1.AuthError('not_found', 404, 'Not found');
205
+ const ua = req.headers['user-agent'];
206
+ return { ip: req.ip ?? 'unknown', userAgent: typeof ua === 'string' ? ua : undefined };
207
+ }
208
+ identify(raw) {
209
+ const id = (0, identifier_1.normalizeIdentifier)(raw, this.cfg.storefront.phoneRegion);
210
+ if (!id)
211
+ throw new errors_1.AuthError('invalid_identifier', 422, 'Enter a valid email address or phone number');
212
+ return id;
213
+ }
214
+ /** IP first; the identifier key is only created for an IP that is not limited (as admin login, M4). */
215
+ async limit(ctx, id, method) {
216
+ const { loginPerEmail, loginPerIp } = this.cfg.rateLimit;
217
+ const byIp = this.limiter.hit(`customer-login:ip:${ctx.ip}`, loginPerIp.limit, loginPerIp.windowSec);
218
+ const byId = byIp.ok
219
+ ? this.limiter.hit(`customer-login:id:${id.kind}:${id.value}`, loginPerEmail.limit, loginPerEmail.windowSec)
220
+ : { ok: true, retryAfterSec: 0 };
221
+ if (byIp.ok && byId.ok)
222
+ return;
223
+ // Audited without an account lookup, so blocked attempts leak nothing about accounts.
224
+ await this.failed(ctx, method, 'rate_limited');
225
+ throw new errors_1.AuthError('rate_limited', 429, 'Too many attempts', {
226
+ retryAfterSec: Math.max(byIp.retryAfterSec, byId.retryAfterSec),
227
+ });
228
+ }
229
+ async failed(ctx, method, reason, customerId) {
230
+ await this.audit.record({
231
+ type: 'customer.login_failed',
232
+ ip: ctx.ip,
233
+ userAgent: ctx.userAgent,
234
+ meta: { method, reason, ...(customerId ? { customerId } : {}) },
235
+ });
236
+ }
237
+ /**
238
+ * Sign-up after a verified OTP: `beforeSignUp` and the insert share one transaction (hooks get it as `ctx.db`), so
239
+ * a rejecting hook or a failing insert leaves no customer. Hooks may set the name only: the identifier is always the
240
+ * one the code was just verified for, stored verified (a different identifier from a hook is ignored and logged).
241
+ */
242
+ async signUp(id, name, ctx) {
243
+ const customer = await this.db.transaction().execute(async (trx) => {
244
+ const input = name === undefined ? { identifier: { ...id } } : { identifier: { ...id }, name };
245
+ const out = await this.hooks.beforeSignUp(input, { db: trx, ip: ctx.ip, userAgent: ctx.userAgent });
246
+ const back = out.identifier;
247
+ if (back && (back.kind !== id.kind || back.value !== id.value)) {
248
+ this.logger.warn('beforeSignUp returned a different identifier; ignored (hooks may only change the name)');
249
+ }
250
+ const finalName = typeof out.name === 'string' && out.name.trim() ? out.name.trim() : null;
251
+ return this.customers.createWithIdentifier({ ...id, name: finalName }, true, trx);
252
+ });
253
+ await this.audit.record({
254
+ type: 'customer.signup',
255
+ ip: ctx.ip,
256
+ userAgent: ctx.userAgent,
257
+ meta: { customerId: customer.id, kind: id.kind, method: 'otp' },
258
+ });
259
+ await this.hooks.after('afterSignUp', customer, { db: this.db, ip: ctx.ip, userAgent: ctx.userAgent });
260
+ return customer;
261
+ }
262
+ async finish(req, res, uid, customerId, method, ctx) {
263
+ let out;
264
+ try {
265
+ out = await this.interactions.finishLogin(req, res, uid, customerId, { amr: [AMR[method]] });
266
+ }
267
+ catch (e) {
268
+ if (e instanceof interaction_service_1.InteractionExpired)
269
+ return this.expired();
270
+ throw e;
271
+ }
272
+ await this.customers.touchLogin(customerId);
273
+ await this.audit.record({
274
+ type: 'customer.login_succeeded',
275
+ ip: ctx.ip,
276
+ userAgent: ctx.userAgent,
277
+ meta: { customerId, method },
278
+ });
279
+ return out;
280
+ }
281
+ };
282
+ exports.CustomerInteractionController = CustomerInteractionController;
283
+ __decorate([
284
+ (0, common_1.Post)(':uid/customer/otp'),
285
+ __param(0, (0, common_1.Req)()),
286
+ __param(1, (0, common_1.Res)()),
287
+ __param(2, (0, common_1.Param)('uid')),
288
+ __param(3, (0, common_1.Body)()),
289
+ __metadata("design:type", Function),
290
+ __metadata("design:paramtypes", [Object, Object, String, Object]),
291
+ __metadata("design:returntype", Promise)
292
+ ], CustomerInteractionController.prototype, "requestOtp", null);
293
+ __decorate([
294
+ (0, common_1.Post)(':uid/customer/otp/verify'),
295
+ (0, common_1.HttpCode)(200),
296
+ __param(0, (0, common_1.Req)()),
297
+ __param(1, (0, common_1.Res)({ passthrough: true })),
298
+ __param(2, (0, common_1.Param)('uid')),
299
+ __param(3, (0, common_1.Body)()),
300
+ __metadata("design:type", Function),
301
+ __metadata("design:paramtypes", [Object, Object, String, Object]),
302
+ __metadata("design:returntype", Promise)
303
+ ], CustomerInteractionController.prototype, "verifyOtp", null);
304
+ __decorate([
305
+ (0, common_1.Post)(':uid/customer/password'),
306
+ (0, common_1.HttpCode)(200),
307
+ __param(0, (0, common_1.Req)()),
308
+ __param(1, (0, common_1.Res)({ passthrough: true })),
309
+ __param(2, (0, common_1.Param)('uid')),
310
+ __param(3, (0, common_1.Body)()),
311
+ __metadata("design:type", Function),
312
+ __metadata("design:paramtypes", [Object, Object, String, Object]),
313
+ __metadata("design:returntype", Promise)
314
+ ], CustomerInteractionController.prototype, "password", null);
315
+ exports.CustomerInteractionController = CustomerInteractionController = __decorate([
316
+ (0, public_decorator_1.Public)(),
317
+ (0, common_1.Controller)('oauth2/interaction'),
318
+ __param(0, (0, common_1.Inject)(constants_1.OAUTH2_CONFIG)),
319
+ __param(1, (0, common_1.Inject)(constants_1.OAUTH2_DB)),
320
+ __param(2, (0, common_1.Inject)(interaction_service_1.InteractionService)),
321
+ __param(3, (0, common_1.Inject)(customer_service_1.CustomerService)),
322
+ __param(4, (0, common_1.Inject)(sign_in_settings_service_1.SignInSettingsService)),
323
+ __param(5, (0, common_1.Inject)(otp_service_1.OtpService)),
324
+ __param(6, (0, common_1.Inject)(auth_hooks_1.AuthHookRunner)),
325
+ __param(7, (0, common_1.Inject)(password_1.PasswordService)),
326
+ __param(8, (0, common_1.Inject)(audit_service_1.AuditService)),
327
+ __param(9, (0, common_1.Inject)(constants_1.RATE_LIMITER)),
328
+ __metadata("design:paramtypes", [Object, Function, interaction_service_1.InteractionService,
329
+ customer_service_1.CustomerService,
330
+ sign_in_settings_service_1.SignInSettingsService,
331
+ otp_service_1.OtpService,
332
+ auth_hooks_1.AuthHookRunner,
333
+ password_1.PasswordService,
334
+ audit_service_1.AuditService, Object])
335
+ ], CustomerInteractionController);
336
+ //# sourceMappingURL=customer-interaction.controller.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"customer-interaction.controller.js","sourceRoot":"","sources":["../../src/interaction/customer-interaction.controller.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,2CAAmG;AAGnG,6BAAwB;AACxB,0DAAsD;AACtD,gDAA6C;AAE7C,4CAAsE;AACtE,wDAA2E;AAC3E,oEAA+E;AAC/E,wDAAmF;AACnF,oFAA8E;AAE9E,sCAAsC;AACtC,gEAAmD;AACnD,oDAAkE;AAClE,+CAAsD;AACtD,mDAAuD;AAEvD,mDAAiD;AACjD,+DAA+E;AAE/E,MAAM,UAAU,GAAG,OAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;AAC9C,MAAM,SAAS,GAAG,OAAC,CAAC,MAAM,CAAC,EAAE,UAAU,EAAE,CAAC,CAAC;AAC3C,MAAM,YAAY,GAAG,OAAC,CAAC,MAAM,CAAC;IAC5B,UAAU;IACV,IAAI,EAAE,OAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,EAAE,CAAC;IAC/B,IAAI,EAAE,OAAC,CAAC,MAAM,EAAE,CAAC,IAAI,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,QAAQ,EAAE;CACnD,CAAC,CAAC;AACH,MAAM,cAAc,GAAG,OAAC,CAAC,MAAM,CAAC;IAC9B,UAAU;IACV,mEAAmE;IACnE,QAAQ,EAAE,OAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC;CACtC,CAAC,CAAC;AA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-0,0 +1,36 @@
1
+ import type { Request, Response } from 'express';
2
+ import { AuditService } from '../audit/audit.service';
3
+ import type { OAuth2Config } from '../config/schema';
4
+ import { type IdentityProvider } from '../idp/identity-provider';
5
+ import { PasswordService } from '../security/password';
6
+ import type { RateLimiter } from '../security/rate-limiter';
7
+ import { UserService } from '../users/user.service';
8
+ import { InteractionService } from './interaction.service';
9
+ type Expired = {
10
+ redirectTo: string;
11
+ };
12
+ /**
13
+ * Spec §6.3 steps 4–5. Registered as a Nest route, so it is matched before oidc-provider, which is
14
+ * mounted at /oauth2 only in ProviderService.onModuleInit.
15
+ */
16
+ export declare class InteractionController {
17
+ private readonly cfg;
18
+ private readonly interactions;
19
+ private readonly users;
20
+ private readonly passwords;
21
+ private readonly audit;
22
+ private readonly limiter;
23
+ private readonly idps;
24
+ constructor(cfg: OAuth2Config, interactions: InteractionService, users: UserService, passwords: PasswordService, audit: AuditService, limiter: RateLimiter, idps: IdentityProvider[]);
25
+ details(req: Request, res: Response, uid: string): Promise<{
26
+ loginHint?: string;
27
+ idps: {
28
+ id: string;
29
+ label: string;
30
+ }[];
31
+ } | Expired>;
32
+ login(req: Request, res: Response, uid: string, body: unknown): Promise<{
33
+ redirectTo: string;
34
+ }>;
35
+ }
36
+ export {};
@@ -0,0 +1,175 @@
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.InteractionController = 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 clients_1 = require("../clients/clients");
20
+ const constants_1 = require("../constants");
21
+ const errors_1 = require("../errors");
22
+ const public_decorator_1 = require("../guard/public.decorator");
23
+ const identity_provider_1 = require("../idp/identity-provider");
24
+ const validate_1 = require("../security/validate");
25
+ const email_1 = require("../security/email");
26
+ const origin_1 = require("../security/origin");
27
+ const password_1 = require("../security/password");
28
+ const user_service_1 = require("../users/user.service");
29
+ const interaction_service_1 = require("./interaction.service");
30
+ const loginSchema = zod_1.z.object({
31
+ email: zod_1.z.string().min(1).max(320),
32
+ // Never trimmed: leading/trailing spaces are part of the password.
33
+ password: zod_1.z.string().min(1).max(1024),
34
+ });
35
+ const expired = () => ({ redirectTo: interaction_service_1.LOGIN_EXPIRED_REDIRECT });
36
+ /**
37
+ * Spec §6.3 steps 4–5. Registered as a Nest route, so it is matched before oidc-provider, which is
38
+ * mounted at /oauth2 only in ProviderService.onModuleInit.
39
+ */
40
+ let InteractionController = class InteractionController {
41
+ cfg;
42
+ interactions;
43
+ users;
44
+ passwords;
45
+ audit;
46
+ limiter;
47
+ idps;
48
+ constructor(cfg, interactions, users, passwords, audit, limiter, idps) {
49
+ this.cfg = cfg;
50
+ this.interactions = interactions;
51
+ this.users = users;
52
+ this.passwords = passwords;
53
+ this.audit = audit;
54
+ this.limiter = limiter;
55
+ this.idps = idps;
56
+ }
57
+ async details(req, res, uid) {
58
+ res.setHeader('Cache-Control', 'no-store');
59
+ try {
60
+ const interaction = await this.interactions.details(req, res, uid);
61
+ // Customer interactions have their own login page and routes; this one only describes admin interactions.
62
+ if ((0, clients_1.realmOf)(interaction.params?.client_id) !== 'admin')
63
+ throw new errors_1.AuthError('not_found', 404, 'Not found');
64
+ const hint = interaction.params?.login_hint;
65
+ return {
66
+ loginHint: typeof hint === 'string' ? hint : undefined,
67
+ idps: this.idps.map(({ id, label }) => ({ id, label })),
68
+ };
69
+ }
70
+ catch (e) {
71
+ if (e instanceof interaction_service_1.InteractionExpired)
72
+ return expired();
73
+ throw e;
74
+ }
75
+ }
76
+ async login(req, res, uid, body) {
77
+ res.setHeader('Cache-Control', 'no-store');
78
+ const origin = req.headers.origin;
79
+ (0, origin_1.assertSameOrigin)(Array.isArray(origin) ? origin[0] : origin, this.cfg.publicUrl);
80
+ const parsed = (0, validate_1.parseBody)(loginSchema, body);
81
+ const email = (0, email_1.normalizeEmail)(parsed.email);
82
+ const { password } = parsed;
83
+ const ip = req.ip ?? 'unknown';
84
+ const userAgent = req.headers['user-agent'];
85
+ const { loginPerEmail, loginPerIp } = this.cfg.rateLimit;
86
+ // M4: IP first; the email key is only created for an IP that is not limited, so a limited client
87
+ // spraying emails adds no entries.
88
+ const byIp = this.limiter.hit(`login:ip:${ip}`, loginPerIp.limit, loginPerIp.windowSec);
89
+ const byEmail = byIp.ok
90
+ ? this.limiter.hit(`login:email:${email}`, loginPerEmail.limit, loginPerEmail.windowSec)
91
+ : { ok: true, retryAfterSec: 0 };
92
+ if (!byIp.ok || !byEmail.ok) {
93
+ // R14: audited without a user lookup (no userId), so blocked attempts leak nothing about accounts.
94
+ const reason = 'rate_limited';
95
+ await this.audit.record({ type: 'login_failed', ip, userAgent, meta: { reason } });
96
+ const retryAfterSec = Math.max(byEmail.retryAfterSec, byIp.retryAfterSec);
97
+ throw new errors_1.AuthError('rate_limited', 429, 'Too many attempts', { retryAfterSec });
98
+ }
99
+ let clientId;
100
+ try {
101
+ clientId = await this.interactions.clientIdOf(req, res, uid);
102
+ }
103
+ catch (e) {
104
+ if (e instanceof interaction_service_1.InteractionExpired)
105
+ return expired();
106
+ throw e;
107
+ }
108
+ // Customer interactions (storefront clients) are finished only by the customer routes.
109
+ if ((0, clients_1.realmOf)(clientId) !== 'admin')
110
+ throw new errors_1.AuthError('not_found', 404, 'Not found');
111
+ const fail = async (reason, userId) => {
112
+ await this.audit.record({ type: 'login_failed', userId, ip, userAgent, meta: { reason } });
113
+ return reason === 'account_disabled'
114
+ ? new errors_1.AuthError('account_disabled', 403, 'Account is disabled')
115
+ : new errors_1.AuthError('invalid_credentials', 401, 'Invalid email or password');
116
+ };
117
+ const user = await this.users.findByEmail(email);
118
+ if (!user || !user.passwordHash) {
119
+ await this.passwords.verifyDummy(password);
120
+ throw await fail('invalid_credentials', user?.id);
121
+ }
122
+ if (!(await this.passwords.verify(user.passwordHash, password))) {
123
+ throw await fail('invalid_credentials', user.id);
124
+ }
125
+ if (user.status !== 'active')
126
+ throw await fail('account_disabled', user.id);
127
+ try {
128
+ const out = await this.interactions.finishLogin(req, res, uid, user.id);
129
+ await this.audit.record({ type: 'login_succeeded', userId: user.id, ip, userAgent });
130
+ return out;
131
+ }
132
+ catch (e) {
133
+ if (e instanceof interaction_service_1.InteractionExpired)
134
+ return expired();
135
+ throw e;
136
+ }
137
+ }
138
+ };
139
+ exports.InteractionController = InteractionController;
140
+ __decorate([
141
+ (0, common_1.Get)(':uid'),
142
+ __param(0, (0, common_1.Req)()),
143
+ __param(1, (0, common_1.Res)({ passthrough: true })),
144
+ __param(2, (0, common_1.Param)('uid')),
145
+ __metadata("design:type", Function),
146
+ __metadata("design:paramtypes", [Object, Object, String]),
147
+ __metadata("design:returntype", Promise)
148
+ ], InteractionController.prototype, "details", null);
149
+ __decorate([
150
+ (0, common_1.Post)(':uid/login'),
151
+ (0, common_1.HttpCode)(200),
152
+ __param(0, (0, common_1.Req)()),
153
+ __param(1, (0, common_1.Res)({ passthrough: true })),
154
+ __param(2, (0, common_1.Param)('uid')),
155
+ __param(3, (0, common_1.Body)()),
156
+ __metadata("design:type", Function),
157
+ __metadata("design:paramtypes", [Object, Object, String, Object]),
158
+ __metadata("design:returntype", Promise)
159
+ ], InteractionController.prototype, "login", null);
160
+ exports.InteractionController = InteractionController = __decorate([
161
+ (0, public_decorator_1.Public)(),
162
+ (0, common_1.Controller)('oauth2/interaction'),
163
+ __param(0, (0, common_1.Inject)(constants_1.OAUTH2_CONFIG)),
164
+ __param(1, (0, common_1.Inject)(interaction_service_1.InteractionService)),
165
+ __param(2, (0, common_1.Inject)(user_service_1.UserService)),
166
+ __param(3, (0, common_1.Inject)(password_1.PasswordService)),
167
+ __param(4, (0, common_1.Inject)(audit_service_1.AuditService)),
168
+ __param(5, (0, common_1.Inject)(constants_1.RATE_LIMITER)),
169
+ __param(6, (0, common_1.Inject)(identity_provider_1.IDENTITY_PROVIDERS)),
170
+ __metadata("design:paramtypes", [Object, interaction_service_1.InteractionService,
171
+ user_service_1.UserService,
172
+ password_1.PasswordService,
173
+ audit_service_1.AuditService, Object, Array])
174
+ ], InteractionController);
175
+ //# sourceMappingURL=interaction.controller.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"interaction.controller.js","sourceRoot":"","sources":["../../src/interaction/interaction.controller.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,2CAAgG;AAEhG,6BAAwB;AACxB,0DAAsD;AACtD,gDAA6C;AAE7C,4CAA2D;AAC3D,sCAAsC;AACtC,gEAAmD;AACnD,gEAAqF;AACrF,mDAAiD;AACjD,6CAAmD;AACnD,+CAAsD;AACtD,mDAAuD;AAEvD,wDAAoD;AACpD,+DAAuG;AAEvG,MAAM,WAAW,GAAG,OAAC,CAAC,MAAM,CAAC;IAC3B,KAAK,EAAE,OAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC;IACjC,mEAAmE;IACnE,QAAQ,EAAE,OAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC;CACtC,CAAC,CAAC;AAIH,MAAM,OAAO,GAAG,GAAY,EAAE,CAAC,CAAC,EAAE,UA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