@molecule/api-resource-user 1.5.6 → 1.6.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/README.md +128 -17
- package/dist/authorization.d.ts +64 -6
- package/dist/authorization.d.ts.map +1 -1
- package/dist/authorization.js +129 -17
- package/dist/authorization.js.map +1 -1
- package/dist/handlers/readSelf.d.ts +8 -1
- package/dist/handlers/readSelf.d.ts.map +1 -1
- package/dist/handlers/readSelf.js +15 -1
- package/dist/handlers/readSelf.js.map +1 -1
- package/dist/handlers/updatePassword.d.ts +11 -2
- package/dist/handlers/updatePassword.d.ts.map +1 -1
- package/dist/handlers/updatePassword.js +23 -5
- package/dist/handlers/updatePassword.js.map +1 -1
- package/dist/index.d.ts +38 -13
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +38 -13
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
- /package/{setup → src/__setup__}/users.sql +0 -0
- /package/{setup → src/__setup__}/usersSecrets.sql +0 -0
package/README.md
CHANGED
|
@@ -3,7 +3,7 @@ AUTO-GENERATED — DO NOT EDIT THIS FILE.
|
|
|
3
3
|
Generated by `mlcl sync-docs` from the package's src/index.ts JSDoc + mlcl/registry.json.
|
|
4
4
|
Edits here are overwritten on the next commit (molecule's pre-commit hook regenerates).
|
|
5
5
|
To change this document, edit the module-level JSDoc in src/index.ts.
|
|
6
|
-
Generated: 2026-10-
|
|
6
|
+
Generated: 2026-10-18T14:55:46.698Z
|
|
7
7
|
-->
|
|
8
8
|
|
|
9
9
|
# @molecule/api-resource-user
|
|
@@ -18,20 +18,19 @@ The `user` resource types, schema, and definition.
|
|
|
18
18
|
- `usersSecrets` — {@link SecretProps}: `passwordHash`, `passwordResetToken` (and
|
|
19
19
|
`passwordResetTokenAt`), `twoFactorSecret` / `pendingTwoFactorSecret`, `lastTwoFactorTimeStep`.
|
|
20
20
|
|
|
21
|
+
**Table setup:** `src/__setup__/users.sql` + `src/__setup__/usersSecrets.sql`; an mlcl-scaffolded API replays `__setup__/*.sql` on migrate.
|
|
22
|
+
|
|
21
23
|
**`usersSecrets.id` IS the user's id — the value of `users.id`, never a fresh uuid.** The DDL
|
|
22
|
-
declares it `UNIQUE PRIMARY KEY` with no foreign key, so nothing enforces
|
|
23
|
-
|
|
24
|
-
`GET /api/users/me`
|
|
25
|
-
both rows from one id:
|
|
24
|
+
declares it `UNIQUE PRIMARY KEY` with no foreign key, so nothing enforces it: a row written
|
|
25
|
+
under another id is never found again — login answers "invalid credentials" while
|
|
26
|
+
`GET /api/users/me` still answers 200. A hand-written signup writes both rows:
|
|
26
27
|
`const id = uuid(); await create('users', { ...props, id }); await create('usersSecrets', { id, passwordHash: await hash(password) })`.
|
|
27
28
|
|
|
28
|
-
Prefer not to hand-write
|
|
29
|
-
`handlers.
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
same key — `findById('usersSecrets', userId)`, or `${tableName}Secrets` when the resource
|
|
34
|
-
carries a custom `tableName` — never SQL.
|
|
29
|
+
Prefer not to hand-write that — `handlers.create` (signup: both rows, hash via
|
|
30
|
+
`@molecule/api-password`, session device), `handlers.logIn` (reads `usersSecrets` by the user's
|
|
31
|
+
id), `handlers.updatePassword`, `handlers.forgotPassword` / `handlers.resetPassword`. To touch
|
|
32
|
+
one secret yourself use the datastore on the same key — `findById('usersSecrets', userId)` (or
|
|
33
|
+
`${tableName}Secrets` for a custom `tableName`) — never SQL.
|
|
35
34
|
|
|
36
35
|
**Issuing a session yourself (the sequence is device, then session — two calls, and the first
|
|
37
36
|
RETURNS the id):** the middleware accepts both `Authorization: Bearer <jwt>` and
|
|
@@ -51,8 +50,14 @@ const token = authorization.set(req, res, { userId, deviceId })
|
|
|
51
50
|
`get<DeviceService>('device')` is the typed accessor (never hand-type a
|
|
52
51
|
`get<{ createOrUpdate(): … }>('device')` generic: a wrong one still compiles and leaves the
|
|
53
52
|
field you invented — `device.id` — `undefined`), and `createOrUpdate` RESOLVES TO THE DEVICE ID
|
|
54
|
-
STRING, not to a row. `
|
|
55
|
-
|
|
53
|
+
STRING, not to a row. `set()` throws when `deviceId` is missing rather than mint a token every
|
|
54
|
+
later request answers 401.
|
|
55
|
+
|
|
56
|
+
**RealWorld-style token API (`Authorization: Token <jwt>`)? CONFIGURATION on this same auth
|
|
57
|
+
path — never a credentials table of your own** (`usersSecrets.passwordHash` is the password
|
|
58
|
+
store). Set `AUTH_SCHEME=Token` (or `verifyMiddleware({ scheme: 'Token' })`): every route
|
|
59
|
+
accepts it, `logIn`/`create` return `accessToken`, `GET /users/me` echoes it, and a password
|
|
60
|
+
change revokes every OTHER device but keeps the caller's own session.
|
|
56
61
|
|
|
57
62
|
**`handlers.*` return `{ statusCode, headers?, body }` and never write to `res`** — not through
|
|
58
63
|
`res.json`, not through `res.send`, not through `res.end`. The mounted routes apply that object
|
|
@@ -633,6 +638,59 @@ function getAuthCookieOptions(): {
|
|
|
633
638
|
|
|
634
639
|
**Returns:** The environment-appropriate base cookie options.
|
|
635
640
|
|
|
641
|
+
##### `authorization.DEFAULT_AUTH_SCHEME`
|
|
642
|
+
|
|
643
|
+
The `Authorization` scheme this resource uses when nothing configures another
|
|
644
|
+
one — the scheme {@link set} writes into the response header.
|
|
645
|
+
|
|
646
|
+
```typescript
|
|
647
|
+
const DEFAULT_AUTH_SCHEME: 'Bearer'
|
|
648
|
+
```
|
|
649
|
+
|
|
650
|
+
##### `authorization.AUTH_SCHEME_LOCALS_KEY`
|
|
651
|
+
|
|
652
|
+
`res.locals` key carrying the `Authorization` scheme THIS request's mount uses:
|
|
653
|
+
`'Bearer'` by default, `'Token'` for a Django REST Framework / RealWorld-style
|
|
654
|
+
API. {@link verifyMiddleware} records it from its `scheme` option (or the app's
|
|
655
|
+
`AUTH_SCHEME`), and {@link set} reads it so a sign-in response labels its token
|
|
656
|
+
with the SAME scheme the client will send back. A `set()` call outside a request
|
|
657
|
+
(a handler invoked directly) falls back to `AUTH_SCHEME`, then to `Bearer`.
|
|
658
|
+
|
|
659
|
+
```typescript
|
|
660
|
+
const AUTH_SCHEME_LOCALS_KEY: 'authScheme'
|
|
661
|
+
```
|
|
662
|
+
|
|
663
|
+
##### `authorization.AUTH_TOKEN_LOCALS_KEY`
|
|
664
|
+
|
|
665
|
+
`res.locals` key carrying the raw JWT that authenticated THIS request — written
|
|
666
|
+
ONLY when the request sent it in the `Authorization` header, never when the
|
|
667
|
+
session came from the httpOnly `token` cookie.
|
|
668
|
+
|
|
669
|
+
That asymmetry is deliberate: echoing a cookie-resolved token into a JSON body
|
|
670
|
+
would hand JavaScript the exact credential the cookie exists to keep unreadable
|
|
671
|
+
(an XSS exfiltration path). A header token is already in the client's hands, so
|
|
672
|
+
`GET /users/me` may return it as `accessToken` to a token-only client that
|
|
673
|
+
restores its session from that response.
|
|
674
|
+
|
|
675
|
+
```typescript
|
|
676
|
+
const AUTH_TOKEN_LOCALS_KEY: 'authToken'
|
|
677
|
+
```
|
|
678
|
+
|
|
679
|
+
##### `authorization.getConfiguredAuthScheme()`
|
|
680
|
+
|
|
681
|
+
The app's configured `Authorization` scheme: `AUTH_SCHEME` from the environment,
|
|
682
|
+
defaulting to {@link DEFAULT_AUTH_SCHEME}.
|
|
683
|
+
|
|
684
|
+
Read at call time (not module load) so a process — or a test — that changes the
|
|
685
|
+
env sees the new value. A session-only app that never sets `AUTH_SCHEME` keeps
|
|
686
|
+
emitting `Bearer`.
|
|
687
|
+
|
|
688
|
+
```typescript
|
|
689
|
+
function getConfiguredAuthScheme(): string
|
|
690
|
+
```
|
|
691
|
+
|
|
692
|
+
**Returns:** A validated scheme name.
|
|
693
|
+
|
|
636
694
|
##### `authorization.invalidateDeviceExistsCache(deviceId)`
|
|
637
695
|
|
|
638
696
|
Evict a single device's positive entry from the device-exists cache so the
|
|
@@ -788,19 +846,35 @@ interface VerifyMiddlewareOptions {
|
|
|
788
846
|
* "no auth".
|
|
789
847
|
*/
|
|
790
848
|
allowCookieSession?: boolean
|
|
849
|
+
/**
|
|
850
|
+
* The `Authorization` scheme this mount accepts and mints: `'Bearer'` (default), or
|
|
851
|
+
* `'Token'` for a Django REST Framework / RealWorld-style API. Defaults to the app's
|
|
852
|
+
* `AUTH_SCHEME` environment value.
|
|
853
|
+
*
|
|
854
|
+
* This is a LABEL, not a second auth mechanism: every route the mount covers accepts the
|
|
855
|
+
* same verifiable JWT, whether it arrives as `Bearer <jwt>` or `Token <jwt>` (both stay
|
|
856
|
+
* accepted). The option decides what {@link set} writes into the sign-in response header
|
|
857
|
+
* — and therefore what the client sends back and what its HTTP client must be configured
|
|
858
|
+
* with (`createFetchClient({ baseURL, authScheme: 'Token' })`).
|
|
859
|
+
*/
|
|
860
|
+
scheme?: string
|
|
791
861
|
}
|
|
792
862
|
```
|
|
793
863
|
|
|
794
864
|
##### `authorization.verifyMiddleware(options)`
|
|
795
865
|
|
|
796
866
|
Middleware that verifies the JWT token from the `Authorization` header and sets `res.locals.session`.
|
|
797
|
-
|
|
867
|
+
Accepts `Bearer` and `Token` (Django REST / RealWorld) plus the configured scheme, on EVERY
|
|
868
|
+
route the mount covers. Falls back to cookie-based session for browser clients unless
|
|
869
|
+
`allowCookieSession` is `false` — which also stops `set()` writing the session cookie for this
|
|
870
|
+
request. Records the scheme for `set()` and, when the token came from the header, records the
|
|
871
|
+
raw token in `res.locals[AUTH_TOKEN_LOCALS_KEY]`. Auto-refreshes tokens older than `JWT_REFRESH_TIME`.
|
|
798
872
|
|
|
799
873
|
```typescript
|
|
800
874
|
function verifyMiddleware(options?: VerifyMiddlewareOptions): MoleculeRequestHandler
|
|
801
875
|
```
|
|
802
876
|
|
|
803
|
-
- `options` — {@link VerifyMiddlewareOptions} controlling the auto-refresh.
|
|
877
|
+
- `options` — {@link VerifyMiddlewareOptions} controlling the auto-refresh, cookie policy and scheme.
|
|
804
878
|
|
|
805
879
|
**Returns:** An Express-compatible middleware function.
|
|
806
880
|
|
|
@@ -1418,6 +1492,13 @@ so the client can re-establish `authenticated` state WITHOUT the token ever
|
|
|
1418
1492
|
being exposed to JavaScript. Always self, so it mirrors `read`'s self branch
|
|
1419
1493
|
(plan + two-factor status).
|
|
1420
1494
|
|
|
1495
|
+
**Token-only clients get the token back as `accessToken`.** When the request
|
|
1496
|
+
authenticated with an `Authorization` header (any accepted scheme — `Bearer` or
|
|
1497
|
+
`Token`), the middleware records that raw JWT and this response echoes it, so a
|
|
1498
|
+
RealWorld-style client can restore `{ user, token }` from `GET /user` the same way
|
|
1499
|
+
login and registration return it. A session resolved from the httpOnly cookie
|
|
1500
|
+
NEVER gets this field: exposing that token to JavaScript would defeat the cookie.
|
|
1501
|
+
|
|
1421
1502
|
```typescript
|
|
1422
1503
|
function readSelf({
|
|
1423
1504
|
tableName,
|
|
@@ -1430,7 +1511,7 @@ function readSelf({
|
|
|
1430
1511
|
- `resource` — The user resource configuration (name, tableName, schema).
|
|
1431
1512
|
- `resource.tableName` — The database table name for users.
|
|
1432
1513
|
|
|
1433
|
-
**Returns:** A request handler responding `{ statusCode: 200, body: { props, plan?, twoFactorEnabled? } }`, or 401 when unauthenticated.
|
|
1514
|
+
**Returns:** A request handler responding `{ statusCode: 200, body: { props, plan?, twoFactorEnabled?, accessToken? } }`, or 401 when unauthenticated.
|
|
1434
1515
|
|
|
1435
1516
|
##### `handlers.RESET_TOKEN_TTL_MS`
|
|
1436
1517
|
|
|
@@ -1541,6 +1622,15 @@ Updates a user's password. If the user already has a password hash, the current
|
|
|
1541
1622
|
must be provided and verified first. The new password is hashed via `@molecule/api-password`
|
|
1542
1623
|
and stored in the secrets table.
|
|
1543
1624
|
|
|
1625
|
+
**Every OTHER session is revoked; the caller's own is kept.** The device rows of all other
|
|
1626
|
+
devices are deleted, so a stolen token on another device dies — but the device this request
|
|
1627
|
+
arrived on stays, and the token that made the request (the `Authorization` header the client
|
|
1628
|
+
is holding) keeps working. A RealWorld-style suite changes the password and then keeps using
|
|
1629
|
+
the same token for the next request; revoking the caller too is what answered its second
|
|
1630
|
+
`PUT /user` with 401 (xr-flash-m167, ~2 min lost). Do not fold a per-user secret into the
|
|
1631
|
+
JWT: the device row is the revocation lever. A caller with no session (a handler invoked
|
|
1632
|
+
outside a request) falls back to revoking every device.
|
|
1633
|
+
|
|
1544
1634
|
```typescript
|
|
1545
1635
|
function updatePassword({
|
|
1546
1636
|
name: _name,
|
|
@@ -1548,6 +1638,7 @@ function updatePassword({
|
|
|
1548
1638
|
schema: _schema,
|
|
1549
1639
|
}: types.Resource<unknown>): (
|
|
1550
1640
|
req: UpdatePasswordRequest,
|
|
1641
|
+
res?: MoleculeResponse,
|
|
1551
1642
|
) => Promise<
|
|
1552
1643
|
| { statusCode: number; body: { error: string; errorKey: string; success?: undefined } }
|
|
1553
1644
|
| { statusCode: number; body: { success: boolean; error?: undefined; errorKey?: undefined } }
|
|
@@ -2060,6 +2151,26 @@ check for a SECOND one: a request can pass several mounts (`api/src/server.ts`'s
|
|
|
2060
2151
|
passes sets the policy both halves read, and a laxer mount later in the chain cannot
|
|
2061
2152
|
re-admit the cookie. If the app mounts two, mount it once instead.
|
|
2062
2153
|
|
|
2154
|
+
**The RealWorld token recipe (detail).** The scheme is configuration, not a second auth
|
|
2155
|
+
layer: `AUTH_SCHEME=Token` in the API's env, or `verifyMiddleware({ scheme: 'Token',
|
|
2156
|
+
allowCookieSession: false })` at the mount, makes every covered route accept
|
|
2157
|
+
`Authorization: Token <jwt>` (`Bearer` stays accepted too) and labels the sign-in response
|
|
2158
|
+
header with that scheme. The token is already in the body — `handlers.logIn` and
|
|
2159
|
+
`handlers.create` return `{ props, accessToken, user }`, and `GET /users/me` adds
|
|
2160
|
+
`accessToken` when the request authenticated with the header (never for a cookie-resolved
|
|
2161
|
+
session: that token must stay unreadable to JavaScript).
|
|
2162
|
+
|
|
2163
|
+
```typescript
|
|
2164
|
+
// Token-only API that speaks RealWorld's scheme.
|
|
2165
|
+
router.use(verifyMiddleware({ scheme: 'Token', allowCookieSession: false }))
|
|
2166
|
+
// POST /users and POST /users/log-in answer { props, accessToken, user };
|
|
2167
|
+
// clients send `Authorization: Token <accessToken>` from then on.
|
|
2168
|
+
```
|
|
2169
|
+
|
|
2170
|
+
The CLIENT labels its header the same way: `authScheme: 'Token'` is an option of the HTTP
|
|
2171
|
+
client's CONSTRUCTOR (`createFetchClient({ baseURL, authScheme: 'Token' })`, or the axios
|
|
2172
|
+
provider's `createAxiosClient`), never a property of `getClient()`'s result.
|
|
2173
|
+
|
|
2063
2174
|
**Revoking a session yourself:** the middleware caches "this device exists" for 10 s per
|
|
2064
2175
|
process, so a hand-written logout that deletes the `devices` row keeps authorizing that
|
|
2065
2176
|
token until the cache expires — a check right after logout still answers 200. Call
|
package/dist/authorization.d.ts
CHANGED
|
@@ -66,6 +66,43 @@ export declare const getAuthCookieOptions: () => {
|
|
|
66
66
|
partitioned?: boolean;
|
|
67
67
|
path: string;
|
|
68
68
|
};
|
|
69
|
+
/**
|
|
70
|
+
* The `Authorization` scheme this resource uses when nothing configures another
|
|
71
|
+
* one — the scheme {@link set} writes into the response header.
|
|
72
|
+
*/
|
|
73
|
+
export declare const DEFAULT_AUTH_SCHEME = "Bearer";
|
|
74
|
+
/**
|
|
75
|
+
* `res.locals` key carrying the `Authorization` scheme THIS request's mount uses:
|
|
76
|
+
* `'Bearer'` by default, `'Token'` for a Django REST Framework / RealWorld-style
|
|
77
|
+
* API. {@link verifyMiddleware} records it from its `scheme` option (or the app's
|
|
78
|
+
* `AUTH_SCHEME`), and {@link set} reads it so a sign-in response labels its token
|
|
79
|
+
* with the SAME scheme the client will send back. A `set()` call outside a request
|
|
80
|
+
* (a handler invoked directly) falls back to `AUTH_SCHEME`, then to `Bearer`.
|
|
81
|
+
*/
|
|
82
|
+
export declare const AUTH_SCHEME_LOCALS_KEY = "authScheme";
|
|
83
|
+
/**
|
|
84
|
+
* `res.locals` key carrying the raw JWT that authenticated THIS request — written
|
|
85
|
+
* ONLY when the request sent it in the `Authorization` header, never when the
|
|
86
|
+
* session came from the httpOnly `token` cookie.
|
|
87
|
+
*
|
|
88
|
+
* That asymmetry is deliberate: echoing a cookie-resolved token into a JSON body
|
|
89
|
+
* would hand JavaScript the exact credential the cookie exists to keep unreadable
|
|
90
|
+
* (an XSS exfiltration path). A header token is already in the client's hands, so
|
|
91
|
+
* `GET /users/me` may return it as `accessToken` to a token-only client that
|
|
92
|
+
* restores its session from that response.
|
|
93
|
+
*/
|
|
94
|
+
export declare const AUTH_TOKEN_LOCALS_KEY = "authToken";
|
|
95
|
+
/**
|
|
96
|
+
* The app's configured `Authorization` scheme: `AUTH_SCHEME` from the environment,
|
|
97
|
+
* defaulting to {@link DEFAULT_AUTH_SCHEME}.
|
|
98
|
+
*
|
|
99
|
+
* Read at call time (not module load) so a process — or a test — that changes the
|
|
100
|
+
* env sees the new value. A session-only app that never sets `AUTH_SCHEME` keeps
|
|
101
|
+
* emitting `Bearer`.
|
|
102
|
+
*
|
|
103
|
+
* @returns A validated scheme name.
|
|
104
|
+
*/
|
|
105
|
+
export declare const getConfiguredAuthScheme: () => string;
|
|
69
106
|
/**
|
|
70
107
|
* Evict a single device's positive entry from the device-exists cache so the
|
|
71
108
|
* next authorization check for that device re-consults the database.
|
|
@@ -144,13 +181,18 @@ export type AuthSessionSource = 'header' | 'cookie';
|
|
|
144
181
|
* (`'unknown'`, `''`, the user's id) yields a token that every later request answers 401.
|
|
145
182
|
*
|
|
146
183
|
* To put a session token in a JSON response BODY — an API whose clients send
|
|
147
|
-
* `Authorization: Token <jwt>` — call this and use its return value
|
|
184
|
+
* `Authorization: Token <jwt>` — call this and use its return value; the shipped `logIn` and
|
|
185
|
+
* `create` handlers already return it as `accessToken`. Do NOT sign a
|
|
148
186
|
* second token with another key or algorithm: `verifyMiddleware` verifies with the app's
|
|
149
187
|
* bonded `@molecule/api-jwt` provider, so a self-signed one answers 401 on the very next
|
|
150
|
-
* request. Mount `verifyMiddleware({ allowCookieSession: false })` in front
|
|
151
|
-
* that sign users in and the client gets the token
|
|
188
|
+
* request. Mount `verifyMiddleware({ allowCookieSession: false, scheme: 'Token' })` in front
|
|
189
|
+
* of the routes that sign users in and the client gets the token in that scheme with no
|
|
190
|
+
* session cookie. (`AUTH_SCHEME=Token` in the app's environment does the same for every
|
|
191
|
+
* mount — the scheme is configuration, not a second auth path.)
|
|
152
192
|
*
|
|
153
|
-
* Always sets the `Authorization` response header
|
|
193
|
+
* Always sets the `Authorization` response header — labelled with the request mount's scheme
|
|
194
|
+
* (`Bearer` by default, `Token` for a RealWorld-style API; see {@link AUTH_SCHEME_LOCALS_KEY}
|
|
195
|
+
* and `AUTH_SCHEME`). Writes the session cookies (the httpOnly
|
|
154
196
|
* `token` and `sessionId`, plus the readable `mol_auth` presence hint) UNLESS the request's
|
|
155
197
|
* cookie-session policy is off — see {@link ALLOW_COOKIE_SESSION_LOCALS_KEY}, written by
|
|
156
198
|
* {@link verifyMiddleware}. A token-only API (`allowCookieSession: false`) gets the header
|
|
@@ -200,11 +242,27 @@ export interface VerifyMiddlewareOptions {
|
|
|
200
242
|
* "no auth".
|
|
201
243
|
*/
|
|
202
244
|
allowCookieSession?: boolean;
|
|
245
|
+
/**
|
|
246
|
+
* The `Authorization` scheme this mount accepts and mints: `'Bearer'` (default), or
|
|
247
|
+
* `'Token'` for a Django REST Framework / RealWorld-style API. Defaults to the app's
|
|
248
|
+
* `AUTH_SCHEME` environment value.
|
|
249
|
+
*
|
|
250
|
+
* This is a LABEL, not a second auth mechanism: every route the mount covers accepts the
|
|
251
|
+
* same verifiable JWT, whether it arrives as `Bearer <jwt>` or `Token <jwt>` (both stay
|
|
252
|
+
* accepted). The option decides what {@link set} writes into the sign-in response header
|
|
253
|
+
* — and therefore what the client sends back and what its HTTP client must be configured
|
|
254
|
+
* with (`createFetchClient({ baseURL, authScheme: 'Token' })`).
|
|
255
|
+
*/
|
|
256
|
+
scheme?: string;
|
|
203
257
|
}
|
|
204
258
|
/**
|
|
205
259
|
* Middleware that verifies the JWT token from the `Authorization` header and sets `res.locals.session`.
|
|
206
|
-
*
|
|
207
|
-
*
|
|
260
|
+
* Accepts `Bearer` and `Token` (Django REST / RealWorld) plus the configured scheme, on EVERY
|
|
261
|
+
* route the mount covers. Falls back to cookie-based session for browser clients unless
|
|
262
|
+
* `allowCookieSession` is `false` — which also stops `set()` writing the session cookie for this
|
|
263
|
+
* request. Records the scheme for `set()` and, when the token came from the header, records the
|
|
264
|
+
* raw token in `res.locals[AUTH_TOKEN_LOCALS_KEY]`. Auto-refreshes tokens older than `JWT_REFRESH_TIME`.
|
|
265
|
+
* @param options - {@link VerifyMiddlewareOptions} controlling the auto-refresh, cookie policy and scheme.
|
|
208
266
|
* @returns An Express-compatible middleware function.
|
|
209
267
|
*/
|
|
210
268
|
export declare const verifyMiddleware: (options?: VerifyMiddlewareOptions) => MoleculeRequestHandler;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"authorization.d.ts","sourceRoot":"","sources":["../src/authorization.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAKH,OAAO,cAAc,CAAA;AAMrB,OAAO,KAAK,EACV,eAAe,EACf,sBAAsB,EACtB,gBAAgB,EACjB,MAAM,wBAAwB,CAAA;AAE/B,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,aAAa,CAAA;AAwB1C;;;;;;;;;;;;;;;;;;GAkBG;AACH,eAAO,MAAM,iBAAiB,GAAI,MAAM,MAAM,KAAG,MACP,CAAA;AA4B1C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACH,eAAO,MAAM,oBAAoB,QAAO;IACtC,MAAM,EAAE,OAAO,CAAA;IACf,QAAQ,EAAE,KAAK,GAAG,MAAM,CAAA;IACxB,WAAW,CAAC,EAAE,OAAO,CAAA;IACrB,IAAI,EAAE,MAAM,CAAA;CAQb,CAAA;
|
|
1
|
+
{"version":3,"file":"authorization.d.ts","sourceRoot":"","sources":["../src/authorization.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAKH,OAAO,cAAc,CAAA;AAMrB,OAAO,KAAK,EACV,eAAe,EACf,sBAA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C,MAAM,WAAW,uBAAuB;IACtC;;;;;;;;;;;;;OAaG;IACH,oBAAoB,CAAC,EAAE,CAAC,OAAO,EAAE,OAAO,EAAE,GAAG,EAAE,eAAe,KAAK,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,CAAA;IAC7F;;;;;;;;;;;OAWG;IACH,kBAAkB,CAAC,EAAE,OAAO,CAAA;IAC5B;;;;;;;;;;OAUG;IACH,MAAM,CAAC,EAAE,MAAM,CAAA;CAChB;AAED;;;;;;;;;GASG;AACH,eAAO,MAAM,gBAAgB,GAC1B,UAAU,uBAAuB,KAAG,sBAyHpC,CAAA"}
|
package/dist/authorization.js
CHANGED
|
@@ -141,6 +141,96 @@ const readAuthCookie = (cookies, base) => {
|
|
|
141
141
|
return primary;
|
|
142
142
|
return primary ?? cookies?.[base];
|
|
143
143
|
};
|
|
144
|
+
/**
|
|
145
|
+
* The `Authorization` scheme this resource uses when nothing configures another
|
|
146
|
+
* one — the scheme {@link set} writes into the response header.
|
|
147
|
+
*/
|
|
148
|
+
export const DEFAULT_AUTH_SCHEME = 'Bearer';
|
|
149
|
+
/**
|
|
150
|
+
* `res.locals` key carrying the `Authorization` scheme THIS request's mount uses:
|
|
151
|
+
* `'Bearer'` by default, `'Token'` for a Django REST Framework / RealWorld-style
|
|
152
|
+
* API. {@link verifyMiddleware} records it from its `scheme` option (or the app's
|
|
153
|
+
* `AUTH_SCHEME`), and {@link set} reads it so a sign-in response labels its token
|
|
154
|
+
* with the SAME scheme the client will send back. A `set()` call outside a request
|
|
155
|
+
* (a handler invoked directly) falls back to `AUTH_SCHEME`, then to `Bearer`.
|
|
156
|
+
*/
|
|
157
|
+
export const AUTH_SCHEME_LOCALS_KEY = 'authScheme';
|
|
158
|
+
/**
|
|
159
|
+
* `res.locals` key carrying the raw JWT that authenticated THIS request — written
|
|
160
|
+
* ONLY when the request sent it in the `Authorization` header, never when the
|
|
161
|
+
* session came from the httpOnly `token` cookie.
|
|
162
|
+
*
|
|
163
|
+
* That asymmetry is deliberate: echoing a cookie-resolved token into a JSON body
|
|
164
|
+
* would hand JavaScript the exact credential the cookie exists to keep unreadable
|
|
165
|
+
* (an XSS exfiltration path). A header token is already in the client's hands, so
|
|
166
|
+
* `GET /users/me` may return it as `accessToken` to a token-only client that
|
|
167
|
+
* restores its session from that response.
|
|
168
|
+
*/
|
|
169
|
+
export const AUTH_TOKEN_LOCALS_KEY = 'authToken';
|
|
170
|
+
/** RFC 7235 `token` production — the only shape an `Authorization` scheme may take. */
|
|
171
|
+
const AUTH_SCHEME_RE = /^[!#$%&'*+\-.^_`|~0-9A-Za-z]+$/;
|
|
172
|
+
/**
|
|
173
|
+
* Schemes {@link verifyMiddleware} always accepts, whatever the app configures:
|
|
174
|
+
* `Bearer` (the HTTP default) and `Token` (Django REST Framework / the RealWorld
|
|
175
|
+
* spec). The scheme is a label, not a credential — the JWT's signature is what
|
|
176
|
+
* authenticates the request — so accepting the historical pair never weakens auth
|
|
177
|
+
* and keeps a client working when the app starts advertising `Token`.
|
|
178
|
+
*/
|
|
179
|
+
const BASE_AUTH_SCHEMES = ['bearer', 'token'];
|
|
180
|
+
/**
|
|
181
|
+
* Validate an `Authorization` scheme name, warning once about a bad value instead
|
|
182
|
+
* of emitting `Authorization: <garbage> <jwt>` (which every client would refuse)
|
|
183
|
+
* or letting a header-injecting value through.
|
|
184
|
+
*
|
|
185
|
+
* @param raw - The candidate scheme (`AUTH_SCHEME` or the mount's `scheme` option).
|
|
186
|
+
* @param source - What supplied it, for the warning text.
|
|
187
|
+
* @returns The scheme when it is a valid RFC 7235 token, else {@link DEFAULT_AUTH_SCHEME}.
|
|
188
|
+
*/
|
|
189
|
+
const normalizeAuthScheme = (raw, source) => {
|
|
190
|
+
const scheme = typeof raw === 'string' ? raw.trim() : '';
|
|
191
|
+
if (!scheme)
|
|
192
|
+
return DEFAULT_AUTH_SCHEME;
|
|
193
|
+
if (!AUTH_SCHEME_RE.test(scheme)) {
|
|
194
|
+
logger.warn(`${source} is set to ${JSON.stringify(scheme)}, which is not a valid Authorization scheme ` +
|
|
195
|
+
`(one RFC 7235 token, e.g. "Bearer" or "Token"). Falling back to "${DEFAULT_AUTH_SCHEME}".`);
|
|
196
|
+
return DEFAULT_AUTH_SCHEME;
|
|
197
|
+
}
|
|
198
|
+
return scheme;
|
|
199
|
+
};
|
|
200
|
+
/** Memo of the last `AUTH_SCHEME` value read, so a bad value warns once, not per request. */
|
|
201
|
+
let cachedConfiguredScheme;
|
|
202
|
+
/**
|
|
203
|
+
* The app's configured `Authorization` scheme: `AUTH_SCHEME` from the environment,
|
|
204
|
+
* defaulting to {@link DEFAULT_AUTH_SCHEME}.
|
|
205
|
+
*
|
|
206
|
+
* Read at call time (not module load) so a process — or a test — that changes the
|
|
207
|
+
* env sees the new value. A session-only app that never sets `AUTH_SCHEME` keeps
|
|
208
|
+
* emitting `Bearer`.
|
|
209
|
+
*
|
|
210
|
+
* @returns A validated scheme name.
|
|
211
|
+
*/
|
|
212
|
+
export const getConfiguredAuthScheme = () => {
|
|
213
|
+
const raw = process.env.AUTH_SCHEME;
|
|
214
|
+
if (cachedConfiguredScheme !== undefined && cachedConfiguredScheme.raw === raw) {
|
|
215
|
+
return cachedConfiguredScheme.scheme;
|
|
216
|
+
}
|
|
217
|
+
const scheme = normalizeAuthScheme(raw, 'AUTH_SCHEME');
|
|
218
|
+
cachedConfiguredScheme = { raw, scheme };
|
|
219
|
+
return scheme;
|
|
220
|
+
};
|
|
221
|
+
/**
|
|
222
|
+
* The scheme for THIS response: what its mount recorded, else the app's configured
|
|
223
|
+
* scheme, else {@link DEFAULT_AUTH_SCHEME}.
|
|
224
|
+
*
|
|
225
|
+
* @param res - The response object.
|
|
226
|
+
* @returns A validated scheme name.
|
|
227
|
+
*/
|
|
228
|
+
const resolveAuthScheme = (res) => {
|
|
229
|
+
const recorded = res.locals?.[AUTH_SCHEME_LOCALS_KEY];
|
|
230
|
+
return typeof recorded === 'string' && AUTH_SCHEME_RE.test(recorded)
|
|
231
|
+
? recorded
|
|
232
|
+
: getConfiguredAuthScheme();
|
|
233
|
+
};
|
|
144
234
|
/**
|
|
145
235
|
* Short-TTL positive cache for "device still exists" lookups, to bound the
|
|
146
236
|
* per-request DB cost of server-side session-revocation enforcement.
|
|
@@ -307,13 +397,18 @@ const maySetSessionCookie = (res) => res.locals?.[ALLOW_COOKIE_SESSION_LOCALS_KE
|
|
|
307
397
|
* (`'unknown'`, `''`, the user's id) yields a token that every later request answers 401.
|
|
308
398
|
*
|
|
309
399
|
* To put a session token in a JSON response BODY — an API whose clients send
|
|
310
|
-
* `Authorization: Token <jwt>` — call this and use its return value
|
|
400
|
+
* `Authorization: Token <jwt>` — call this and use its return value; the shipped `logIn` and
|
|
401
|
+
* `create` handlers already return it as `accessToken`. Do NOT sign a
|
|
311
402
|
* second token with another key or algorithm: `verifyMiddleware` verifies with the app's
|
|
312
403
|
* bonded `@molecule/api-jwt` provider, so a self-signed one answers 401 on the very next
|
|
313
|
-
* request. Mount `verifyMiddleware({ allowCookieSession: false })` in front
|
|
314
|
-
* that sign users in and the client gets the token
|
|
404
|
+
* request. Mount `verifyMiddleware({ allowCookieSession: false, scheme: 'Token' })` in front
|
|
405
|
+
* of the routes that sign users in and the client gets the token in that scheme with no
|
|
406
|
+
* session cookie. (`AUTH_SCHEME=Token` in the app's environment does the same for every
|
|
407
|
+
* mount — the scheme is configuration, not a second auth path.)
|
|
315
408
|
*
|
|
316
|
-
* Always sets the `Authorization` response header
|
|
409
|
+
* Always sets the `Authorization` response header — labelled with the request mount's scheme
|
|
410
|
+
* (`Bearer` by default, `Token` for a RealWorld-style API; see {@link AUTH_SCHEME_LOCALS_KEY}
|
|
411
|
+
* and `AUTH_SCHEME`). Writes the session cookies (the httpOnly
|
|
317
412
|
* `token` and `sessionId`, plus the readable `mol_auth` presence hint) UNLESS the request's
|
|
318
413
|
* cookie-session policy is off — see {@link ALLOW_COOKIE_SESSION_LOCALS_KEY}, written by
|
|
319
414
|
* {@link verifyMiddleware}. A token-only API (`allowCookieSession: false`) gets the header
|
|
@@ -367,8 +462,10 @@ export const set = (_req, res, session) => {
|
|
|
367
462
|
const token = sign(sessionPayload);
|
|
368
463
|
if (token) {
|
|
369
464
|
// The header is the credential a token-only API's clients read; it is set on
|
|
370
|
-
// every request that mints a token, cookies or not.
|
|
371
|
-
|
|
465
|
+
// every request that mints a token, cookies or not. The scheme is the mount's
|
|
466
|
+
// (`Bearer` by default, `Token` for a RealWorld-style API) so the client can
|
|
467
|
+
// send the token back exactly as it was labelled.
|
|
468
|
+
res.setHeader('Authorization', `${resolveAuthScheme(res)} ${token}`);
|
|
372
469
|
// A request whose cookie policy is OFF gets the header and NOTHING else. The
|
|
373
470
|
// cookie is not a convenience here — it is a second credential the client did
|
|
374
471
|
// not ask for: once written, an HTTP test runner's cookie jar (Hurl, `curl -b`)
|
|
@@ -422,20 +519,26 @@ export const set = (_req, res, session) => {
|
|
|
422
519
|
};
|
|
423
520
|
/**
|
|
424
521
|
* Middleware that verifies the JWT token from the `Authorization` header and sets `res.locals.session`.
|
|
425
|
-
*
|
|
426
|
-
*
|
|
522
|
+
* Accepts `Bearer` and `Token` (Django REST / RealWorld) plus the configured scheme, on EVERY
|
|
523
|
+
* route the mount covers. Falls back to cookie-based session for browser clients unless
|
|
524
|
+
* `allowCookieSession` is `false` — which also stops `set()` writing the session cookie for this
|
|
525
|
+
* request. Records the scheme for `set()` and, when the token came from the header, records the
|
|
526
|
+
* raw token in `res.locals[AUTH_TOKEN_LOCALS_KEY]`. Auto-refreshes tokens older than `JWT_REFRESH_TIME`.
|
|
527
|
+
* @param options - {@link VerifyMiddlewareOptions} controlling the auto-refresh, cookie policy and scheme.
|
|
427
528
|
* @returns An Express-compatible middleware function.
|
|
428
529
|
*/
|
|
429
530
|
export const verifyMiddleware = (options) => async (req, res, next) => {
|
|
430
531
|
try {
|
|
431
|
-
// Record THIS mount's cookie policy for the rest of the request,
|
|
432
|
-
// early return: `set()` reads
|
|
433
|
-
// sign-in response on
|
|
434
|
-
//
|
|
435
|
-
//
|
|
436
|
-
// token lookup below.
|
|
532
|
+
// Record THIS mount's cookie policy and scheme for the rest of the request,
|
|
533
|
+
// before any early return: `set()` reads both (so a token-only API writes no
|
|
534
|
+
// cookie from the sign-in response on, and labels its token with this mount's
|
|
535
|
+
// scheme) and a later, stricter mount reads it to know it may strip a session
|
|
536
|
+
// an earlier one resolved out of the cookie. The sign-in request itself carries
|
|
537
|
+
// no token, so the write cannot sit behind the token lookup below.
|
|
437
538
|
const allowCookieSession = options?.allowCookieSession !== false;
|
|
438
539
|
res.locals[ALLOW_COOKIE_SESSION_LOCALS_KEY] = allowCookieSession;
|
|
540
|
+
const scheme = normalizeAuthScheme(options?.scheme ?? getConfiguredAuthScheme(), options?.scheme === undefined ? 'AUTH_SCHEME' : 'verifyMiddleware({ scheme })');
|
|
541
|
+
res.locals[AUTH_SCHEME_LOCALS_KEY] = scheme;
|
|
439
542
|
// Get token from Authorization header, falling back to the `token`
|
|
440
543
|
// cookie that `set()` writes alongside the header. The JSDoc above
|
|
441
544
|
// promises this fallback for browser clients; without it the cookie
|
|
@@ -445,9 +548,12 @@ export const verifyMiddleware = (options) => async (req, res, next) => {
|
|
|
445
548
|
// never trusted (no decode-fallback bypass).
|
|
446
549
|
const rawAuth = req.headers.authorization;
|
|
447
550
|
const authHeader = Array.isArray(rawAuth) ? rawAuth[0] : rawAuth;
|
|
448
|
-
//
|
|
449
|
-
// the RealWorld spec use)
|
|
450
|
-
|
|
551
|
+
// `<scheme> <jwt>`: `Bearer`, `Token` (the scheme Django REST Framework and
|
|
552
|
+
// the RealWorld spec use), or whatever this app configured. The scheme only
|
|
553
|
+
// labels the credential — the same JWT is verified the same way.
|
|
554
|
+
const authMatch = /^([!#$%&'*+\-.^_`|~0-9A-Za-z]+) +(.+)$/.exec((authHeader ?? '').trim());
|
|
555
|
+
const acceptedSchemes = new Set([...BASE_AUTH_SCHEMES, scheme.toLowerCase()]);
|
|
556
|
+
const headerToken = authMatch && acceptedSchemes.has(authMatch[1].toLowerCase()) ? authMatch[2].trim() : null;
|
|
451
557
|
const cookies = req.cookies;
|
|
452
558
|
const cookieToken = readAuthCookie(cookies, 'token');
|
|
453
559
|
const token = headerToken ??
|
|
@@ -494,6 +600,12 @@ export const verifyMiddleware = (options) => async (req, res, next) => {
|
|
|
494
600
|
// that one) — see {@link AUTH_SESSION_SOURCE_LOCALS_KEY}.
|
|
495
601
|
const sessionSource = headerToken ? 'header' : 'cookie';
|
|
496
602
|
res.locals[AUTH_SESSION_SOURCE_LOCALS_KEY] = sessionSource;
|
|
603
|
+
// Hand a header-authenticated client its own credential back (readSelf echoes
|
|
604
|
+
// it as `accessToken`). NEVER for a cookie-resolved session: that would expose
|
|
605
|
+
// the httpOnly token to JavaScript, which is the one thing the cookie prevents.
|
|
606
|
+
if (sessionSource === 'header' && headerToken) {
|
|
607
|
+
res.locals[AUTH_TOKEN_LOCALS_KEY] = headerToken;
|
|
608
|
+
}
|
|
497
609
|
// Auto-refresh the token if it's old enough.
|
|
498
610
|
try {
|
|
499
611
|
const decoded = decode(token);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"authorization.js","sourceRoot":"","sources":["../src/authorization.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,0EAA0E;AAC1E,gFAAgF;AAChF,oCAAoC;AACpC,OAAO,cAAc,CAAA;AACrB,OAAO,EAAE,EAAE,IAAI,IAAI,EAAE,MAAM,MAAM,CAAA;AAEjC,OAAO,EAAE,GAAG,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAA;AACnD,OAAO,EAAE,GAAG,IAAI,SAAS,EAAE,MAAM,sBAAsB,CAAA;AACvD,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,IAAI,SAAS,EAAE,MAAM,mBAAmB,CAAA;AASrE,MAAM,MAAM,GAAG,SAAS,EAAE,CAAA;AAE1B,MAAM,iBAAiB,GAAG,GAAW,EAAE;IACrC,IAAI,CAAC;QACH,OAA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C,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,CAAC,KAAK,CAAC,6BAA6B,EAAE,KAAK,CAAC,CAAA;IACpD,CAAC;IAED,OAAO,IAAI,EAAE,CAAA;AACf,CAAC,CAAA"}
|
|
@@ -12,9 +12,16 @@ import type * as types from '../types.js';
|
|
|
12
12
|
* so the client can re-establish `authenticated` state WITHOUT the token ever
|
|
13
13
|
* being exposed to JavaScript. Always self, so it mirrors `read`'s self branch
|
|
14
14
|
* (plan + two-factor status).
|
|
15
|
+
*
|
|
16
|
+
* **Token-only clients get the token back as `accessToken`.** When the request
|
|
17
|
+
* authenticated with an `Authorization` header (any accepted scheme — `Bearer` or
|
|
18
|
+
* `Token`), the middleware records that raw JWT and this response echoes it, so a
|
|
19
|
+
* RealWorld-style client can restore `{ user, token }` from `GET /user` the same way
|
|
20
|
+
* login and registration return it. A session resolved from the httpOnly cookie
|
|
21
|
+
* NEVER gets this field: exposing that token to JavaScript would defeat the cookie.
|
|
15
22
|
* @param resource - The user resource configuration (name, tableName, schema).
|
|
16
23
|
* @param resource.tableName - The database table name for users.
|
|
17
|
-
* @returns A request handler responding `{ statusCode: 200, body: { props, plan?, twoFactorEnabled? } }`, or 401 when unauthenticated.
|
|
24
|
+
* @returns A request handler responding `{ statusCode: 200, body: { props, plan?, twoFactorEnabled?, accessToken? } }`, or 401 when unauthenticated.
|
|
18
25
|
*/
|
|
19
26
|
export declare const readSelf: ({ tableName }: types.Resource) => (_req: MoleculeRequest, res: MoleculeResponse) => Promise<{
|
|
20
27
|
statusCode: number;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"readSelf.d.ts","sourceRoot":"","sources":["../../src/handlers/readSelf.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAA;
|
|
1
|
+
{"version":3,"file":"readSelf.d.ts","sourceRoot":"","sources":["../../src/handlers/readSelf.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAA;AAG/E,OAAO,KAAK,KAAK,KAAK,MAAM,aAAa,CAAA;AAMzC;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,eAAO,MAAM,QAAQ,GAAI,eAAe,KAAK,CAAC,QAAQ,MACtC,MAAM,eAAe,EAAE,KAAK,gBAAgB;;;EA6D3D,CAAA"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { getLogger } from '@molecule/api-bond';
|
|
2
2
|
import { findById } from '@molecule/api-database';
|
|
3
3
|
import { t } from '@molecule/api-i18n';
|
|
4
|
+
import { AUTH_TOKEN_LOCALS_KEY } from '../authorization.js';
|
|
4
5
|
import { getPlan } from '../utilities/getPlan.js';
|
|
5
6
|
import { stripSensitiveUserColumns } from '../utilities/stripSensitiveUserColumns.js';
|
|
6
7
|
const logger = getLogger();
|
|
@@ -16,9 +17,16 @@ const logger = getLogger();
|
|
|
16
17
|
* so the client can re-establish `authenticated` state WITHOUT the token ever
|
|
17
18
|
* being exposed to JavaScript. Always self, so it mirrors `read`'s self branch
|
|
18
19
|
* (plan + two-factor status).
|
|
20
|
+
*
|
|
21
|
+
* **Token-only clients get the token back as `accessToken`.** When the request
|
|
22
|
+
* authenticated with an `Authorization` header (any accepted scheme — `Bearer` or
|
|
23
|
+
* `Token`), the middleware records that raw JWT and this response echoes it, so a
|
|
24
|
+
* RealWorld-style client can restore `{ user, token }` from `GET /user` the same way
|
|
25
|
+
* login and registration return it. A session resolved from the httpOnly cookie
|
|
26
|
+
* NEVER gets this field: exposing that token to JavaScript would defeat the cookie.
|
|
19
27
|
* @param resource - The user resource configuration (name, tableName, schema).
|
|
20
28
|
* @param resource.tableName - The database table name for users.
|
|
21
|
-
* @returns A request handler responding `{ statusCode: 200, body: { props, plan?, twoFactorEnabled? } }`, or 401 when unauthenticated.
|
|
29
|
+
* @returns A request handler responding `{ statusCode: 200, body: { props, plan?, twoFactorEnabled?, accessToken? } }`, or 401 when unauthenticated.
|
|
22
30
|
*/
|
|
23
31
|
export const readSelf = ({ tableName }) => {
|
|
24
32
|
return async (_req, res) => {
|
|
@@ -51,6 +59,12 @@ export const readSelf = ({ tableName }) => {
|
|
|
51
59
|
if (plan) {
|
|
52
60
|
body.plan = plan;
|
|
53
61
|
}
|
|
62
|
+
// A header-authenticated caller already holds this token; the middleware
|
|
63
|
+
// records it only for that case, never for a cookie-resolved session.
|
|
64
|
+
const accessToken = res.locals?.[AUTH_TOKEN_LOCALS_KEY];
|
|
65
|
+
if (typeof accessToken === 'string' && accessToken) {
|
|
66
|
+
body.accessToken = accessToken;
|
|
67
|
+
}
|
|
54
68
|
// Always self — include two-factor setup info like `read`'s self branch.
|
|
55
69
|
try {
|
|
56
70
|
const secrets = await findById(`${tableName}Secrets`, userId);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"readSelf.js","sourceRoot":"","sources":["../../src/handlers/readSelf.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAA;AAC9C,OAAO,EAAE,QAAQ,EAAE,MAAM,wBAAwB,CAAA;AACjD,OAAO,EAAE,CAAC,EAAE,MAAM,oBAAoB,CAAA;
|
|
1
|
+
{"version":3,"file":"readSelf.js","sourceRoot":"","sources":["../../src/handlers/readSelf.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAA;AAC9C,OAAO,EAAE,QAAQ,EAAE,MAAM,wBAAwB,CAAA;AACjD,OAAO,EAAE,CAAC,EAAE,MAAM,oBAAoB,CAAA;AAGtC,OAAO,EAAE,qBAAqB,EAAE,MAAM,qBAAqB,CAAA;AAE3D,OAAO,EAAE,OAAO,EAAE,MAAM,yBAAyB,CAAA;AACjD,OAAO,EAAE,yBAAyB,EAAE,MAAM,2CAA2C,CAAA;AAErF,MAAM,MAAM,GAAG,SAAS,EAAE,CAAA;AAE1B;;;;;;;;;;;;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CAAC;gBACnD,IAAI,CAAC,WAAW,GAAG,WAAW,CAAA;YAChC,CAAC;YAED,yEAAyE;YACzE,IAAI,CAAC;gBACH,MAAM,OAAO,GAAG,MAAM,QAAQ,CAAoB,GAAG,SAAS,SAAS,EAAE,MAAM,CAAC,CAAA;gBAChF,IAAI,OAAO,EAAE,CAAC;oBACZ,IAAI,CAAC,gBAAgB,GAAG,IAAI,CAAC,gBAAgB,IAAI,KAAK,CAAA;oBACtD,IAAI,CAAC,mBAAmB,GAAG,OAAO,CAAC,OAAO,CAAC,sBAAsB,CAAC,CAAA;gBACpE,CAAC;YACH,CAAC;YAAC,OAAO,MAAM,EAAE,CAAC;gBAChB,2EAA2E;gBAC3E,qDAAqD;YACvD,CAAC;YAED,OAAO,EAAE,UAAU,EAAE,GAAG,EAAE,IAAI,EAAE,CAAA;QAClC,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,CAAA;YACnB,OAAO;gBACL,UAAU,EAAE,GAAG;gBACf,IAAI,EAAE,EAAE,KAAK,EAAE,CAAC,CAAC,6BAA6B,CAAC,EAAE,QAAQ,EAAE,6BAA6B,EAAE;aAC3F,CAAA;QACH,CAAC;IACH,CAAC,CAAA;AACH,CAAC,CAAA"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { MoleculeRequest } from '@molecule/api-resource';
|
|
1
|
+
import type { MoleculeRequest, MoleculeResponse } from '@molecule/api-resource';
|
|
2
2
|
import type * as types from '../types.js';
|
|
3
3
|
/** Request body for password update, with current password verification and new password. */
|
|
4
4
|
export interface UpdatePasswordRequest extends MoleculeRequest {
|
|
@@ -11,13 +11,22 @@ export interface UpdatePasswordRequest extends MoleculeRequest {
|
|
|
11
11
|
* Updates a user's password. If the user already has a password hash, the current password
|
|
12
12
|
* must be provided and verified first. The new password is hashed via `@molecule/api-password`
|
|
13
13
|
* and stored in the secrets table.
|
|
14
|
+
*
|
|
15
|
+
* **Every OTHER session is revoked; the caller's own is kept.** The device rows of all other
|
|
16
|
+
* devices are deleted, so a stolen token on another device dies — but the device this request
|
|
17
|
+
* arrived on stays, and the token that made the request (the `Authorization` header the client
|
|
18
|
+
* is holding) keeps working. A RealWorld-style suite changes the password and then keeps using
|
|
19
|
+
* the same token for the next request; revoking the caller too is what answered its second
|
|
20
|
+
* `PUT /user` with 401 (xr-flash-m167, ~2 min lost). Do not fold a per-user secret into the
|
|
21
|
+
* JWT: the device row is the revocation lever. A caller with no session (a handler invoked
|
|
22
|
+
* outside a request) falls back to revoking every device.
|
|
14
23
|
* @param resource - The user resource configuration (name, tableName, schema).
|
|
15
24
|
* @param resource.name - The resource name.
|
|
16
25
|
* @param resource.tableName - The database table name for users.
|
|
17
26
|
* @param resource.schema - The validation schema for user properties.
|
|
18
27
|
* @returns A request handler that responds with `{ statusCode: 200, body: { success: true } }` on success.
|
|
19
28
|
*/
|
|
20
|
-
export declare const updatePassword: ({ name: _name, tableName, schema: _schema }: types.Resource) => (req: UpdatePasswordRequest) => Promise<{
|
|
29
|
+
export declare const updatePassword: ({ name: _name, tableName, schema: _schema }: types.Resource) => (req: UpdatePasswordRequest, res?: MoleculeResponse) => Promise<{
|
|
21
30
|
statusCode: number;
|
|
22
31
|
body: {
|
|
23
32
|
error: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"updatePassword.d.ts","sourceRoot":"","sources":["../../src/handlers/updatePassword.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAA;
|
|
1
|
+
{"version":3,"file":"updatePassword.d.ts","sourceRoot":"","sources":["../../src/handlers/updatePassword.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAA;AAI/E,OAAO,KAAK,KAAK,KAAK,MAAM,aAAa,CAAA;AAKzC,6FAA6F;AAC7F,MAAM,WAAW,qBAAsB,SAAQ,eAAe;IAC5D,IAAI,EAAE;QACJ,eAAe,CAAC,EAAE,MAAM,CAAA;QACxB,WAAW,CAAC,EAAE,MAAM,CAAA;KACrB,CAAA;CACF;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,eAAO,MAAM,cAAc,GAAI,6CAA6C,KAAK,CAAC,QAAQ,MAC1E,KAAK,qBAAqB,EAAE,MAAM,gBAAgB;;;;;;;;;;;;;;EA6GjE,CAAA"}
|
|
@@ -9,6 +9,15 @@ const logger = getLogger();
|
|
|
9
9
|
* Updates a user's password. If the user already has a password hash, the current password
|
|
10
10
|
* must be provided and verified first. The new password is hashed via `@molecule/api-password`
|
|
11
11
|
* and stored in the secrets table.
|
|
12
|
+
*
|
|
13
|
+
* **Every OTHER session is revoked; the caller's own is kept.** The device rows of all other
|
|
14
|
+
* devices are deleted, so a stolen token on another device dies — but the device this request
|
|
15
|
+
* arrived on stays, and the token that made the request (the `Authorization` header the client
|
|
16
|
+
* is holding) keeps working. A RealWorld-style suite changes the password and then keeps using
|
|
17
|
+
* the same token for the next request; revoking the caller too is what answered its second
|
|
18
|
+
* `PUT /user` with 401 (xr-flash-m167, ~2 min lost). Do not fold a per-user secret into the
|
|
19
|
+
* JWT: the device row is the revocation lever. A caller with no session (a handler invoked
|
|
20
|
+
* outside a request) falls back to revoking every device.
|
|
12
21
|
* @param resource - The user resource configuration (name, tableName, schema).
|
|
13
22
|
* @param resource.name - The resource name.
|
|
14
23
|
* @param resource.tableName - The database table name for users.
|
|
@@ -16,7 +25,7 @@ const logger = getLogger();
|
|
|
16
25
|
* @returns A request handler that responds with `{ statusCode: 200, body: { success: true } }` on success.
|
|
17
26
|
*/
|
|
18
27
|
export const updatePassword = ({ name: _name, tableName, schema: _schema }) => {
|
|
19
|
-
return async (req) => {
|
|
28
|
+
return async (req, res) => {
|
|
20
29
|
try {
|
|
21
30
|
const id = req.params.id;
|
|
22
31
|
const { currentPassword, newPassword } = req.body;
|
|
@@ -82,11 +91,20 @@ export const updatePassword = ({ name: _name, tableName, schema: _schema }) => {
|
|
|
82
91
|
passwordResetToken: null,
|
|
83
92
|
passwordResetTokenAt: null,
|
|
84
93
|
});
|
|
85
|
-
//
|
|
86
|
-
//
|
|
87
|
-
//
|
|
94
|
+
// Revoke the user's sessions — every device EXCEPT the one this request
|
|
95
|
+
// arrived on. That kills a compromised session elsewhere while the token the
|
|
96
|
+
// caller is holding stays valid, which is what lets a client change its own
|
|
97
|
+
// password and keep making authenticated requests. With no session (a handler
|
|
98
|
+
// invoked outside a request) there is no device to spare, so revoke all.
|
|
99
|
+
const currentDeviceId = res?.locals?.session?.deviceId;
|
|
100
|
+
const deviceService = get('device');
|
|
88
101
|
try {
|
|
89
|
-
|
|
102
|
+
if (currentDeviceId && typeof deviceService?.deleteOthersByUserId === 'function') {
|
|
103
|
+
await deviceService.deleteOthersByUserId(id, currentDeviceId);
|
|
104
|
+
}
|
|
105
|
+
else {
|
|
106
|
+
await deviceService?.deleteByUserId(id);
|
|
107
|
+
}
|
|
90
108
|
// Evict this process's positive device-exists cache so no just-deleted
|
|
91
109
|
// device keeps authenticating for the cache TTL — immediate revocation.
|
|
92
110
|
invalidateAllDeviceExistsCache();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"updatePassword.js","sourceRoot":"","sources":["../../src/handlers/updatePassword.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAA;AACjE,OAAO,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAA;AAC7D,OAAO,EAAE,CAAC,EAAE,MAAM,oBAAoB,CAAA;AACtC,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,wBAAwB,CAAA;
|
|
1
|
+
{"version":3,"file":"updatePassword.js","sourceRoot":"","sources":["../../src/handlers/updatePassword.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,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AM,aAAa,GAAG,GAAG,CAAgB,QAAQ,CAAC,CAAA;YAClD,IAAI,CAAC;gBACH,IAAI,eAAe,IAAI,OAAO,aAAa,EAAE,oBAAoB,KAAK,UAAU,EAAE,CAAC;oBACjF,MAAM,aAAa,CAAC,oBAAoB,CAAC,EAAE,EAAE,eAAe,CAAC,CAAA;gBAC/D,CAAC;qBAAM,CAAC;oBACN,MAAM,aAAa,EAAE,cAAc,CAAC,EAAE,CAAC,CAAA;gBACzC,CAAC;gBACD,uEAAuE;gBACvE,wEAAwE;gBACxE,8BAA8B,EAAE,CAAA;YAClC,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBACf,2DAA2D;gBAC3D,MAAM,CAAC,IAAI,CAAC,qDAAqD,EAAE,EAAE,KAAK,EAAE,MAAM,EAAE,EAAE,EAAE,CAAC,CAAA;YAC3F,CAAC;YAED,SAAS,CAAC,KAAK,CAAC,EAAE,IAAI,EAAE,uBAAuB,EAAE,MAAM,EAAE,EAAE,EAAE,CAAC,CAAC,KAAK,CAAC,GAAG,EAAE,GAAE,CAAC,CAAC,CAAA;YAE9E,OAAO,EAAE,UAAU,EAAE,GAAG,EAAE,IAAI,EAAE,EAAE,OAAO,EAAE,IAAI,EAAE,EAAE,CAAA;QACrD,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,CAAA;YACnB,OAAO;gBACL,UAAU,EAAE,GAAG;gBACf,IAAI,EAAE;oBACJ,KAAK,EAAE,CAAC,CAAC,mCAAmC,CAAC;oBAC7C,QAAQ,EAAE,mCAAmC;iBAC9C;aACF,CAAA;QACH,CAAC;IACH,CAAC,CAAA;AACH,CAAC,CAAA"}
|
package/dist/index.d.ts
CHANGED
|
@@ -8,20 +8,19 @@
|
|
|
8
8
|
* - `usersSecrets` — {@link SecretProps}: `passwordHash`, `passwordResetToken` (and
|
|
9
9
|
* `passwordResetTokenAt`), `twoFactorSecret` / `pendingTwoFactorSecret`, `lastTwoFactorTimeStep`.
|
|
10
10
|
*
|
|
11
|
+
* **Table setup:** `src/__setup__/users.sql` + `src/__setup__/usersSecrets.sql`; an mlcl-scaffolded API replays `__setup__/*.sql` on migrate.
|
|
12
|
+
*
|
|
11
13
|
* **`usersSecrets.id` IS the user's id — the value of `users.id`, never a fresh uuid.** The DDL
|
|
12
|
-
* declares it `UNIQUE PRIMARY KEY` with no foreign key, so nothing enforces
|
|
13
|
-
*
|
|
14
|
-
* `GET /api/users/me`
|
|
15
|
-
* both rows from one id:
|
|
14
|
+
* declares it `UNIQUE PRIMARY KEY` with no foreign key, so nothing enforces it: a row written
|
|
15
|
+
* under another id is never found again — login answers "invalid credentials" while
|
|
16
|
+
* `GET /api/users/me` still answers 200. A hand-written signup writes both rows:
|
|
16
17
|
* `const id = uuid(); await create('users', { ...props, id }); await create('usersSecrets', { id, passwordHash: await hash(password) })`.
|
|
17
18
|
*
|
|
18
|
-
* Prefer not to hand-write
|
|
19
|
-
* `handlers.
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
* same key — `findById('usersSecrets', userId)`, or `${tableName}Secrets` when the resource
|
|
24
|
-
* carries a custom `tableName` — never SQL.
|
|
19
|
+
* Prefer not to hand-write that — `handlers.create` (signup: both rows, hash via
|
|
20
|
+
* `@molecule/api-password`, session device), `handlers.logIn` (reads `usersSecrets` by the user's
|
|
21
|
+
* id), `handlers.updatePassword`, `handlers.forgotPassword` / `handlers.resetPassword`. To touch
|
|
22
|
+
* one secret yourself use the datastore on the same key — `findById('usersSecrets', userId)` (or
|
|
23
|
+
* `${tableName}Secrets` for a custom `tableName`) — never SQL.
|
|
25
24
|
*
|
|
26
25
|
* **Issuing a session yourself (the sequence is device, then session — two calls, and the first
|
|
27
26
|
* RETURNS the id):** the middleware accepts both `Authorization: Bearer <jwt>` and
|
|
@@ -41,8 +40,14 @@
|
|
|
41
40
|
* `get<DeviceService>('device')` is the typed accessor (never hand-type a
|
|
42
41
|
* `get<{ createOrUpdate(): … }>('device')` generic: a wrong one still compiles and leaves the
|
|
43
42
|
* field you invented — `device.id` — `undefined`), and `createOrUpdate` RESOLVES TO THE DEVICE ID
|
|
44
|
-
* STRING, not to a row. `
|
|
45
|
-
*
|
|
43
|
+
* STRING, not to a row. `set()` throws when `deviceId` is missing rather than mint a token every
|
|
44
|
+
* later request answers 401.
|
|
45
|
+
*
|
|
46
|
+
* **RealWorld-style token API (`Authorization: Token <jwt>`)? CONFIGURATION on this same auth
|
|
47
|
+
* path — never a credentials table of your own** (`usersSecrets.passwordHash` is the password
|
|
48
|
+
* store). Set `AUTH_SCHEME=Token` (or `verifyMiddleware({ scheme: 'Token' })`): every route
|
|
49
|
+
* accepts it, `logIn`/`create` return `accessToken`, `GET /users/me` echoes it, and a password
|
|
50
|
+
* change revokes every OTHER device but keeps the caller's own session.
|
|
46
51
|
*
|
|
47
52
|
* **`handlers.*` return `{ statusCode, headers?, body }` and never write to `res`** — not through
|
|
48
53
|
* `res.json`, not through `res.send`, not through `res.end`. The mounted routes apply that object
|
|
@@ -99,6 +104,26 @@
|
|
|
99
104
|
* passes sets the policy both halves read, and a laxer mount later in the chain cannot
|
|
100
105
|
* re-admit the cookie. If the app mounts two, mount it once instead.
|
|
101
106
|
*
|
|
107
|
+
* **The RealWorld token recipe (detail).** The scheme is configuration, not a second auth
|
|
108
|
+
* layer: `AUTH_SCHEME=Token` in the API's env, or `verifyMiddleware({ scheme: 'Token',
|
|
109
|
+
* allowCookieSession: false })` at the mount, makes every covered route accept
|
|
110
|
+
* `Authorization: Token <jwt>` (`Bearer` stays accepted too) and labels the sign-in response
|
|
111
|
+
* header with that scheme. The token is already in the body — `handlers.logIn` and
|
|
112
|
+
* `handlers.create` return `{ props, accessToken, user }`, and `GET /users/me` adds
|
|
113
|
+
* `accessToken` when the request authenticated with the header (never for a cookie-resolved
|
|
114
|
+
* session: that token must stay unreadable to JavaScript).
|
|
115
|
+
*
|
|
116
|
+
* ```typescript
|
|
117
|
+
* // Token-only API that speaks RealWorld's scheme.
|
|
118
|
+
* router.use(verifyMiddleware({ scheme: 'Token', allowCookieSession: false }))
|
|
119
|
+
* // POST /users and POST /users/log-in answer { props, accessToken, user };
|
|
120
|
+
* // clients send `Authorization: Token <accessToken>` from then on.
|
|
121
|
+
* ```
|
|
122
|
+
*
|
|
123
|
+
* The CLIENT labels its header the same way: `authScheme: 'Token'` is an option of the HTTP
|
|
124
|
+
* client's CONSTRUCTOR (`createFetchClient({ baseURL, authScheme: 'Token' })`, or the axios
|
|
125
|
+
* provider's `createAxiosClient`), never a property of `getClient()`'s result.
|
|
126
|
+
*
|
|
102
127
|
* **Revoking a session yourself:** the middleware caches "this device exists" for 10 s per
|
|
103
128
|
* process, so a hand-written logout that deletes the `devices` row keeps authorizing that
|
|
104
129
|
* token until the cache expires — a check right after logout still answers 200. Call
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmMG;AAEH,OAAO,KAAK,aAAa,MAAM,oBAAoB,CAAA;AACnD,OAAO,KAAK,WAAW,MAAM,wBAAwB,CAAA;AACrD,cAAc,oBAAoB,CAAA;AAClC,OAAO,KAAK,QAAQ,MAAM,qBAAqB,CAAA;AAC/C,cAAc,WAAW,CAAA;AACzB,cAAc,wBAAwB,CAAA;AACtC,cAAc,eAAe,CAAA;AAC7B,cAAc,aAAa,CAAA;AAC3B,cAAc,aAAa,CAAA;AAC3B,cAAc,cAAc,CAAA;AAC5B,OAAO,KAAK,KAAK,MAAM,YAAY,CAAA;AACnC,OAAO,KAAK,SAAS,MAAM,sBAAsB,CAAA"}
|
package/dist/index.js
CHANGED
|
@@ -8,20 +8,19 @@
|
|
|
8
8
|
* - `usersSecrets` — {@link SecretProps}: `passwordHash`, `passwordResetToken` (and
|
|
9
9
|
* `passwordResetTokenAt`), `twoFactorSecret` / `pendingTwoFactorSecret`, `lastTwoFactorTimeStep`.
|
|
10
10
|
*
|
|
11
|
+
* **Table setup:** `src/__setup__/users.sql` + `src/__setup__/usersSecrets.sql`; an mlcl-scaffolded API replays `__setup__/*.sql` on migrate.
|
|
12
|
+
*
|
|
11
13
|
* **`usersSecrets.id` IS the user's id — the value of `users.id`, never a fresh uuid.** The DDL
|
|
12
|
-
* declares it `UNIQUE PRIMARY KEY` with no foreign key, so nothing enforces
|
|
13
|
-
*
|
|
14
|
-
* `GET /api/users/me`
|
|
15
|
-
* both rows from one id:
|
|
14
|
+
* declares it `UNIQUE PRIMARY KEY` with no foreign key, so nothing enforces it: a row written
|
|
15
|
+
* under another id is never found again — login answers "invalid credentials" while
|
|
16
|
+
* `GET /api/users/me` still answers 200. A hand-written signup writes both rows:
|
|
16
17
|
* `const id = uuid(); await create('users', { ...props, id }); await create('usersSecrets', { id, passwordHash: await hash(password) })`.
|
|
17
18
|
*
|
|
18
|
-
* Prefer not to hand-write
|
|
19
|
-
* `handlers.
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
* same key — `findById('usersSecrets', userId)`, or `${tableName}Secrets` when the resource
|
|
24
|
-
* carries a custom `tableName` — never SQL.
|
|
19
|
+
* Prefer not to hand-write that — `handlers.create` (signup: both rows, hash via
|
|
20
|
+
* `@molecule/api-password`, session device), `handlers.logIn` (reads `usersSecrets` by the user's
|
|
21
|
+
* id), `handlers.updatePassword`, `handlers.forgotPassword` / `handlers.resetPassword`. To touch
|
|
22
|
+
* one secret yourself use the datastore on the same key — `findById('usersSecrets', userId)` (or
|
|
23
|
+
* `${tableName}Secrets` for a custom `tableName`) — never SQL.
|
|
25
24
|
*
|
|
26
25
|
* **Issuing a session yourself (the sequence is device, then session — two calls, and the first
|
|
27
26
|
* RETURNS the id):** the middleware accepts both `Authorization: Bearer <jwt>` and
|
|
@@ -41,8 +40,14 @@
|
|
|
41
40
|
* `get<DeviceService>('device')` is the typed accessor (never hand-type a
|
|
42
41
|
* `get<{ createOrUpdate(): … }>('device')` generic: a wrong one still compiles and leaves the
|
|
43
42
|
* field you invented — `device.id` — `undefined`), and `createOrUpdate` RESOLVES TO THE DEVICE ID
|
|
44
|
-
* STRING, not to a row. `
|
|
45
|
-
*
|
|
43
|
+
* STRING, not to a row. `set()` throws when `deviceId` is missing rather than mint a token every
|
|
44
|
+
* later request answers 401.
|
|
45
|
+
*
|
|
46
|
+
* **RealWorld-style token API (`Authorization: Token <jwt>`)? CONFIGURATION on this same auth
|
|
47
|
+
* path — never a credentials table of your own** (`usersSecrets.passwordHash` is the password
|
|
48
|
+
* store). Set `AUTH_SCHEME=Token` (or `verifyMiddleware({ scheme: 'Token' })`): every route
|
|
49
|
+
* accepts it, `logIn`/`create` return `accessToken`, `GET /users/me` echoes it, and a password
|
|
50
|
+
* change revokes every OTHER device but keeps the caller's own session.
|
|
46
51
|
*
|
|
47
52
|
* **`handlers.*` return `{ statusCode, headers?, body }` and never write to `res`** — not through
|
|
48
53
|
* `res.json`, not through `res.send`, not through `res.end`. The mounted routes apply that object
|
|
@@ -99,6 +104,26 @@
|
|
|
99
104
|
* passes sets the policy both halves read, and a laxer mount later in the chain cannot
|
|
100
105
|
* re-admit the cookie. If the app mounts two, mount it once instead.
|
|
101
106
|
*
|
|
107
|
+
* **The RealWorld token recipe (detail).** The scheme is configuration, not a second auth
|
|
108
|
+
* layer: `AUTH_SCHEME=Token` in the API's env, or `verifyMiddleware({ scheme: 'Token',
|
|
109
|
+
* allowCookieSession: false })` at the mount, makes every covered route accept
|
|
110
|
+
* `Authorization: Token <jwt>` (`Bearer` stays accepted too) and labels the sign-in response
|
|
111
|
+
* header with that scheme. The token is already in the body — `handlers.logIn` and
|
|
112
|
+
* `handlers.create` return `{ props, accessToken, user }`, and `GET /users/me` adds
|
|
113
|
+
* `accessToken` when the request authenticated with the header (never for a cookie-resolved
|
|
114
|
+
* session: that token must stay unreadable to JavaScript).
|
|
115
|
+
*
|
|
116
|
+
* ```typescript
|
|
117
|
+
* // Token-only API that speaks RealWorld's scheme.
|
|
118
|
+
* router.use(verifyMiddleware({ scheme: 'Token', allowCookieSession: false }))
|
|
119
|
+
* // POST /users and POST /users/log-in answer { props, accessToken, user };
|
|
120
|
+
* // clients send `Authorization: Token <accessToken>` from then on.
|
|
121
|
+
* ```
|
|
122
|
+
*
|
|
123
|
+
* The CLIENT labels its header the same way: `authScheme: 'Token'` is an option of the HTTP
|
|
124
|
+
* client's CONSTRUCTOR (`createFetchClient({ baseURL, authScheme: 'Token' })`, or the axios
|
|
125
|
+
* provider's `createAxiosClient`), never a property of `getClient()`'s result.
|
|
126
|
+
*
|
|
102
127
|
* **Revoking a session yourself:** the middleware caches "this device exists" for 10 s per
|
|
103
128
|
* process, so a hand-written logout that deletes the `devices` row keeps authorizing that
|
|
104
129
|
* token until the cache expires — a check right after logout still answers 200. Call
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmMG;AAEH,OAAO,KAAK,aAAa,MAAM,oBAAoB,CAAA;AACnD,OAAO,KAAK,WAAW,MAAM,wBAAwB,CAAA;AACrD,cAAc,oBAAoB,CAAA;AAClC,OAAO,KAAK,QAAQ,MAAM,qBAAqB,CAAA;AAC/C,cAAc,WAAW,CAAA;AACzB,cAAc,wBAAwB,CAAA;AACtC,cAAc,eAAe,CAAA;AAC7B,cAAc,aAAa,CAAA;AAC3B,cAAc,aAAa,CAAA;AAC3B,cAAc,cAAc,CAAA;AAC5B,OAAO,KAAK,KAAK,MAAM,YAAY,CAAA;AACnC,OAAO,KAAK,SAAS,MAAM,sBAAsB,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@molecule/api-resource-user",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.6.0",
|
|
4
4
|
"description": "User resource types and schema for molecule.dev.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
},
|
|
19
19
|
"files": [
|
|
20
20
|
"dist",
|
|
21
|
-
"
|
|
21
|
+
"src/__setup__",
|
|
22
22
|
"README.md"
|
|
23
23
|
],
|
|
24
24
|
"keywords": [
|
|
File without changes
|
|
File without changes
|