very-express 0.9.0-alpha → 0.9.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/AGENTS.md +24 -10
- package/dist/index.js +747 -969
- package/dist/templates/_middlewares/Authentication.ts +0 -3
- package/dist/templates/_middlewares/UserContext.ts +1 -18
- package/dist/templates/_projectSettings/env +13 -12
- package/dist/templates/_projectSettings/package.json +2 -2
- package/dist/templates/_routes/FirebaseAuthUI.gen.ts +20 -0
- package/dist/templates/_routes/LoginUI.ts +293 -242
- package/dist/templates/_services/TypeOrmRepositoryAdapter.ts +0 -6
- package/dist/templates/_services/VexDbConnector.ts +1 -26
- package/dist/templates/_services/auth/JWTService.ts +0 -15
- package/dist/templates/_types/auth.ts +12 -8
- package/dist/templates/_utils/hash.ts +0 -16
- package/dist/templates/root/public/js/deleteaccount.js +0 -54
- package/docs/appGenerated/auth.md +84 -0
- package/docs/architecture/authAndRouting.md +1 -1
- package/docs/architecture/databaseTargets.md +4 -2
- package/docs/features/accountDeletion.md +2 -3
- package/docs/features/auditFields.md +2 -2
- package/docs/releaseNote/v0-8-5.md +98 -0
- package/docs/releaseNote/v0-9-0.md +41 -47
- package/docs/superpowers/specs/2026-09-22-usercontext-audit-enforcement-design.md +9 -9
- package/docs/vexJsonSchema.md +17 -0
- package/package.json +1 -1
- package/vex.config.json +1 -6
- package/dist/templates/_routes/ExternalIdentityUI.gen.ts +0 -20
- package/dist/templates/root/public/js/externallogin.js +0 -133
- package/docs/features/auth.md +0 -34
- package/docs/features/externalIdentity.md +0 -163
- /package/docs/{ForeignKey.md → features/ForeignKey.md} +0 -0
- /package/docs/{apiUsage.md → features/apiUsage.md} +0 -0
|
@@ -8,7 +8,7 @@ Branch: TBD
|
|
|
8
8
|
|
|
9
9
|
`createdBy` / `createdAt` 这类审计字段在生成的应用里**静默留下 NULL**,且没有任何信号。
|
|
10
10
|
|
|
11
|
-
|
|
11
|
+
生产项目的实测现场:
|
|
12
12
|
|
|
13
13
|
- 23/24 个 schema 声明了 `createdBy` / `updatedBy`(`onCreateUserId` / `onUpdateUserId`)
|
|
14
14
|
- 只有 `User` 一个声明了 `dataIsolation`
|
|
@@ -67,7 +67,7 @@ if (useAuth) {
|
|
|
67
67
|
|
|
68
68
|
改为 fail-loud 即推翻此契约,文档必须同步。
|
|
69
69
|
|
|
70
|
-
### 2.4
|
|
70
|
+
### 2.4 触发路径证明(生产项目实测)
|
|
71
71
|
|
|
72
72
|
```
|
|
73
73
|
$ grep -rln "DataIsolationContext.middleware" src/system/_controllers/ | wc -l
|
|
@@ -211,7 +211,7 @@ UserContext.run(tokenData, () => next());
|
|
|
211
211
|
- `:55` 的 `DataIsolationContext` 可选 import 删除
|
|
212
212
|
- 不再生成独立的上下文中间件 —— `UserContext` 从 middleware 降级为 helper 模块(只剩 `run()` / `getStore()` / `userId`)
|
|
213
213
|
|
|
214
|
-
**为什么这是从构造上消除挂载门**:`Authentication.middleware` 本来就挂在每个 `useAuth` 的 controller 上(生成 18 个 +
|
|
214
|
+
**为什么这是从构造上消除挂载门**:`Authentication.middleware` 本来就挂在每个 `useAuth` 的 controller 上(生成 18 个 + 应用手写 17 个里的 14 个)。没有第二处需要记得挂的装饰器,就没有「忘了挂」这一态。
|
|
215
215
|
|
|
216
216
|
### 4.4 Adapter 强制规则
|
|
217
217
|
|
|
@@ -338,9 +338,9 @@ Mongoose `replace` 与其余三者行为不一致。本 spec 接受,但要求
|
|
|
338
338
|
|
|
339
339
|
**代价(明确接受)**:**没有逃生口**。任何处于请求链之外的写(seed、后台 job、tsoa 注册路径)都无法声明身份,只能硬失败或静默 NULL。
|
|
340
340
|
|
|
341
|
-
|
|
341
|
+
**影响面(生产项目实测)**:`VexDb.getRepository(...)` 构造点 79 处,其中写路径 19 处(4 处直连写 + 15 处 `this.repo`)。选 ALS 路线意味着这 79 处**零改动**。
|
|
342
342
|
|
|
343
|
-
|
|
343
|
+
**已识别的硬冲突**:某应用的注册路径在**无 auth** 的 controller 里 create `User`:
|
|
344
344
|
|
|
345
345
|
| 位置 | 装饰器 |
|
|
346
346
|
|---|---|
|
|
@@ -391,11 +391,11 @@ const user = await this.userRepo.create({ name: email.split("@")[0], email, acti
|
|
|
391
391
|
|
|
392
392
|
### 6.1 注册路径(高)
|
|
393
393
|
|
|
394
|
-
见 D2
|
|
394
|
+
见 D2。当前该应用安全,但依赖「`User` 没有 `createdBy`」这一巧合。必须在 D2 的 A/B/C 中做出选择后才能认为风险闭环。
|
|
395
395
|
|
|
396
396
|
### 6.2 请求链外的写入(中)
|
|
397
397
|
|
|
398
|
-
`src/services/*`
|
|
398
|
+
`src/services/*` 中的写路径无请求上下文。实测:
|
|
399
399
|
|
|
400
400
|
| 位置 | 写入 | 该实体是否有 `onCreateUserId` |
|
|
401
401
|
|---|---|---|
|
|
@@ -445,9 +445,9 @@ const user = await this.userRepo.create({ name: email.split("@")[0], email, acti
|
|
|
445
445
|
| 删除生成的 `@Middlewares(DataIsolationContext.middleware)` | 破坏性(生成物) | 下游需重新 `vex`;旧的 `DataIsolationContext.gen.ts` 会被 `cleanupStaleFiles()` 清理 |
|
|
446
446
|
| `pipeline` 生成 `UserContext.gen.ts` | 新增 | — |
|
|
447
447
|
| 数据隔离功能 | 无变化 | 覆盖面顺带扩大(所有 authed controller) |
|
|
448
|
-
| **数据隔离第一次真正生效** | **破坏性(下游可见)** | `entityIsolation` 里的实体,此前若其 controller 没挂中间件就不过滤;改后任何 authed controller 访问它都会过滤。`mergeFilter` 是 `{ ...mapped, ...ownership }`,**ownership 覆盖调用方 filter 的 `_id`** → 按 id 查/改的接口会静默变成「操作自己那一行」。**这是各 app 自己的接口问题,修复不在本卡范围**
|
|
448
|
+
| **数据隔离第一次真正生效** | **破坏性(下游可见)** | `entityIsolation` 里的实体,此前若其 controller 没挂中间件就不过滤;改后任何 authed controller 访问它都会过滤。`mergeFilter` 是 `{ ...mapped, ...ownership }`,**ownership 覆盖调用方 filter 的 `_id`** → 按 id 查/改的接口会静默变成「操作自己那一行」。**这是各 app 自己的接口问题,修复不在本卡范围** |
|
|
449
449
|
|
|
450
|
-
**迁移**:下游跑一次 `vex`。历史 NULL 行**不会**被回填 —— 需要各应用自行决定值(`createdBy`
|
|
450
|
+
**迁移**:下游跑一次 `vex`。历史 NULL 行**不会**被回填 —— 需要各应用自行决定值(`createdBy` 有些可由关系推导,有些应用的 owner 是 profile 行而 `createdBy` 语义是 `User`,推不出来)。
|
|
451
451
|
|
|
452
452
|
## 8. 测试计划
|
|
453
453
|
|
package/docs/vexJsonSchema.md
CHANGED
|
@@ -69,8 +69,25 @@ Each `.json` file defines one REST resource. Filename must match `x-documentConf
|
|
|
69
69
|
| `ObjectId` | MongoDB ObjectId (mongo mode) |
|
|
70
70
|
| `UnixTimestamp` | Integer epoch **seconds** (SQL: `bigint`) |
|
|
71
71
|
| `Timestamp` | ISO-8601 datetime (SQL: `timestamptz`, mapped back to an ISO string) |
|
|
72
|
+
| `Binary` | Binary payload (SQL: `bytea`). The API reads and writes a **base64 string**. |
|
|
72
73
|
| `enum` | Enum field — pair with `enum` array |
|
|
73
74
|
|
|
75
|
+
#### Binary fields (`x-format: "Binary"`)
|
|
76
|
+
|
|
77
|
+
```jsonc
|
|
78
|
+
"data": { "type": "string", "x-format": "Binary", "description": "base64-encoded payload" }
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
The column is `bytea`; the entity property and the generated API types stay `string`. A TypeORM
|
|
82
|
+
transformer converts `string → Buffer` on write and `Buffer → base64 string` on read, so JSON
|
|
83
|
+
responses and request bodies always carry base64 text. Requirements:
|
|
84
|
+
|
|
85
|
+
- `type` must be `string` — any other type is rejected at generation time.
|
|
86
|
+
- The transformer does not validate the text, and the generator emits no `pattern` check; `Buffer.from(v, "base64")` ignores invalid characters. Validate base64 in the client, or in a hand-written check.
|
|
87
|
+
- `maxLength` has no effect on a binary column — the delivered size is checked by the app, not the generator.
|
|
88
|
+
- Set `express.json({ limit })` in the app when uploads exceed the 100 kB body-parser default.
|
|
89
|
+
- In mongo mode the field is a plain `String` column holding the same base64 text.
|
|
90
|
+
|
|
74
91
|
### `x-vexData` values
|
|
75
92
|
|
|
76
93
|
| Value | Description |
|
package/package.json
CHANGED
package/vex.config.json
CHANGED
|
@@ -16,15 +16,10 @@
|
|
|
16
16
|
"localAuth": true,
|
|
17
17
|
"useHttpOnlyCookieToken": true,
|
|
18
18
|
"deleteAccount": true,
|
|
19
|
+
"firebase": true,
|
|
19
20
|
"oauthProviders": {
|
|
20
21
|
"google": false,
|
|
21
22
|
"github": false
|
|
22
|
-
},
|
|
23
|
-
"externalIdentity": {
|
|
24
|
-
"enabled": true,
|
|
25
|
-
"preset": "firebase",
|
|
26
|
-
"projectId": "renomaster-c36d6",
|
|
27
|
-
"signInMethod": "redirect"
|
|
28
23
|
}
|
|
29
24
|
},
|
|
30
25
|
"useRBAC": {
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
// {{headerComment}}
|
|
2
|
-
import type { ExternalIdentityUI } from "./LoginUI.gen";
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Test/compile-time stand-in for the generated login-page wiring.
|
|
6
|
-
*
|
|
7
|
-
* **In a generated app this file is overwritten by the generator**, which emits either the resolved
|
|
8
|
-
* `auth.externalIdentity` settings or `undefined` when the feature is off. It lives in the template
|
|
9
|
-
* directory so that `LoginUI.ts`'s unconditional import resolves in this repo — the import has to be
|
|
10
|
-
* unconditional because the default is how the configuration reaches the login page without editing
|
|
11
|
-
* the app-owned `server.ts`.
|
|
12
|
-
*
|
|
13
|
-
* `let` plus a setter rather than a `const`, so the unit tests can vary what the generator "emitted".
|
|
14
|
-
* The generated version is a plain `const`; nothing in the app calls the setter.
|
|
15
|
-
*/
|
|
16
|
-
export let externalIdentityUI: ExternalIdentityUI | undefined = undefined;
|
|
17
|
-
|
|
18
|
-
export function setExternalIdentityUI(ui: ExternalIdentityUI | undefined): void {
|
|
19
|
-
externalIdentityUI = ui;
|
|
20
|
-
}
|
|
@@ -1,133 +0,0 @@
|
|
|
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
|
-
});
|
package/docs/features/auth.md
DELETED
|
@@ -1,34 +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
|
-
- **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).
|
|
@@ -1,163 +0,0 @@
|
|
|
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.
|
|
File without changes
|
|
File without changes
|