very-express 0.8.4 → 0.9.0-alpha
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/AGENTS.md +8 -1
- package/dist/index.js +1120 -580
- package/dist/templates/_projectSettings/env +13 -0
- package/dist/templates/_projectSettings/package.json +2 -1
- package/dist/templates/_routes/ExternalIdentityUI.gen.ts +20 -0
- package/dist/templates/_routes/LoginUI.ts +385 -5
- package/dist/templates/_services/oauth/OAuthProfileMap.ts +2 -2
- package/dist/templates/_services/oauth/OAuthStrategyService.ts +5 -5
- package/dist/templates/_types/auth.ts +9 -1
- package/dist/templates/jsonSchema/UserAuthProfiles.json +13 -5
- package/dist/templates/root/public/js/deleteaccount.js +54 -0
- package/dist/templates/root/public/js/externallogin.js +133 -0
- package/docs/features/accountDeletion.md +1 -1
- package/docs/features/auth.md +34 -0
- package/docs/features/externalIdentity.md +163 -0
- package/docs/releaseNote/v0-8-4.md +131 -0
- package/docs/releaseNote/v0-9-0.md +49 -0
- package/package.json +1 -1
- package/vex.config.json +6 -0
- package/docs/appGenerated/auth.md +0 -23
|
@@ -24,7 +24,52 @@ document.addEventListener("DOMContentLoaded", function () {
|
|
|
24
24
|
result.textContent = JSON.stringify(data, null, 2);
|
|
25
25
|
}
|
|
26
26
|
|
|
27
|
+
/**
|
|
28
|
+
* Deletion is self-service and the server resolves the account from the token alone, so with no
|
|
29
|
+
* token there is nothing to delete: sending an empty `Bearer ` would only earn a bare 401 that
|
|
30
|
+
* reads like a server fault. Point at the login page instead.
|
|
31
|
+
*
|
|
32
|
+
* Both credentials are required — `Authentication.middleware` treats them as one requirement — so
|
|
33
|
+
* a half-populated store counts as "not signed in" rather than as an API call.
|
|
34
|
+
*
|
|
35
|
+
* Note this file is copied into a project once and never overwritten, so a project generated
|
|
36
|
+
* before these checks existed keeps the old behaviour until it is updated by hand.
|
|
37
|
+
*/
|
|
38
|
+
function signedIn() {
|
|
39
|
+
return !!localStorage.getItem("accessToken") && !!localStorage.getItem("accessTokenIndex");
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function notSignedIn() {
|
|
43
|
+
render({
|
|
44
|
+
status: 401,
|
|
45
|
+
error: "You are not signed in. Deletion is self-service and the server takes the account " +
|
|
46
|
+
"from your access token, so sign in first.",
|
|
47
|
+
signIn: "/login",
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* A 401 from the server means the stored credential was not accepted — expired, or already
|
|
53
|
+
* tombstoned. Deliberately does NOT clear it: the request may equally have failed for a reason
|
|
54
|
+
* that has nothing to do with the token, and dropping the session on any failure would sign the
|
|
55
|
+
* user out of a working account. Sign in again and retry; the login flow overwrites both tokens.
|
|
56
|
+
*/
|
|
57
|
+
function sessionRejected(outcome) {
|
|
58
|
+
render({
|
|
59
|
+
status: outcome.status,
|
|
60
|
+
error: "Your session was not accepted, so nothing was deleted. It may have expired — " +
|
|
61
|
+
"sign in again and retry.",
|
|
62
|
+
detail: outcome.body,
|
|
63
|
+
signIn: "/login",
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
|
|
27
67
|
button.addEventListener("click", function () {
|
|
68
|
+
if (!signedIn()) {
|
|
69
|
+
notSignedIn();
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
|
|
28
73
|
if (input.value !== "DELETE") {
|
|
29
74
|
render({ error: 'Type DELETE in the box to confirm.' });
|
|
30
75
|
return;
|
|
@@ -60,6 +105,15 @@ document.addEventListener("DOMContentLoaded", function () {
|
|
|
60
105
|
})
|
|
61
106
|
.then(function (outcome) {
|
|
62
107
|
if (!outcome.ok) {
|
|
108
|
+
// 401 means the credential was not accepted. Say what to do about it rather than
|
|
109
|
+
// printing a raw error body the user cannot act on — see sessionRejected for why
|
|
110
|
+
// the stored tokens are left alone.
|
|
111
|
+
if (outcome.status === 401) {
|
|
112
|
+
sessionRejected(outcome);
|
|
113
|
+
button.disabled = false;
|
|
114
|
+
return;
|
|
115
|
+
}
|
|
116
|
+
|
|
63
117
|
render({ status: outcome.status, error: outcome.body });
|
|
64
118
|
button.disabled = false;
|
|
65
119
|
return;
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
// External identity (broker SSO) sign-in glue.
|
|
2
|
+
//
|
|
3
|
+
// The login page renders one button per configured sign-in method, each carrying its provider id in a
|
|
4
|
+
// `data-provider` attribute, and the broker's own init script defines a global that turns
|
|
5
|
+
// `(providerId)` into a fresh ID token — for Firebase, `signInWithPopup` followed by `getIdToken()`.
|
|
6
|
+
//
|
|
7
|
+
// This file owns nothing vendor specific. It calls that global and hands the token to
|
|
8
|
+
// POST /api/auth/external, the only endpoint in the system that accepts a non-vex credential. The
|
|
9
|
+
// exchange consumes the token and answers with a vex session redirect; from that point on the client
|
|
10
|
+
// holds only vex tokens and nothing here runs again.
|
|
11
|
+
//
|
|
12
|
+
// Configuration arrives as `window.__vexExternalLogin`, rendered inline by the login page:
|
|
13
|
+
// { getToken: "<global name>", resumeRedirect: "<global name>", signInMethod: "popup"|"redirect",
|
|
14
|
+
// config: { ...broker public config, from env... }, problems: [...] }
|
|
15
|
+
//
|
|
16
|
+
// Two entry points, and neither the page nor this file needs to know which mode is in use:
|
|
17
|
+
// - a button calls getToken(providerId); in "redirect" mode the page navigates away before that
|
|
18
|
+
// promise ever settles
|
|
19
|
+
// - on page load, resumeRedirect() completes a redirect sign-in, or resolves null
|
|
20
|
+
|
|
21
|
+
document.addEventListener("DOMContentLoaded", function () {
|
|
22
|
+
var settings = window.__vexExternalLogin || {};
|
|
23
|
+
var getTokenName = settings.getToken;
|
|
24
|
+
var problems = settings.problems || [];
|
|
25
|
+
|
|
26
|
+
var buttons = document.querySelectorAll ? document.querySelectorAll(".externalLoginBtn") : [];
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Broker SDKs report a misconfigured client with something generic — Firebase's
|
|
30
|
+
* `auth/internal-error` says nothing about the cause. The login page sends along what the server
|
|
31
|
+
* could determine, so a developer is not left reading a network trace.
|
|
32
|
+
*/
|
|
33
|
+
function report(message) {
|
|
34
|
+
if (problems.length > 0) {
|
|
35
|
+
message += "\n\nServer-side configuration problems:\n- " + problems.join("\n- ");
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
// alert rather than a DOM node: the login page has no result container.
|
|
39
|
+
alert(message);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function exchange(idToken) {
|
|
43
|
+
return fetch("/api/auth/external", {
|
|
44
|
+
method: "POST",
|
|
45
|
+
headers: { "Content-Type": "application/json" },
|
|
46
|
+
body: JSON.stringify({ idToken: idToken }),
|
|
47
|
+
}).then(function (response) {
|
|
48
|
+
// read as text first: an error response may not be JSON (a proxy or the express error
|
|
49
|
+
// handler can return HTML), and response.json() would then reject and hide the real status
|
|
50
|
+
return response.text().then(function (text) {
|
|
51
|
+
var body;
|
|
52
|
+
try {
|
|
53
|
+
body = text ? JSON.parse(text) : {};
|
|
54
|
+
}
|
|
55
|
+
catch (e) {
|
|
56
|
+
body = { raw: text };
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
return { ok: response.ok, status: response.status, body: body };
|
|
60
|
+
});
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Complete a redirect sign-in.
|
|
66
|
+
*
|
|
67
|
+
* A no-op in popup mode, so this runs unconditionally: the redirect path cannot be distinguished
|
|
68
|
+
* from an ordinary page load until the broker answers, and it must be asked on every load to catch
|
|
69
|
+
* the return.
|
|
70
|
+
*/
|
|
71
|
+
function resume() {
|
|
72
|
+
var resumeName = settings.resumeRedirect;
|
|
73
|
+
var fn = resumeName ? window[resumeName] : undefined;
|
|
74
|
+
if (typeof fn !== "function") return;
|
|
75
|
+
|
|
76
|
+
Promise.resolve()
|
|
77
|
+
.then(function () { return fn(); })
|
|
78
|
+
.then(function (idToken) {
|
|
79
|
+
if (!idToken) return; // not a return from a redirect sign-in
|
|
80
|
+
return exchange(idToken);
|
|
81
|
+
})
|
|
82
|
+
.then(function (outcome) {
|
|
83
|
+
if (!outcome) return;
|
|
84
|
+
if (outcome.ok && outcome.body && outcome.body.result && outcome.body.result.url) {
|
|
85
|
+
window.location.href = outcome.body.result.url;
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
report("External sign-in failed (" + outcome.status + "): " + JSON.stringify(outcome.body));
|
|
89
|
+
})
|
|
90
|
+
.catch(function (err) {
|
|
91
|
+
report("External sign-in error: " + String(err));
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
Array.prototype.forEach.call(buttons, function (button) {
|
|
96
|
+
button.addEventListener("click", function () {
|
|
97
|
+
var getToken = getTokenName ? window[getTokenName] : undefined;
|
|
98
|
+
if (typeof getToken !== "function") {
|
|
99
|
+
report(
|
|
100
|
+
"External sign-in is not configured: window." + getTokenName +
|
|
101
|
+
" is missing. Check the broker's init script."
|
|
102
|
+
);
|
|
103
|
+
return;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
button.disabled = true;
|
|
107
|
+
|
|
108
|
+
Promise.resolve()
|
|
109
|
+
.then(function () { return getToken(button.getAttribute("data-provider")); })
|
|
110
|
+
.then(function (idToken) {
|
|
111
|
+
if (!idToken) throw new Error("the configured getToken() resolved with no ID token");
|
|
112
|
+
return exchange(idToken);
|
|
113
|
+
})
|
|
114
|
+
.then(function (outcome) {
|
|
115
|
+
// mirrors the local flow: the server answers with the session redirect, and the
|
|
116
|
+
// /logincallback page performs the code-for-tokens exchange
|
|
117
|
+
if (outcome.ok && outcome.body && outcome.body.result && outcome.body.result.url) {
|
|
118
|
+
window.location.href = outcome.body.result.url;
|
|
119
|
+
return;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
button.disabled = false;
|
|
123
|
+
report("External sign-in failed (" + outcome.status + "): " + JSON.stringify(outcome.body));
|
|
124
|
+
})
|
|
125
|
+
.catch(function (err) {
|
|
126
|
+
button.disabled = false;
|
|
127
|
+
report("External sign-in error: " + String(err));
|
|
128
|
+
});
|
|
129
|
+
});
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
resume();
|
|
133
|
+
});
|
|
@@ -112,7 +112,7 @@ returns `alreadyDeleted` without re-stamping the row.
|
|
|
112
112
|
Order is load-bearing:
|
|
113
113
|
|
|
114
114
|
1. **Credentials first** — auth profiles, roles, sessions. Tombstoning first would leave the OAuth
|
|
115
|
-
path able to resolve the account through `provider` / `
|
|
115
|
+
path able to resolve the account through `provider` / `providerUserId`, i.e. a deleted user could log
|
|
116
116
|
back into their own tombstone.
|
|
117
117
|
2. **Tombstone last** — `softDelete(userId, TOMBSTONE)`. A mid-flight failure therefore leaves a
|
|
118
118
|
live account that can simply be retried.
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
# Auth
|
|
2
|
+
- Stateless JWT token
|
|
3
|
+
- **Rolling Keys**
|
|
4
|
+
define in `.env`,
|
|
5
|
+
named `JWT_KEY{increment}`
|
|
6
|
+
```bash
|
|
7
|
+
JWT_KEY1=aaaaa
|
|
8
|
+
JWT_KEY2=bbbbb
|
|
9
|
+
JWT_KEY3=ccccc
|
|
10
|
+
```
|
|
11
|
+
- **OAuth2**
|
|
12
|
+
Supported Providers:
|
|
13
|
+
- Google
|
|
14
|
+
- Github
|
|
15
|
+
|
|
16
|
+
define in `.env`,
|
|
17
|
+
named `OAUTH_{provider}_CLIENTID` & `OAUTH_{provider}_CLIENTSECRET`
|
|
18
|
+
```bash
|
|
19
|
+
OAUTH_GOOGLE_CLIENTID=xxxxx
|
|
20
|
+
OAUTH_GOOGLE_CLIENTSECRET=xxxxx
|
|
21
|
+
```
|
|
22
|
+
- **External identity (broker SSO)** — off by default
|
|
23
|
+
- `POST /auth/external` takes an ID token from a broker (Firebase), verifies it against the
|
|
24
|
+
issuer's JWKS, and provisions the vex identity. The broker's token is consumed there and never
|
|
25
|
+
stored; the reply is the usual session-code redirect, so `POST /auth/token` still mints every
|
|
26
|
+
token.
|
|
27
|
+
- The generated login page renders the broker's buttons; the broker's SDK comes from the npm
|
|
28
|
+
package, served same-origin.
|
|
29
|
+
- **Prefer a broker that exposes the upstream IdP's subject — Firebase or Cognito.** Those produce
|
|
30
|
+
`("google", <Google sub>)`, the same key the passport flow writes. A broker that cannot (Keycloak,
|
|
31
|
+
Okta) only yields one broker-labelled row, so the UI shows the broker's name instead of the
|
|
32
|
+
provider the user actually picked.
|
|
33
|
+
- Config, identity layers, `signInMethod`, troubleshooting:
|
|
34
|
+
[`docs/features/externalIdentity.md`](../features/externalIdentity.md).
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
# External identity (broker SSO)
|
|
2
|
+
|
|
3
|
+
Sign in through an external identity broker — Firebase today — while **every token in the system stays
|
|
4
|
+
vex-issued**. Off by default.
|
|
5
|
+
|
|
6
|
+
```
|
|
7
|
+
Browser ──(SDK sign-in)──> Broker ──(ID token)──> POST /api/auth/external ──> vex JWT
|
|
8
|
+
│
|
|
9
|
+
verify JWKS, map claims,
|
|
10
|
+
find-or-create the vex identity
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
The broker's token is a **credential, not a session**: presented once, consumed at that endpoint, never
|
|
14
|
+
stored, never echoed, and accepted nowhere else. Everything downstream is the existing vex flow — the
|
|
15
|
+
endpoint answers with a session-code redirect, and `POST /api/auth/token` mints the access/refresh pair.
|
|
16
|
+
|
|
17
|
+
The server holds **no broker SDK and no client secret**: the ID token is a standard OIDC JWT, verified
|
|
18
|
+
with the `jsonwebtoken` the app already has, against keys fetched from the issuer's JWKS and imported
|
|
19
|
+
with `node:crypto`.
|
|
20
|
+
|
|
21
|
+
## Configuration
|
|
22
|
+
|
|
23
|
+
```json
|
|
24
|
+
"auth": {
|
|
25
|
+
"externalIdentity": {
|
|
26
|
+
"enabled": true,
|
|
27
|
+
"preset": "firebase",
|
|
28
|
+
"projectId": "your-firebase-project"
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
A preset names a broker. Explicit keys override it, so you can start from a preset and adjust one field.
|
|
34
|
+
Without a preset, `issuer` and the rest must be given explicitly.
|
|
35
|
+
|
|
36
|
+
| Key | Default | Meaning |
|
|
37
|
+
|---|---|---|
|
|
38
|
+
| `enabled` | `false` | The feature gate. Auth must also be on. |
|
|
39
|
+
| `preset` | — | `firebase`. Unknown names fail generation loudly. |
|
|
40
|
+
| `projectId` | — | Preset variable: supplies the issuer and the audience. |
|
|
41
|
+
| `identityLayer` | `auto` | `auto` / `broker` / `upstream` — see below. |
|
|
42
|
+
| `signInMethod` | `popup` | `popup` / `redirect` — see below. |
|
|
43
|
+
| `onMissingEmail` | `reject` | `reject` refuses a login with no email; `synthesize` writes `<subject>@<provider>.invalid`. |
|
|
44
|
+
| `issuer`, `jwksUrl`, `discovery`, `audience`, `audienceClaim`, `algorithms`, `providerLabel`, `claims` | from the preset | For a broker with no preset. |
|
|
45
|
+
|
|
46
|
+
Generation fails loudly rather than emitting a half-working verifier: unknown preset, a missing preset
|
|
47
|
+
variable, a symmetric algorithm (`HS*`, an alg-confusion risk), `providerLabel: "local"` (reserved by
|
|
48
|
+
vex's own password path), or `identityLayer: "upstream"` on a preset that cannot reach an upstream
|
|
49
|
+
subject.
|
|
50
|
+
|
|
51
|
+
### Env
|
|
52
|
+
|
|
53
|
+
```
|
|
54
|
+
FIREBASE_API_KEY=
|
|
55
|
+
FIREBASE_AUTH_DOMAIN=
|
|
56
|
+
FIREBASE_PROJECT_ID=
|
|
57
|
+
FIREBASE_APP_ID=
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
These are the broker's **public** browser values, served to the login page by design. `storageBucket`,
|
|
61
|
+
`messagingSenderId` and `measurementId` are for other Firebase products and are not used.
|
|
62
|
+
|
|
63
|
+
**`.env` is read once, at startup.** The dev watcher reloads on changes to it, but a process started by
|
|
64
|
+
hand needs restarting — and `dotenv` never overrides a variable that is already set in the environment,
|
|
65
|
+
so a value exported by your shell, IDE launch config or container silently wins. The server log names
|
|
66
|
+
what it could not resolve and says when a value is being shadowed.
|
|
67
|
+
|
|
68
|
+
Copy **all four** values from one app registration. Mixing an old `apiKey` with a new `appId` is a
|
|
69
|
+
silent failure: the request is authenticated with the key.
|
|
70
|
+
|
|
71
|
+
## The identity that gets stored
|
|
72
|
+
|
|
73
|
+
`provider` and `providerUserId` always come from the **same layer**, so the stored pair can never name a
|
|
74
|
+
namespace its id does not belong to:
|
|
75
|
+
|
|
76
|
+
| Layer | `provider` | `providerUserId` |
|
|
77
|
+
|---|---|---|
|
|
78
|
+
| `broker` | the broker (`firebase`) | the broker's own subject |
|
|
79
|
+
| `upstream` | the upstream IdP (`google`) | the upstream subject |
|
|
80
|
+
|
|
81
|
+
`auto` picks `upstream` when the login carries one and falls back to `broker` when it does not — a
|
|
82
|
+
Firebase password or phone sign-in has no upstream provider.
|
|
83
|
+
|
|
84
|
+
**Each login writes exactly one row**: the identity used. A user who signs in with Google through
|
|
85
|
+
Firebase gets `("google", <Google sub>)` — the same key the passport flow writes, so both paths converge
|
|
86
|
+
on one row. A second linked provider appears after the first login with it.
|
|
87
|
+
|
|
88
|
+
The row set **is** the connected-accounts UI: there is no separate display field.
|
|
89
|
+
|
|
90
|
+
Reading the token is deliberately conservative. Only `email_verified` addresses may be used for
|
|
91
|
+
account linking — without that gate, any provider that does not verify addresses becomes an
|
|
92
|
+
account-takeover path. And the issuer is pinned in configuration, never taken from the token: a verifier
|
|
93
|
+
that fetched the JWKS URL named by an unvalidated `iss` claim would be an SSRF gadget.
|
|
94
|
+
|
|
95
|
+
## The login page
|
|
96
|
+
|
|
97
|
+
The generated page renders one button per configured provider. The **preset** supplies the vendor
|
|
98
|
+
parts — SDK location, provider list, public env names, a browser init snippet — so nothing here names a
|
|
99
|
+
vendor and nothing needs editing in `server.ts`:
|
|
100
|
+
|
|
101
|
+
| Supplied by | What |
|
|
102
|
+
|---|---|
|
|
103
|
+
| the preset, emitted into `ExternalIdentityUI.gen.ts` | the SDK, the provider list, the init snippet |
|
|
104
|
+
| vex, in `LoginUI.gen.ts` | the buttons, the nonce'd script tags, the config carrier, and the glue that posts the ID token to `/api/auth/external` |
|
|
105
|
+
|
|
106
|
+
**The SDK comes from npm, not a CDN.** `firebase` is a dependency, and the page loads it through a
|
|
107
|
+
same-origin route (`/js/firebase/…`) whose file names are an allowlist. The version is npm's business,
|
|
108
|
+
no CDN host needs a CSP allowance, and the page works offline. The route reads `node_modules` at request
|
|
109
|
+
time because generation happens before `npm install` — run `npm install` after upgrading, or the login
|
|
110
|
+
page reports the SDK as not installed.
|
|
111
|
+
|
|
112
|
+
### popup or redirect
|
|
113
|
+
|
|
114
|
+
`popup` is the default and is what Google recommends on browsers that block third-party storage access —
|
|
115
|
+
the pending sign-in state stays in the page's own first-party storage.
|
|
116
|
+
|
|
117
|
+
`redirect` navigates the whole page. Reach for it when a popup is blocked, not to dodge the storage
|
|
118
|
+
policy: redirect has its own form of that failure, which is why Google documents
|
|
119
|
+
[best practices for `signInWithRedirect` on browsers that block third-party storage
|
|
120
|
+
access](https://firebase.google.com/docs/auth/web/redirect-best-practices). Its remedy is to serve the
|
|
121
|
+
broker's sign-in helper from your own domain; vex does not generate that proxy.
|
|
122
|
+
|
|
123
|
+
## When sign-in fails
|
|
124
|
+
|
|
125
|
+
The page expands the broker error codes that carry a meaning — `auth/unauthorized-domain` (add this
|
|
126
|
+
origin under Authentication → Settings → Authorized domains), `auth/operation-not-allowed` (enable the
|
|
127
|
+
provider under Authentication → Sign-in method), `auth/popup-blocked`, and so on — in the alert and in
|
|
128
|
+
the server log.
|
|
129
|
+
|
|
130
|
+
`auth/internal-error` names no cause by design. Its message points at the usual ones: a restricted API
|
|
131
|
+
key (Google Cloud console → APIs & Services → Credentials: the key must allow this origin under HTTP
|
|
132
|
+
referrers), an extension blocking `firebaseapp.com` / `apis.google.com`, or blocked third-party cookies.
|
|
133
|
+
For those, a request failing with `net::ERR_BLOCKED_BY_CLIENT` was never sent at all — an extension
|
|
134
|
+
blocked it.
|
|
135
|
+
|
|
136
|
+
A `GET /__/firebase/init.json 404` in the broker's own console output is expected: `/__/firebase/…` is a
|
|
137
|
+
Hosting reserved URL, and an API-only project has no Hosting site. The handler falls back to the
|
|
138
|
+
configuration in its own redirect URL.
|
|
139
|
+
|
|
140
|
+
### Works in a private window, fails in the normal profile
|
|
141
|
+
|
|
142
|
+
That combination means the configuration is right and the profile is interfering — check it before
|
|
143
|
+
touching any Firebase setting:
|
|
144
|
+
|
|
145
|
+
1. **An extension.** Private windows disable them. Look for `net::ERR_BLOCKED_BY_CLIENT`; then disable
|
|
146
|
+
all extensions and add them back one at a time.
|
|
147
|
+
2. **Stale auth state for the origin.** The SDK caches sign-in and pending-redirect state in the origin's
|
|
148
|
+
`IndexedDB` (`firebaseLocalStorageDb`), keyed by API key. After changing the key, or after a string of
|
|
149
|
+
failed attempts, it can be inconsistent. Clear site data for the app origin and for
|
|
150
|
+
`<project>.firebaseapp.com`.
|
|
151
|
+
3. **A profile-level cookie setting**, or an enterprise policy with a URL blocklist.
|
|
152
|
+
|
|
153
|
+
## Firebase: which values are used, and where
|
|
154
|
+
|
|
155
|
+
| Console section | Used? |
|
|
156
|
+
|---|---|
|
|
157
|
+
| SDK setup → npm | no bundler here, but the SDK *package* is used — see the login page section |
|
|
158
|
+
| SDK setup → CDN | no |
|
|
159
|
+
| SDK setup → 配置 (the `firebaseConfig` object) | **yes** — `apiKey`, `authDomain`, `projectId`, `appId` |
|
|
160
|
+
|
|
161
|
+
Also enable the providers you want (Authentication → Sign-in method) and keep your app's origin in the
|
|
162
|
+
authorized domains list. The app's config must come from a **Web** app registration; a mobile `appId`
|
|
163
|
+
(`…:android:…` / `…:ios:…`) is detected and reported rather than left to a network trace.
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
# v0.8.4
|
|
2
|
+
|
|
3
|
+
## Account deletion (tombstone)
|
|
4
|
+
|
|
5
|
+
Generated apps now get self-service account deletion: `POST /api/auth/delete-account` and a
|
|
6
|
+
`/delete_account` page, on by default.
|
|
7
|
+
|
|
8
|
+
The account is **soft-deleted**, not erased. The row survives so business tables can keep their
|
|
9
|
+
required foreign keys — a hard delete would orphan every `Job`, `ChatMessage` and `UserReport`
|
|
10
|
+
pointing at it — while credentials and personal data are removed.
|
|
11
|
+
|
|
12
|
+
| Step | Effect |
|
|
13
|
+
|---|---|
|
|
14
|
+
| Clear credentials | `UserAuthProfiles`, `UserRole`, `Session` rows for the user are hard-deleted |
|
|
15
|
+
| Tombstone last | `deleted: true`, `email` → NULL, `name` → `"Deleted user"`, `locale` / `profileErrors` → NULL, `active` → false |
|
|
16
|
+
|
|
17
|
+
Credentials are removed **before** the tombstone on purpose. Tombstoning first would leave the OAuth
|
|
18
|
+
path able to resolve the account through `provider` / `oauthId`, i.e. a deleted user could log back
|
|
19
|
+
into their own tombstone. Marker last also means a mid-flight failure leaves a live account that can
|
|
20
|
+
simply be retried.
|
|
21
|
+
|
|
22
|
+
`email` becomes `NULL`, never `""`: `User` declares a unique index on it, so a second deletion would
|
|
23
|
+
collide on the empty string, and the same address must be able to register a fresh account
|
|
24
|
+
immediately.
|
|
25
|
+
|
|
26
|
+
Deletion is idempotent — a repeat call changes nothing.
|
|
27
|
+
|
|
28
|
+
## Soft delete: `x-vexData: "softDelete"`
|
|
29
|
+
|
|
30
|
+
Soft delete is a general, opt-in schema feature, not a hard-coded user concept. Tag one boolean
|
|
31
|
+
property:
|
|
32
|
+
|
|
33
|
+
```jsonc
|
|
34
|
+
"deleted": { "type": "boolean", "default": false, "x-vexData": "softDelete" }
|
|
35
|
+
// and list it in the root "required" array
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
- **Not client-writable.** The marker is omitted from the generated request body (`PayloadUser`), so
|
|
39
|
+
a client cannot soft-delete, resurrect or pre-tombstone a row through the CRUD API.
|
|
40
|
+
- **Hidden by default.** The adapters add `marker IS NOT TRUE` (`$ne: true` on Mongo) to every read
|
|
41
|
+
and write filter. No call-site changes.
|
|
42
|
+
- **No new columns.** `softDelete(id, data?)` writes the marker through the normal update-phase
|
|
43
|
+
machinery, so `updatedAt` / `updatedBy` record who deleted the row and when. There is no
|
|
44
|
+
`deletedAt` / `deletedBy`.
|
|
45
|
+
- **Required + defaulted.** The marker must be `boolean`, `default: false` and `required`, producing
|
|
46
|
+
`boolean NOT NULL DEFAULT false`. A nullable marker would make the hide-filter drop every row
|
|
47
|
+
written before the column existed.
|
|
48
|
+
|
|
49
|
+
Internal callers use dedicated repository methods, never a filter key:
|
|
50
|
+
|
|
51
|
+
```ts
|
|
52
|
+
softDelete(id, data?) // write the marker + redaction in one update
|
|
53
|
+
findOneWithDeleted(filter, join, select) // skip ONLY the soft-delete term; ownership still applies
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
A soft-delete key inside `Filter<T>` was rejected deliberately: `Filter` is the shape of every HTTP
|
|
57
|
+
`filter` body, so it would have been a client-side bypass.
|
|
58
|
+
|
|
59
|
+
The hide term is **not** applied to relation loading — which is why the marker is a plain column and
|
|
60
|
+
not TypeORM's `@DeleteDateColumn`, whose relation-nulling would break retained conversations
|
|
61
|
+
rendering "Deleted user".
|
|
62
|
+
|
|
63
|
+
## Tokens of deleted accounts are rejected
|
|
64
|
+
|
|
65
|
+
`Authentication.middleware` verified the JWT signature and nothing else, so a deleted user's
|
|
66
|
+
unexpired access token kept working for the rest of its lifetime. A generated `AccountStateGuard`
|
|
67
|
+
now closes that gap.
|
|
68
|
+
|
|
69
|
+
It reads the marker **value** rather than relying on the row being hidden, so the answer holds even
|
|
70
|
+
under `app.showSoftDeleted`, where a visibility-based check would call every tombstone alive. It
|
|
71
|
+
treats a missing marker as live (`!== true`), matching the adapters.
|
|
72
|
+
|
|
73
|
+
Every other auth path was already fail-closed: refresh and the OAuth exchange look the user up
|
|
74
|
+
through a soft-filtered read, local login compares an email that is now NULL, and the OAuth callback
|
|
75
|
+
cannot re-bind because the profile rows are gone.
|
|
76
|
+
|
|
77
|
+
## Config
|
|
78
|
+
|
|
79
|
+
```jsonc
|
|
80
|
+
{
|
|
81
|
+
"app": { "showSoftDeleted": false },
|
|
82
|
+
"auth": { "deleteAccount": true }
|
|
83
|
+
}
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
- `auth.deleteAccount` — **default true** (opt-out). Also requires auth to be enabled: a deletion
|
|
87
|
+
endpoint that cannot authenticate a caller could only delete the wrong account. When false, no
|
|
88
|
+
endpoint, no service, no page.
|
|
89
|
+
- `app.showSoftDeleted` — **default false**. Lifts the adapter filter app-wide, making tombstones
|
|
90
|
+
visible and writable again. It warns on every generation run, because it is a blunt instrument: it
|
|
91
|
+
applies to every entity, including ones added later.
|
|
92
|
+
|
|
93
|
+
Both are read with `??`, so an explicit `false` is never swallowed.
|
|
94
|
+
|
|
95
|
+
## The `/delete_account` page
|
|
96
|
+
|
|
97
|
+
Served from `LoginUI` rather than as a static file — `express.static("public")` would expose
|
|
98
|
+
`public/delete_account.html` at `/delete_account.html`, not at the route a store listing points at.
|
|
99
|
+
Linked from `/`.
|
|
100
|
+
|
|
101
|
+
`LoginUIConfig.deleteAccount` is optional and defaults to true, because an app's `server.ts` is
|
|
102
|
+
generated once and is not overwritten on later runs; a required field would stop such a project from
|
|
103
|
+
compiling.
|
|
104
|
+
|
|
105
|
+
The client clears its stored tokens on success — the account is gone the moment the tombstone is
|
|
106
|
+
written, so keeping a token the server now rejects would only produce confusing 401s.
|
|
107
|
+
|
|
108
|
+
## Behaviour changes
|
|
109
|
+
|
|
110
|
+
- **Every authenticated request costs one extra indexed read** of the identity row when the identity
|
|
111
|
+
document is soft-deletable. Projects with no soft-delete marker are unaffected — the guard is
|
|
112
|
+
emitted as a no-op there.
|
|
113
|
+
- **A request carrying a soft-delete marker is rejected with `400 Invalid Request Body`**, matching
|
|
114
|
+
the existing `throw-on-extras` contract for other server-managed fields.
|
|
115
|
+
|
|
116
|
+
## After upgrading
|
|
117
|
+
|
|
118
|
+
Re-run the generator. Then:
|
|
119
|
+
|
|
120
|
+
1. **Add the column.** `useUserSchema` apps get `User.deleted` merged in automatically.
|
|
121
|
+
`SQL_SYNCHRONIZE=true` covers development; production needs
|
|
122
|
+
`ALTER TABLE "user" ADD COLUMN "deleted" boolean NOT NULL DEFAULT false`.
|
|
123
|
+
2. **Check `allowOverwrite: false`.** An app that pinned `UserModel.gen.ts` / `User.gen.ts` must add
|
|
124
|
+
the column by hand, or clear those `.vex/meta.json` entries, or the SQL column will not exist.
|
|
125
|
+
3. **Business rows and uploaded objects are the app's job.** This release covers the identity domain
|
|
126
|
+
only. Third-party identities too: vex cannot delete a Firebase account — capture the provider uid
|
|
127
|
+
*before* calling the service.
|
|
128
|
+
4. **To disable it entirely:** `"auth": { "deleteAccount": false }`.
|
|
129
|
+
|
|
130
|
+
Guides: [`docs/features/accountDeletion.md`](../features/accountDeletion.md),
|
|
131
|
+
[`docs/vexJsonSchema.md`](../vexJsonSchema.md).
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
# v0.9.0
|
|
2
|
+
|
|
3
|
+
## Breaking — `UserAuthProfiles.oauthId` → `providerUserId`
|
|
4
|
+
|
|
5
|
+
- `(provider, providerUserId)` is the account-linking key, and it now has a **composite unique index**;
|
|
6
|
+
nothing enforced it before.
|
|
7
|
+
- A schema migration renames the property; one `ALTER TABLE` renames the column.
|
|
8
|
+
|
|
9
|
+
## External identity (broker SSO) — Firebase
|
|
10
|
+
|
|
11
|
+
- `POST /api/auth/external` verifies a broker ID token against the issuer's JWKS and provisions the
|
|
12
|
+
matching vex identity. **Off by default.**
|
|
13
|
+
- Every token stays vex-issued: the broker's token is consumed at that one endpoint and never stored.
|
|
14
|
+
- No broker SDK on the server, no client secret, no new dependency.
|
|
15
|
+
- The generated login page renders the broker's buttons for you — configure it in `vex.config.json`,
|
|
16
|
+
then `npm install` (the `firebase` dependency is new).
|
|
17
|
+
- **Use a Web app's config**, all four values from the same registration.
|
|
18
|
+
- Configuration, identity rules, troubleshooting: [`docs/features/externalIdentity.md`](../features/externalIdentity.md).
|
|
19
|
+
|
|
20
|
+
## `sessionCode` is single-use
|
|
21
|
+
|
|
22
|
+
- `POST /api/auth/token` now consumes the code, instead of leaving it replayable for its whole TTL.
|
|
23
|
+
|
|
24
|
+
## Login and delete pages
|
|
25
|
+
|
|
26
|
+
- The home page shows the login link for broker-only apps, which previously had none.
|
|
27
|
+
- `/delete_account` states the sign-in prerequisite and links to `/login`.
|
|
28
|
+
- `public/js/deleteaccount.js` no longer sends an empty `Bearer ` — **new projects only**, that file is
|
|
29
|
+
copied once and not overwritten.
|
|
30
|
+
- The login page's CSP now allows the hosts a broker SDK injects at runtime.
|
|
31
|
+
|
|
32
|
+
## After upgrading
|
|
33
|
+
|
|
34
|
+
1. **`npm install`** — `firebase` is a new dependency.
|
|
35
|
+
2. **Re-run the generator**, so the schema migration renames the property.
|
|
36
|
+
3. **Rename the column and add the constraint:**
|
|
37
|
+
```sql
|
|
38
|
+
ALTER TABLE "userauthprofiles" RENAME COLUMN "oauthId" TO "providerUserId";
|
|
39
|
+
ALTER TABLE "userauthprofiles" ADD CONSTRAINT "unique_provider_providerUserId"
|
|
40
|
+
UNIQUE ("provider", "providerUserId");
|
|
41
|
+
```
|
|
42
|
+
`SQL_SYNCHRONIZE=true` covers development. If the old code let two rows claim one identity, find them
|
|
43
|
+
first: `SELECT provider, "providerUserId", COUNT(*) FROM "userauthprofiles" GROUP BY 1,2 HAVING COUNT(*) > 1;`
|
|
44
|
+
4. **Update app code** that reads `oauthId`.
|
|
45
|
+
5. **Keep `package.json` at `0.9.0` or later** — the migration runner compares the migration's label with
|
|
46
|
+
`.vex/meta.json`'s last generated version, so a lower version re-runs it on every generation.
|
|
47
|
+
|
|
48
|
+
Guides: [`docs/features/externalIdentity.md`](../features/externalIdentity.md),
|
|
49
|
+
[`docs/features/accountDeletion.md`](../features/accountDeletion.md).
|
package/package.json
CHANGED
package/vex.config.json
CHANGED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
# Auth
|
|
2
|
-
- Stateless JWT token
|
|
3
|
-
- **Rolling Keys**
|
|
4
|
-
define in `.env`,
|
|
5
|
-
named `JWT_KEY{increment}`
|
|
6
|
-
```bash
|
|
7
|
-
JWT_KEY1=aaaaa
|
|
8
|
-
JWT_KEY2=bbbbb
|
|
9
|
-
JWT_KEY3=ccccc
|
|
10
|
-
```
|
|
11
|
-
- **OAuth2**
|
|
12
|
-
Supported Providers:
|
|
13
|
-
- Google
|
|
14
|
-
- Github
|
|
15
|
-
|
|
16
|
-
define in `.env`,
|
|
17
|
-
named `OAUTH_{provider}_CLIENTID` & `OAUTH_{provider}_CLIENTSECRET`
|
|
18
|
-
```bash
|
|
19
|
-
OAUTH_GOOGLE_CLIENTID=xxxxx
|
|
20
|
-
OAUTH_GOOGLE_CLIENTSECRET=xxxxx
|
|
21
|
-
```
|
|
22
|
-
- Stated
|
|
23
|
-
- not yet implement
|