@bymax-one/nest-auth 1.4.0 → 1.4.2
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/CHANGELOG.md +208 -3
- package/README.md +86 -1
- package/dist/server/index.cjs +109 -50
- package/dist/server/index.d.cts +55 -21
- package/dist/server/index.d.ts +55 -21
- package/dist/server/index.mjs +109 -51
- package/package.json +2 -1
package/CHANGELOG.md
CHANGED
|
@@ -2,8 +2,211 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to `@bymax-one/nest-auth` will be documented in this file.
|
|
4
4
|
|
|
5
|
-
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
|
|
6
|
-
|
|
5
|
+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
|
|
6
|
+
|
|
7
|
+
**Versioning, while the library is pre-adoption.** [Semantic Versioning](https://semver.org/spec/v2.0.0.html)
|
|
8
|
+
is the target, not yet the practice. Until the API settles, breaking changes ship in **minor and
|
|
9
|
+
patch** releases rather than driving the major, deliberately: the library has no production
|
|
10
|
+
dependant, the surface is still being corrected as audits land, and a major per breaking change
|
|
11
|
+
would put a young library in double digits while saying nothing useful about its stability.
|
|
12
|
+
Strict SemVer starts when the API is declared stable, and that transition will be announced here.
|
|
13
|
+
|
|
14
|
+
**What this means for you:** do not infer compatibility from the version number in the `1.x` line
|
|
15
|
+
— `^1.4.0` and `~1.4.0` both resolve to releases that may break you. Read the entry before
|
|
16
|
+
upgrading. Every breaking change carries an **Apply to a derived backend** note saying exactly
|
|
17
|
+
what moves, and that note is the compatibility contract until strict SemVer begins.
|
|
18
|
+
|
|
19
|
+
## [Unreleased]
|
|
20
|
+
|
|
21
|
+
## [1.4.2] - 2026-08-13
|
|
22
|
+
|
|
23
|
+
Closes the two findings that came out of auditing this library from the outside: every DTO it
|
|
24
|
+
ships published an empty schema, and a request naming a tenant a configured resolver would not
|
|
25
|
+
honour was answered `201` with the account created elsewhere. **One breaking change rides along
|
|
26
|
+
in a patch** — the tenant refusal — so `^1.4.0` and `~1.4.1` both pick it up on a routine update.
|
|
27
|
+
Read the `Apply to a derived backend` note before upgrading.
|
|
28
|
+
|
|
29
|
+
### Added
|
|
30
|
+
|
|
31
|
+
- **Request-body schemas, generated from the DTOs' own decorators**
|
|
32
|
+
([`conformance/openapi-request-schemas.json`](conformance/openapi-request-schemas.json)).
|
|
33
|
+
OpenAPI 3.0 for all 22 DTOs, derived from class-validator metadata and regenerated by
|
|
34
|
+
`pnpm gen:openapi-schemas`. It closes a gap a consumer's OpenAPI audit found: because the
|
|
35
|
+
`@nestjs/swagger` CLI plugin does not run over precompiled `node_modules`, every DTO this
|
|
36
|
+
library ships published as `{"type":"object","properties":{}}`, and the real contracts were
|
|
37
|
+
discoverable only by triggering validation errors.
|
|
38
|
+
|
|
39
|
+
The artifact is data rather than code so `rust-auth` can assert the same file, and it is
|
|
40
|
+
**generated, not hand-written**: the suite regenerates and fails on drift, so a decorator
|
|
41
|
+
change nobody mirrored is a red test in the repository that caused it. Three guards make the
|
|
42
|
+
gate mean what it says — the committed copy must equal the regeneration, the set of validators
|
|
43
|
+
the derivation understands is pinned by name (an unmapped decorator is silent, so a new one
|
|
44
|
+
must fail rather than thin the schema), and the DTO list is asserted so a DTO added later
|
|
45
|
+
cannot be quietly uncovered.
|
|
46
|
+
|
|
47
|
+
A regex carrying flags is **refused** rather than rendered: `pattern` is the ECMA 262 dialect
|
|
48
|
+
with no flags slot (JSON Schema Wright Draft 00 §5.2.3) and ECMA 262 has no inline modifier to
|
|
49
|
+
rewrite them into, so emitting `.source` would publish a stricter pattern than the server
|
|
50
|
+
enforces, silently.
|
|
51
|
+
|
|
52
|
+
- **Normalisation descriptions, each carrying the probe that verifies it**
|
|
53
|
+
([`conformance/openapi-request-descriptions.json`](conformance/openapi-request-descriptions.json)).
|
|
54
|
+
Twelve e-mail fields are trimmed and lowercased before validation — a fact a client needs and
|
|
55
|
+
no schema keyword expresses. A generator cannot derive it, because `@Transform` runs an opaque
|
|
56
|
+
lambda, so the prose is written by hand and every entry ships an `{ input, expected }` probe the
|
|
57
|
+
suite runs through `plainToInstance`. The probe is the sentence's operational meaning rather
|
|
58
|
+
than a test beside it, so prose and behaviour cannot drift.
|
|
59
|
+
|
|
60
|
+
The opposite direction is covered by a canary sweep: one rich input through every string
|
|
61
|
+
property of all 22 DTOs, failing when a property transforms without a declared entry. Stated
|
|
62
|
+
limit, in the artifact itself: a future transform that is the identity on that canary escapes
|
|
63
|
+
both checks. The rejected alternative — reading class-transformer's `cjs/storage` internals —
|
|
64
|
+
has no type declarations and is an unpublished path that can move between minors.
|
|
65
|
+
|
|
66
|
+
### Fixed
|
|
67
|
+
|
|
68
|
+
- **BREAKING: a request body naming `tenantId` is now refused when the deployment configures a
|
|
69
|
+
`tenantIdResolver`**, instead of being accepted and silently discarded. A security audit of a
|
|
70
|
+
derived backend found `POST /register` answering `201` for
|
|
71
|
+
`{"tenantId": "attacker-chosen-tenant", ...}` while creating the account under the resolved
|
|
72
|
+
tenant — the caller's belief about which tenant it registered into diverging from server state,
|
|
73
|
+
on the boundary the resolver exists to defend, with nothing in the response saying so. No
|
|
74
|
+
privilege crossed, and that is why it survived: accept-and-ignore is the worst of the three
|
|
75
|
+
available answers precisely because it looks like success.
|
|
76
|
+
|
|
77
|
+
The refusal is **conditional, and the asymmetry is the point**. Without a resolver the field is
|
|
78
|
+
the only thing that can name a tenant — `resolveTenantId` already answers `400` when it is
|
|
79
|
+
absent — so rejecting it outright would break every deployment that relies on it. With a
|
|
80
|
+
resolver configured it does not participate at all, and whitelist validation already refuses
|
|
81
|
+
`role` and `status` on exactly that principle. This makes the principle config-aware rather
|
|
82
|
+
than carving an exception out of it.
|
|
83
|
+
|
|
84
|
+
`null` and an omitted field are not refused: the caller asserted nothing, so there is nothing
|
|
85
|
+
to contradict.
|
|
86
|
+
|
|
87
|
+
**Apply to a derived backend:** if you configure `tenantIdResolver`, stop sending `tenantId` on
|
|
88
|
+
the nine endpoints that accept it. Eight read it from the **request body** — `register`,
|
|
89
|
+
`login`, `verify-email`, `resend-verification`, `forgot-password`, `reset-password`,
|
|
90
|
+
`verify-otp`, `resend-otp` — and one reads it from the **query string**:
|
|
91
|
+
`GET /oauth/:provider?tenantId=…`, so dropping a body field is not the change to make there.
|
|
92
|
+
All nine answered `201`/`200` while discarding the value and now answer `400 auth.validation`
|
|
93
|
+
with `field: "tenantId"`. Deployments without a resolver are unaffected — the field remains
|
|
94
|
+
required there.
|
|
95
|
+
|
|
96
|
+
## [1.4.1] - 2026-08-12
|
|
97
|
+
|
|
98
|
+
Aligns every HTTP status with `rust-auth` and makes the pairing structural rather than
|
|
99
|
+
conventional. **Two breaking changes ride along in a patch release** — the `AuthException`
|
|
100
|
+
signature and thirteen HTTP status codes — matching how this line has shipped breaking changes
|
|
101
|
+
before (see `1.3.2`). Both `^1.4.0` and `~1.4.0` resolve to it, so a routine update picks it up:
|
|
102
|
+
read the migration notes below before upgrading. The `AuthException` half is compiler-guided;
|
|
103
|
+
the status half is not, and will surface as failing assertions in any suite that pins statuses.
|
|
104
|
+
|
|
105
|
+
### Fixed
|
|
106
|
+
|
|
107
|
+
- **BREAKING: thirteen error codes answered the wrong HTTP status, and five answered two.**
|
|
108
|
+
A consumer's OpenAPI audit surfaced `auth.email_already_exists` answering `401` here and `409`
|
|
109
|
+
in `rust-auth`. It was not one code. `auth.session_not_found` answered `401` instead of `404`;
|
|
110
|
+
`auth.mfa_already_enabled` `401` instead of `409`; `auth.mfa_not_enabled`,
|
|
111
|
+
`auth.mfa_setup_required`, `auth.password_reset_token_invalid`,
|
|
112
|
+
`auth.email_change_token_invalid` and `auth.invalid_invitation_token` `401` instead of `400`.
|
|
113
|
+
Five more disagreed with _themselves_ depending on the throw site: `auth.account_locked` was
|
|
114
|
+
`429` on login but `401` on the MFA and password-reset lockouts — so a client backing off on
|
|
115
|
+
`429` did not back off on the others — and `auth.email_not_verified`, `auth.mfa_required`,
|
|
116
|
+
`auth.forbidden` and `auth.token_invalid` each answered two statuses across the codebase.
|
|
117
|
+
Every value now matches `rust-auth`, which was the correct side throughout.
|
|
118
|
+
|
|
119
|
+
**Root cause, and why no gate caught it.** `conformance/wire-contract.json` pinned the code
|
|
120
|
+
_vocabulary_ and not the status per code, so the field had no gate at all; and
|
|
121
|
+
`AuthException`'s status argument defaulted to `401`, making an omission neither a type error
|
|
122
|
+
nor a lint error but a plausible-looking wrong answer. Both libraries' suites were green
|
|
123
|
+
throughout — each side was self-consistent, and neither read the other.
|
|
124
|
+
|
|
125
|
+
**Apply to a derived backend:** if you assert on HTTP statuses, thirteen codes move. The eight
|
|
126
|
+
above take their new value everywhere. The five that answered two statuses now answer one, and
|
|
127
|
+
a route-level assertion can fail on any of them even where the code itself is unchanged:
|
|
128
|
+
`auth.account_locked` is `429` on every path (it was `401` on the MFA and password-reset
|
|
129
|
+
lockouts), `auth.email_not_verified` is `403` (it was `401` on login and in `UserStatusGuard`),
|
|
130
|
+
`auth.mfa_required` is `403` (it was `401` on the login MFA gate), `auth.forbidden` is `403`
|
|
131
|
+
(it was `401` at every throw site), and `auth.token_invalid` is `401` (it was `400` in
|
|
132
|
+
`SelfOrAdminGuard`'s hash-format rejection). Statuses only — no code string, message or
|
|
133
|
+
envelope shape changed.
|
|
134
|
+
|
|
135
|
+
### Changed
|
|
136
|
+
|
|
137
|
+
- **BREAKING: `AuthException` no longer takes a status argument.** The signature is now
|
|
138
|
+
`new AuthException(code, details?)`; the status is derived from the code via the new
|
|
139
|
+
`AUTH_ERROR_STATUS` table. One code answering two statuses is no longer expressible, which is
|
|
140
|
+
what the defaulted argument allowed. **Apply to a derived backend:** drop the second argument
|
|
141
|
+
where you passed a status — `new AuthException(CODE, HttpStatus.FORBIDDEN)` becomes
|
|
142
|
+
`new AuthException(CODE)`, and `new AuthException(CODE, status, details)` becomes
|
|
143
|
+
`new AuthException(CODE, details)`. TypeScript flags the old three-argument form and any
|
|
144
|
+
numeric status passed where `details` is now expected, so the migration is compiler-guided
|
|
145
|
+
rather than silent.
|
|
146
|
+
|
|
147
|
+
### Added
|
|
148
|
+
|
|
149
|
+
- **`AUTH_ERROR_STATUS`** ([`src/server/errors/auth-error-codes.ts`](src/server/errors/auth-error-codes.ts)),
|
|
150
|
+
exported from the package root: the `code → HTTP status` map every error answers by. Useful
|
|
151
|
+
for a generated client, an API document, or a test asserting against the wire contract.
|
|
152
|
+
|
|
153
|
+
- **`errorCatalog.statuses` in [`conformance/wire-contract.json`](conformance/wire-contract.json)**,
|
|
154
|
+
byte-identical with `rust-auth` like the rest of that file, plus conformance tests asserting
|
|
155
|
+
`AUTH_ERROR_STATUS` against it, that the table covers the catalog exactly, and that each
|
|
156
|
+
internal-only code carries the status of the public code it collapses onto — a differing
|
|
157
|
+
status would hand back through the status line what the collapse removes from the body.
|
|
158
|
+
These are wire statuses: `auth.otp_max_attempts` is `401` because a caller receives it as
|
|
159
|
+
`auth.otp_invalid`, and a `429` would say the address was registered, since only a record
|
|
160
|
+
that exists can reach an attempt ceiling.
|
|
161
|
+
|
|
162
|
+
### Tests
|
|
163
|
+
|
|
164
|
+
- **19 end-to-end status-window assertions replaced with an exact `(code, status)` pair**, across
|
|
165
|
+
six spec files, via a shared `expectAuthError` helper: 16 were a bounded `status >= 400 &&
|
|
166
|
+
status < 500`, and 3 asserted only the `>= 400` lower bound, which is looser still. That form
|
|
167
|
+
is why the drift above survived the suite — `401` where the contract says `404` is still a 4xx,
|
|
168
|
+
so the check was satisfied by the right answer and the wrong one alike. Four of them asserted
|
|
169
|
+
no error code at all and now do.
|
|
170
|
+
|
|
171
|
+
- **Two negated status assertions replaced in the rate-limit spec.** `expect(status).not.toBe(429)`
|
|
172
|
+
accepts every wrong answer but one: the allowed login attempts now assert
|
|
173
|
+
`auth.invalid_credentials` at the contract's status, and the separate-budget reset asserts
|
|
174
|
+
`200` exactly, which also pins the anti-enumeration answer. Same defect as the range, one
|
|
175
|
+
shape further out — and harder to spot, because a negation reads like a deliberate claim
|
|
176
|
+
about a specific status.
|
|
177
|
+
|
|
178
|
+
- **The internal-only code list is now pinned by name.** Every other assertion about those codes
|
|
179
|
+
lives inside a `for … of contract.errorCatalog.internalOnly` loop, so an empty or shortened
|
|
180
|
+
list did not fail them — it stopped them running, and they reported success for having checked
|
|
181
|
+
nothing. Unlike `codes` and `statuses`, nothing had pinned that array's contents.
|
|
182
|
+
|
|
183
|
+
- **MFA specs derive TOTP codes from the live step rather than a remembered one**
|
|
184
|
+
([`mfa-disable-flow`](test/e2e/mfa-disable-flow.e2e-spec.ts),
|
|
185
|
+
[`mfa-recovery-codes-flow`](test/e2e/mfa-recovery-codes-flow.e2e-spec.ts)). The fixtures spend
|
|
186
|
+
two adjacent TOTP counters and then reached one step backwards for a free slot, assuming the
|
|
187
|
+
whole fixture lands inside a single 30-second step. Crossing a step boundary inverted that
|
|
188
|
+
assumption: the slot reached for was the one `verify-enable` had burned, the anti-replay guard
|
|
189
|
+
refused it, and `/mfa/disable` answered `401`, which surfaced as a pre-disable token still
|
|
190
|
+
being accepted. A test defect, not a library one — the guard and the ±1 window behaved as
|
|
191
|
+
designed.
|
|
192
|
+
|
|
193
|
+
- **`AuthException` is now tested against inherited `Object` members** (`constructor`,
|
|
194
|
+
`toString`, `__proto__`, `hasOwnProperty`) and against a code absent from the catalog.
|
|
195
|
+
|
|
196
|
+
### Internal / CI
|
|
197
|
+
|
|
198
|
+
- **OSV-Scanner workflow** ([`.github/workflows/osv-scanner.yml`](.github/workflows/osv-scanner.yml)),
|
|
199
|
+
a thin caller of the shared reusable. It scans the full resolved dependency tree on push, pull
|
|
200
|
+
request and a weekly schedule — coverage neither `dependency-review` (pull-request diff only)
|
|
201
|
+
nor `peer-advisory-drift` (declared ranges only) provides, since an already-installed
|
|
202
|
+
transitive package can turn vulnerable between releases.
|
|
203
|
+
|
|
204
|
+
- **`conformance/wire-contract.json` excluded from Prettier**
|
|
205
|
+
([`.prettierignore`](.prettierignore)). Its bytes are the contract — the file must stay
|
|
206
|
+
byte-identical with `rust-auth`'s copy, and the `lint-staged` glob `*.{json,md,yml,yaml}` runs
|
|
207
|
+
`prettier --write` over it, so an ordinary commit was one formatting-default change away from
|
|
208
|
+
breaking the pairing with no signal at all. Nothing in either repository compares one copy to
|
|
209
|
+
the other, which is what makes a silent reformat unrecoverable rather than merely wrong.
|
|
7
210
|
|
|
8
211
|
## [1.4.0] - 2026-08-11
|
|
9
212
|
|
|
@@ -1342,7 +1545,9 @@ ever installable.
|
|
|
1342
1545
|
- Phase 4 password-reset tests cover: both `token` and `otp` flows, mutual exclusivity validation, `verifiedToken` exchange, resend cooldown, anti-enumeration (no error on unknown email), and session invalidation on reset
|
|
1343
1546
|
- Phase 5 tests cover: platform login with MFA path and brute-force lockout, `JwtPlatformGuard` cross-context rejection, `PlatformRolesGuard` hierarchy enforcement, OAuth CSRF state lifecycle, `onOAuthLogin` hook resolution strategies, and invitation role-authorization + acceptance single-use enforcement
|
|
1344
1547
|
|
|
1345
|
-
[Unreleased]: https://github.com/bymaxone/nest-auth/compare/v1.
|
|
1548
|
+
[Unreleased]: https://github.com/bymaxone/nest-auth/compare/v1.4.2...HEAD
|
|
1549
|
+
[1.4.2]: https://github.com/bymaxone/nest-auth/compare/v1.4.1...v1.4.2
|
|
1550
|
+
[1.4.1]: https://github.com/bymaxone/nest-auth/compare/v1.4.0...v1.4.1
|
|
1346
1551
|
[1.4.0]: https://github.com/bymaxone/nest-auth/compare/v1.3.2...v1.4.0
|
|
1347
1552
|
[1.3.2]: https://github.com/bymaxone/nest-auth/compare/v1.3.1...v1.3.2
|
|
1348
1553
|
[1.3.1]: https://github.com/bymaxone/nest-auth/compare/v1.3.0...v1.3.1
|
package/README.md
CHANGED
|
@@ -958,7 +958,7 @@ When integrating `@bymax-one/nest-auth` in production, verify each of the follow
|
|
|
958
958
|
Authentication is critical infrastructure, so the suite is held to a bar beyond "it runs" — every behavior is pinned so that a regression **fails a test**.
|
|
959
959
|
|
|
960
960
|
- ✅ **100% line coverage** — statements, branches, functions, and lines, enforced as a release gate across unit + e2e
|
|
961
|
-
- ✅ **100% mutation score** — verified with [Stryker](https://stryker-mutator.io/): 4,
|
|
961
|
+
- ✅ **100% mutation score** — verified with [Stryker](https://stryker-mutator.io/): 4,989 seeded faults detected (4,968 killed, 21 timed out), **no survivors and nothing left uncovered**, against a `break` threshold of 100 ([measured cold on 2026-08-12](./docs/mutation_testing_results.md#re-measured-cold--2026-08-12))
|
|
962
962
|
- ✅ **3,547 tests** — 3,420 unit and 127 end-to-end, spanning all five subpaths
|
|
963
963
|
- ✅ **Every equivalent mutant documented** — the 350 mutants that no test can kill (a redundant guard, a dependency array of stable references) each carry an inline `// Stryker disable` with the reason, so the score is an accounting rather than a number
|
|
964
964
|
|
|
@@ -1020,6 +1020,61 @@ Conditionally registered controllers (mfa, sessions, platform, invitations, oaut
|
|
|
1020
1020
|
> hand a victim a callback URL and have the victim's browser complete the attacker's login.
|
|
1021
1021
|
> Mount `app.use(cookieParser())` before the module's routes or every callback answers 401.
|
|
1022
1022
|
|
|
1023
|
+
### Request bodies
|
|
1024
|
+
|
|
1025
|
+
Validated by `createAuthValidationPipe()` with `whitelist` and `forbidNonWhitelisted`, so an
|
|
1026
|
+
unknown property is a `400 auth.validation` rather than a silently ignored field. `tenantId` is
|
|
1027
|
+
optional on every **unauthenticated** body below (≤128 chars, no control characters) and scopes
|
|
1028
|
+
the operation to one organization. `POST /password/change` is the exception: it is behind
|
|
1029
|
+
`JwtAuthGuard`, takes its tenant from the JWT, and declares no `tenantId` — so sending one is an
|
|
1030
|
+
unknown property, and `forbidNonWhitelisted` answers `400 auth.validation`. Email fields are
|
|
1031
|
+
trimmed and lowercased before they reach the service, so the stored identity matches the
|
|
1032
|
+
case-insensitive lookup and every email-keyed control.
|
|
1033
|
+
|
|
1034
|
+
| Endpoint | Body |
|
|
1035
|
+
| -------------------------------- | -------------------------------------------------------------------------------- |
|
|
1036
|
+
| `POST /register` | `{ email, password, name }` — `name` 2–128 |
|
|
1037
|
+
| `POST /login` | `{ email, password }` |
|
|
1038
|
+
| `POST /verify-email` | `{ email, otp }` — `otp` is **exactly 6 digits** |
|
|
1039
|
+
| `POST /resend-verification` | `{ email }` |
|
|
1040
|
+
| `POST /password/forgot-password` | `{ email }` |
|
|
1041
|
+
| `POST /password/verify-otp` | `{ email, otp }` |
|
|
1042
|
+
| `POST /password/resend-otp` | `{ email }` |
|
|
1043
|
+
| `POST /password/reset-password` | `{ email, newPassword }` **plus exactly one** of `token`, `otp`, `verifiedToken` |
|
|
1044
|
+
| `POST /password/change` | `{ currentPassword, newPassword }` |
|
|
1045
|
+
|
|
1046
|
+
Three constraints are worth stating because they are not visible from the field names:
|
|
1047
|
+
|
|
1048
|
+
- **`reset-password` carries exactly one proof.** `token` is the emailed URL parameter, `otp` the
|
|
1049
|
+
emailed 4–8 character code, and `verifiedToken` the 64-character handle `POST
|
|
1050
|
+
/password/verify-otp` returns (5-minute TTL) so the OTP need not be re-submitted. All three are
|
|
1051
|
+
optional at the validation boundary and the mutual exclusivity is enforced in the service — a
|
|
1052
|
+
body carrying none or more than one is rejected there, not by the DTO.
|
|
1053
|
+
- **The password length the DTO enforces is not your policy.** `@MinLength(8)` is structural: it
|
|
1054
|
+
is the floor NIST SP 800-63B-4 §3.1.1.1 permits under any circumstance, and it is what a
|
|
1055
|
+
decorator can express, since decorators evaluate before any configuration exists. The real
|
|
1056
|
+
floor is `password.minLength` — **default 15** — enforced by `PasswordService`, which answers
|
|
1057
|
+
the same `auth.validation` code and `details` shape. A client that validates against 8 will see
|
|
1058
|
+
a `400` from the service.
|
|
1059
|
+
- **`login` deliberately floors `password` at 1 character.** Rejecting only the empty string
|
|
1060
|
+
stops a caller from spending a full scrypt derivation for free; enforcing the configured policy
|
|
1061
|
+
length here would leak it as a pre-KDF timing signal, because a request failing validation
|
|
1062
|
+
returns before the hash runs.
|
|
1063
|
+
|
|
1064
|
+
#### Machine-readable schemas
|
|
1065
|
+
|
|
1066
|
+
The same contracts are published as data in
|
|
1067
|
+
[`conformance/openapi-request-schemas.json`](./conformance/openapi-request-schemas.json) —
|
|
1068
|
+
OpenAPI 3.0 schemas for all 22 DTOs, generated from the decorators themselves and regenerated by
|
|
1069
|
+
`pnpm gen:openapi-schemas`. Alongside it,
|
|
1070
|
+
[`openapi-request-descriptions.json`](./conformance/openapi-request-descriptions.json) carries the
|
|
1071
|
+
facts no keyword expresses: the twelve e-mail fields that are **trimmed and lowercased before
|
|
1072
|
+
validation**, each entry shipping the probe that verifies its own sentence.
|
|
1073
|
+
|
|
1074
|
+
Both are development artifacts — they are not in the published tarball, and nothing reads them at
|
|
1075
|
+
runtime yet. They exist so the schemas are a function of the decorators rather than a second
|
|
1076
|
+
description maintained by hand, and so the same file can be asserted from `rust-auth`.
|
|
1077
|
+
|
|
1023
1078
|
### Administrative operations — methods, deliberately not routes
|
|
1024
1079
|
|
|
1025
1080
|
Two support-desk operations ship as **methods with no HTTP route**. Every route above is scoped
|
|
@@ -1092,6 +1147,36 @@ It passes an `AuthException` through untouched, keeps the status any other `Http
|
|
|
1092
1147
|
chose, and answers an unhandled throw with `auth.internal` and a generic message — never the
|
|
1093
1148
|
thrown one.
|
|
1094
1149
|
|
|
1150
|
+
#### The HTTP status belongs to the code
|
|
1151
|
+
|
|
1152
|
+
Every code answers exactly one status, and the status is derived from the code rather than
|
|
1153
|
+
chosen at the throw site — `AuthException` takes no status argument. A client can switch on
|
|
1154
|
+
`error.code` and the status line together and get the same answer from either implementation:
|
|
1155
|
+
`@bymax-one/nest-auth` and `rust-auth` read the same table, pinned in
|
|
1156
|
+
[`conformance/wire-contract.json`](./conformance/wire-contract.json) under
|
|
1157
|
+
`errorCatalog.statuses` and asserted by both suites against that file.
|
|
1158
|
+
|
|
1159
|
+
| Status | Codes |
|
|
1160
|
+
| -----: | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
1161
|
+
| `400` | `auth.validation` · `auth.password_compromised` · `auth.password_reset_token_invalid` · `auth.email_change_token_invalid` · `auth.invalid_invitation_token` · `auth.mfa_not_enabled` · `auth.mfa_setup_required` |
|
|
1162
|
+
| `401` | `auth.invalid_credentials` · `auth.token_invalid` · `auth.refresh_token_invalid` · `auth.mfa_invalid_code` · `auth.mfa_temp_token_invalid` · `auth.otp_invalid` · `auth.oauth_failed` · `auth.platform_auth_required` |
|
|
1163
|
+
| `403` | `auth.account_inactive` · `auth.account_suspended` · `auth.account_banned` · `auth.pending_approval` · `auth.email_not_verified` · `auth.mfa_required` · `auth.insufficient_role` · `auth.forbidden` · `auth.untrusted_origin` · `auth.reauthentication_required` |
|
|
1164
|
+
| `404` | `auth.session_not_found` |
|
|
1165
|
+
| `409` | `auth.email_already_exists` · `auth.mfa_already_enabled` · `auth.mfa_state_conflict` · `auth.oauth_email_mismatch` |
|
|
1166
|
+
| `429` | `auth.account_locked` · `auth.too_many_requests` |
|
|
1167
|
+
| `500` | `auth.internal` |
|
|
1168
|
+
|
|
1169
|
+
`AUTH_ERROR_STATUS` is exported if you need the mapping at runtime — for a typed client, an
|
|
1170
|
+
API document, or a test that asserts against it.
|
|
1171
|
+
|
|
1172
|
+
> **Anti-enumeration reads through the status too.** `POST /forgot-password` answers `200` and
|
|
1173
|
+
> `POST /verify-email` / the resend endpoints answer `204` **whether or not the address exists**.
|
|
1174
|
+
> A `200` there does not mean an email was sent, and treating it as confirmation re-introduces
|
|
1175
|
+
> the account enumeration the endpoints exist to prevent. For the same reason the OTP failures
|
|
1176
|
+
> collapse: a wrong code, a record that expired, and an exhausted attempt ceiling are one code
|
|
1177
|
+
> (`auth.otp_invalid`) at one status (`401`) — a `429` on the ceiling would say the address was
|
|
1178
|
+
> registered, since only a record that exists can reach one.
|
|
1179
|
+
|
|
1095
1180
|
### Server Decorators
|
|
1096
1181
|
|
|
1097
1182
|
| Decorator | Usage |
|