passflow 0.1.0 → 0.2.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/dist/cli.mjs +11 -7
- package/package.json +1 -1
- package/skills/REVISION +1 -1
- package/skills/passflow-node-api/SKILL.md +5 -4
- package/skills/passflow-node-api/assets/src/passflow.ts +13 -2
- package/skills/passflow-node-api/references/guardrails.md +3 -3
- package/skills/passflow-react-vite/SKILL.md +4 -3
- package/skills/passflow-react-vite/assets/server/passflow.ts +13 -2
- package/skills/passflow-react-vite/references/guardrails.md +1 -1
package/dist/cli.mjs
CHANGED
|
@@ -9,7 +9,7 @@ import { createInterface } from "node:readline/promises";
|
|
|
9
9
|
import { createServer } from "node:http";
|
|
10
10
|
import { fileURLToPath } from "node:url";
|
|
11
11
|
// package.json
|
|
12
|
-
var version = "0.
|
|
12
|
+
var version = "0.2.0";
|
|
13
13
|
// src/errors.ts
|
|
14
14
|
/** The project, or the command line, is refused before anything is created: exit 2. */
|
|
15
15
|
var Refusal = class extends Error {
|
|
@@ -1539,18 +1539,22 @@ async function provisionInCloud(options, stack, baseUrl) {
|
|
|
1539
1539
|
env
|
|
1540
1540
|
}, stack, baseUrl);
|
|
1541
1541
|
}
|
|
1542
|
+
/** One or more Passflow client IDs, comma-separated, normalised to `a,b` with no repeats. */
|
|
1543
|
+
function checkAudience(audience) {
|
|
1544
|
+
const ids = [...new Set(audience.split(",").map((id) => id.trim()).filter(Boolean))];
|
|
1545
|
+
if (ids.length === 0 || !ids.every((id) => /^[A-Za-z0-9_-]+$/.test(id))) throw new Refusal("--audience must be one or more Passflow client IDs, separated by commas.");
|
|
1546
|
+
return ids.join(",");
|
|
1547
|
+
}
|
|
1542
1548
|
async function nodeApiValues(options) {
|
|
1543
1549
|
let issuer = options.issuer;
|
|
1544
1550
|
let audience = options.audience;
|
|
1545
1551
|
if ((!issuer || !audience) && !canAsk()) throw new Refusal("a Node API gets no app of its own: pass --issuer and --audience, the issuer and the client ID of the app whose tokens it accepts.");
|
|
1546
1552
|
if (!issuer || !audience) log("A Node API gets no app of its own. It accepts the tokens of the app that signs users in.");
|
|
1547
1553
|
issuer ??= await ask("Issuer URL of that app (for example https://<key>.passflow.cloud): ");
|
|
1548
|
-
audience ??= await ask("Client ID of that app: ");
|
|
1549
|
-
const checkedIssuer = checkUrl("--issuer", issuer);
|
|
1550
|
-
if (!/^[A-Za-z0-9_-]+$/.test(audience)) throw new Refusal("--audience must be a Passflow client ID.");
|
|
1554
|
+
audience ??= await ask("Client ID of that app (several apps: separate them with commas): ");
|
|
1551
1555
|
return {
|
|
1552
|
-
issuer:
|
|
1553
|
-
clientId: audience
|
|
1556
|
+
issuer: checkUrl("--issuer", issuer),
|
|
1557
|
+
clientId: checkAudience(audience)
|
|
1554
1558
|
};
|
|
1555
1559
|
}
|
|
1556
1560
|
/** `passflow integrate`. Returns the exit code. */
|
|
@@ -1662,7 +1666,7 @@ The app:
|
|
|
1662
1666
|
--base-url <url> the app's origin, with no path (default: the stack's dev URL)
|
|
1663
1667
|
--api-url <url> React + Vite: the API's origin for VITE_API_URL (default ${defaultApiUrl})
|
|
1664
1668
|
--issuer <url> Node API: the issuer of the app whose tokens the API accepts
|
|
1665
|
-
--audience <client
|
|
1669
|
+
--audience <client ids> Node API: the client IDs of the apps whose tokens it accepts, comma-separated
|
|
1666
1670
|
|
|
1667
1671
|
Hand-off:
|
|
1668
1672
|
--agent <name> start claude, codex or cursor-agent with the prompt
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "passflow",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "The Passflow CLI. `npx passflow integrate` detects your stack, creates a Passflow app for it, writes its env file and installs the matching agent skill, so your coding agent can add Passflow sign-in.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"homepage": "https://docs.usepassflow.com",
|
package/skills/REVISION
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
5d29ad1dffba5bdeeeb61352267f722547b1879b
|
|
@@ -37,7 +37,8 @@ Check each one before you change a file. Read `package.json` and look for the fi
|
|
|
37
37
|
|
|
38
38
|
**Yarn Berry or Bun: stop.** Tell the user that this skill supports npm, pnpm and Yarn 1 only.
|
|
39
39
|
4. **Env file `.env`** at the project root, with `PASSFLOW_ISSUER` and `PASSFLOW_AUDIENCE`. You never create or edit it, and you never print its values.
|
|
40
|
-
- `
|
|
40
|
+
- `PASSFLOW_AUDIENCE` is one or more client IDs, comma-separated (`id1` or `id1,id2`): each is the client ID of a Passflow app whose access tokens this API accepts. Never an invented audience string such as `api` or a URL: no token carries it, so every token would get 401. Every app in the list gets the same access; an app that must get less needs its own verifier (see `references/guardrails.md`, rule 5).
|
|
41
|
+
- `npx passflow integrate` writes it. In a Passflow GitHub App run, the service writes `.env.example` with the public values filled in (`PASSFLOW_ISSUER`, `PASSFLOW_AUDIENCE`) and any secret empty; this stack has no secret. Leave that file as it is. If `.env` is missing or a value is empty, do not invent values: carry on with the code, and the last step tells the developer how to get them (the issuer URL, and the client ID of each Passflow app whose tokens this API accepts).
|
|
41
42
|
- In a Passflow GitHub App run there is no `.env`: that is expected. Do not look for its values.
|
|
42
43
|
- A committed `.env`: on the developer's machine, check with `git ls-files --error-unmatch .env`. If it succeeds, git tracks the file: stop. Tell the user to run `git rm --cached .env`, commit, and add `.env` to `.gitignore`. In a Passflow GitHub App run, the service refuses a repository with a committed `.env`, `.env.local` or `.env.*.local` before you start, so there is nothing to check.
|
|
43
44
|
|
|
@@ -139,7 +140,7 @@ Check each one before you change a file. Read `package.json` and look for the fi
|
|
|
139
140
|
`passflow` is exported by `passflow-express.ts` and `passflow-hono.ts`. Read the claims in a handler with `getAuth(req)` (Express), `getAuth(request)` (Fastify) or `getAuth(c)` (Hono), each imported from the same adapter path. A missing role is a plain 403 with no `WWW-Authenticate`. In Fastify, `passflowPlugin` is registered once per instance; a scope without it uses `createFastifyHooks(verifier)` from `@passflow/node/fastify`, as `assets/examples/fastify-routes.ts` shows.
|
|
140
141
|
|
|
141
142
|
5. **Tell the developer.** End with a short message that lists what they still have to do, each as a command or a line to add. Include only the items that apply:
|
|
142
|
-
- **Env values.** If `.env` is missing or a value is empty: run `npx passflow integrate`, or create `.env` with `PASSFLOW_ISSUER=` and `PASSFLOW_AUDIENCE=` from the Passflow portal (the issuer URL, and the client ID of
|
|
143
|
+
- **Env values.** If `.env` is missing or a value is empty: run `npx passflow integrate`, or create `.env` with `PASSFLOW_ISSUER=` and `PASSFLOW_AUDIENCE=` from the Passflow portal (the issuer URL, and the client ID of each app whose tokens the API accepts, comma-separated when there are several). Names only in your message, never values.
|
|
143
144
|
- **Loading `.env`.** If the app does not load it already (dotenv, `--env-file`, its framework): start Node with `--env-file=.env`, for example `node --env-file=.env dist/server.js` in the start script.
|
|
144
145
|
- **CORS package.** If a browser on another origin calls the API and the CORS package is missing: `npm install cors` (plus `npm install -D @types/cors` in a TypeScript project) for Express, or `npm install @fastify/cors` for Fastify, written for the project's package manager. Then copy the CORS asset and add the one line from step 3, before the routes.
|
|
145
146
|
- **Check.** `bash <skill>/scripts/verify.sh run --port <the API's port>`, with `--origin <a browser origin it allows>` when there is CORS, and `--api <path>` when the route is not `/api/me`.
|
|
@@ -153,7 +154,7 @@ Read `references/guardrails.md` before you edit auth code. In short:
|
|
|
153
154
|
- Check the token on every protected route, on the server.
|
|
154
155
|
- Return the library's 401 or 503 unchanged; no `next(err)`, no rewritten body.
|
|
155
156
|
- When a browser calls the API, CORS goes first and exposes `WWW-Authenticate` through `exposeChallengeHeader`. Never turn on `credentials`.
|
|
156
|
-
- Issuer and audience come from `PASSFLOW_ISSUER` and `PASSFLOW_AUDIENCE`, never hard-coded.
|
|
157
|
+
- Issuer and audience come from `PASSFLOW_ISSUER` and `PASSFLOW_AUDIENCE`, never hard-coded. `PASSFLOW_AUDIENCE` holds one or more client IDs, comma-separated, never an invented audience string.
|
|
157
158
|
- Copy Passflow calls from `assets/`, never from memory.
|
|
158
159
|
- Never print or log a token, an `Authorization` header or an env value.
|
|
159
160
|
- Add no dependency other than `@passflow/node`, edit no `package.json` script, and create or edit no `.env*` file.
|
|
@@ -180,7 +181,7 @@ Each check prints `PASS`, `FAIL` or `SKIP` (a check that does not apply, such as
|
|
|
180
181
|
|
|
181
182
|
- **`TypeError: [passflow] issuer must be a non-empty string` at startup.** `.env` was not loaded, or `PASSFLOW_ISSUER` is empty. See step 5.
|
|
182
183
|
- **Type error on `createVerifier`: `string | undefined` is not assignable to `string`.** The installed `@passflow/node` is older than the one the assets need. Run the install line again.
|
|
183
|
-
- **Every token gets 401 `invalid_token`.** `PASSFLOW_ISSUER` differs from the token's `iss` (a trailing slash counts), or `PASSFLOW_AUDIENCE` is
|
|
184
|
+
- **Every token gets 401 `invalid_token`.** `PASSFLOW_ISSUER` differs from the token's `iss` (a trailing slash counts), or no client ID in `PASSFLOW_AUDIENCE` is that of the app the token was issued for. To see why, use `explainRejection` from `assets/examples/explain-rejection.ts` for a moment: it logs the error's `code` and `reason` only. Remove it afterwards.
|
|
184
185
|
- **Every request gets 503.** The API cannot load the issuer's key set. From the API's machine, `curl -i "$PASSFLOW_ISSUER/.well-known/jwks.json"` must answer 200.
|
|
185
186
|
- **The browser sees a bare 401 and the step-up dialog never opens.** CORS does not expose `WWW-Authenticate`, or it is mounted after the routes. See step 3.
|
|
186
187
|
- **Fastify throws `FST_ERR_DEC_ALREADY_PRESENT`.** `passflowPlugin` was registered twice on one instance. Register it once; use `createFastifyHooks(verifier)` elsewhere, as in `assets/examples/fastify-routes.ts`.
|
|
@@ -2,9 +2,20 @@ import { createVerifier } from '@passflow/node';
|
|
|
2
2
|
|
|
3
3
|
// One verifier per trust policy, built once at startup. It owns the key cache.
|
|
4
4
|
// PASSFLOW_ISSUER is matched exactly against the token's `iss`.
|
|
5
|
-
// PASSFLOW_AUDIENCE is
|
|
5
|
+
// PASSFLOW_AUDIENCE is one client ID, or several joined with commas: each is the client ID of a Passflow app
|
|
6
|
+
// whose access tokens this API accepts.
|
|
6
7
|
// A missing value throws a TypeError when this module loads.
|
|
7
8
|
export const verifier = createVerifier({
|
|
8
9
|
issuer: process.env.PASSFLOW_ISSUER,
|
|
9
|
-
audience: process.env.PASSFLOW_AUDIENCE,
|
|
10
|
+
audience: clientIds(process.env.PASSFLOW_AUDIENCE),
|
|
10
11
|
});
|
|
12
|
+
|
|
13
|
+
// Splits a comma-separated list of client IDs, trims each and drops empty entries. Nothing left counts as
|
|
14
|
+
// missing.
|
|
15
|
+
function clientIds(value: string | undefined): string[] | undefined {
|
|
16
|
+
const ids = (value ?? '')
|
|
17
|
+
.split(',')
|
|
18
|
+
.map((id) => id.trim())
|
|
19
|
+
.filter((id) => id !== '');
|
|
20
|
+
return ids.length > 0 ? ids : undefined;
|
|
21
|
+
}
|
|
@@ -32,9 +32,9 @@ Read this before you edit any auth code in the API. Each rule says what to do, w
|
|
|
32
32
|
|
|
33
33
|
## 5. Configuration comes from the environment
|
|
34
34
|
|
|
35
|
-
- **Rule:** the issuer and the audience come from `PASSFLOW_ISSUER` and `PASSFLOW_AUDIENCE`. Nothing Passflow-specific is hard-coded.
|
|
36
|
-
- **Why:** each environment (local, staging, production) has its own issuer and
|
|
37
|
-
- **Instead:** keep `src/passflow.ts` as the asset has it. Build one verifier at startup and share it.
|
|
35
|
+
- **Rule:** the issuer and the audience come from `PASSFLOW_ISSUER` and `PASSFLOW_AUDIENCE`. Nothing Passflow-specific is hard-coded. `PASSFLOW_AUDIENCE` is one or more client IDs, comma-separated: each is the client ID of a Passflow app whose access tokens this API accepts, never an invented audience string such as `api` or a URL.
|
|
36
|
+
- **Why:** each environment (local, staging, production) has its own issuer and apps. A hard-coded value ships the wrong one, or mixes them. An access token carries its app's client ID as `aud`, so an invented audience matches no token and every call gets 401.
|
|
37
|
+
- **Instead:** keep `src/passflow.ts` as the asset has it: it splits `PASSFLOW_AUDIENCE` on commas and passes the list to the verifier. Build one verifier at startup and share it. To accept another app's tokens, add its client ID to the list. Every app in `PASSFLOW_AUDIENCE` gets the same access: the verifier accepts a token whose `aud` holds any listed ID and checks neither `azp` nor `client_id`. When one app must get less, give it its own verifier with only its client ID, and protect its routes with that. A handler can tell apps apart by the token's `aud` claim (a `string[]`).
|
|
38
38
|
- **Checked:** no.
|
|
39
39
|
|
|
40
40
|
## 6. Copy SDK calls from `assets/`, never from memory
|
|
@@ -46,10 +46,11 @@ Check each one before you change a file. Read the `package.json` files and look
|
|
|
46
46
|
| `VITE_PASSFLOW_APP_ID` | SPA | The SPA app's client ID. Public. |
|
|
47
47
|
| `VITE_API_URL` | SPA | The API's origin as the browser calls it. |
|
|
48
48
|
| `PASSFLOW_ISSUER` | API | The same issuer URL as `VITE_PASSFLOW_URL`. |
|
|
49
|
-
| `PASSFLOW_AUDIENCE` | API | The SPA app's client ID: the same value as `VITE_PASSFLOW_APP_ID`. |
|
|
49
|
+
| `PASSFLOW_AUDIENCE` | API | The SPA app's client ID: the same value as `VITE_PASSFLOW_APP_ID`. A comma-separated list when the API also accepts other apps' tokens. |
|
|
50
50
|
| `APP_BASE_URL` | API | The SPA's origin, for example `http://localhost:5173`, with no path, query or fragment: an SPA served under a sub-path is not supported, and `npx passflow integrate` refuses a `--base-url` with a path. It is the origin the API's CORS allows. |
|
|
51
51
|
|
|
52
52
|
- `PASSFLOW_AUDIENCE` is the SPA app's client ID, because the access tokens the SPA gets carry `aud = [app ID]`. Never invent an audience string such as `api` or a URL: every token would then get 401.
|
|
53
|
+
- When the API also accepts the access tokens of other Passflow apps, `PASSFLOW_AUDIENCE` is a comma-separated list of client IDs (`spa-id,other-id`) that includes the SPA's. Each entry is an app's client ID, never an invented string. Every app in the list gets the same access to the API.
|
|
53
54
|
- `VITE_API_URL` is not provisioned. When it is absent, the CLI writes `http://localhost:8086`, or the origin given to its `--api-url` flag. The developer sets it to the real API origin in each environment.
|
|
54
55
|
- Nothing secret goes in a `VITE_` variable. Vite puts every `VITE_` value into the browser bundle. The SPA needs no secret, and this stack has none.
|
|
55
56
|
- If `.env.local` is missing or a value is empty, do not invent values: carry on with the code, and the last step tells the developer how to get them.
|
|
@@ -185,7 +186,7 @@ Read `references/guardrails.md` before you edit auth code. In short:
|
|
|
185
186
|
|
|
186
187
|
- Nothing secret in a `VITE_` variable: Vite ships every one to the browser.
|
|
187
188
|
- The API checks the token on every protected route. Hiding a page in the SPA protects nothing.
|
|
188
|
-
- `PASSFLOW_AUDIENCE` is the SPA app's client ID, the same value as `VITE_PASSFLOW_APP_ID
|
|
189
|
+
- `PASSFLOW_AUDIENCE` is the SPA app's client ID, the same value as `VITE_PASSFLOW_APP_ID`, or a comma-separated list of client IDs that includes it. Never invent one.
|
|
189
190
|
- Tokens go to the API's origin only, through `useApi()`. Never build an `Authorization` header by hand, and never send the token to another origin.
|
|
190
191
|
- Verify tokens on the API with `createVerifier`; never decode one by hand, in the SPA or the API.
|
|
191
192
|
- CORS goes first on the API, allows the SPA's origin only, and exposes `WWW-Authenticate` through `exposeChallengeHeader`. Never turn on `credentials`.
|
|
@@ -216,7 +217,7 @@ Each check prints `PASS`, `FAIL` or `SKIP` (a check that does not apply, such as
|
|
|
216
217
|
|
|
217
218
|
- **The page is blank and the console says `VITE_PASSFLOW_URL and VITE_PASSFLOW_APP_ID must be set in .env.local`** (or `VITE_API_URL`). The value was missing when Vite started or built. Fill in `.env.local`, then restart `npm run dev` or build again.
|
|
218
219
|
- **Passflow shows "redirect_uri not registered for this client".** The app's redirect URLs lack the SPA's root URL, or the SPA runs on another origin or port than `APP_BASE_URL`. Add `<origin>/` to the app's redirect URLs, or open the SPA on the registered origin.
|
|
219
|
-
- **Every API call gets 401 `invalid_token`.** `PASSFLOW_AUDIENCE` is not the SPA app's client ID, or `PASSFLOW_ISSUER` differs from the token's `iss` (a trailing slash counts).
|
|
220
|
+
- **Every API call gets 401 `invalid_token`.** `PASSFLOW_AUDIENCE` is not, or does not include, the SPA app's client ID, or `PASSFLOW_ISSUER` differs from the token's `iss` (a trailing slash counts). `PASSFLOW_ISSUER` must equal `VITE_PASSFLOW_URL`, and `PASSFLOW_AUDIENCE` must be or include `VITE_PASSFLOW_APP_ID`.
|
|
220
221
|
- **The API call has no `Authorization` header.** The request did not go through `useApi()`, its URL is not on `VITE_API_URL`'s origin, or no user is signed in.
|
|
221
222
|
- **The browser reports a CORS error.** `APP_BASE_URL` does not match the origin the SPA runs on, CORS is mounted after the routes, or the API has no CORS at all. See step 6.
|
|
222
223
|
- **`TypeError: [passflow] issuer must be a non-empty string` when the API starts.** The API did not load `.env.local`. See step 8.
|
|
@@ -3,13 +3,24 @@ import { createVerifier } from '@passflow/node';
|
|
|
3
3
|
// One verifier per trust policy, built once at startup. It owns the key cache.
|
|
4
4
|
// PASSFLOW_ISSUER is matched exactly against the token's `iss`; it is the same URL as VITE_PASSFLOW_URL.
|
|
5
5
|
// PASSFLOW_AUDIENCE is the SPA app's client ID, the same value as VITE_PASSFLOW_APP_ID: the access tokens the
|
|
6
|
-
// SPA sends carry aud = [app ID].
|
|
6
|
+
// SPA sends carry aud = [app ID]. When the API also accepts the tokens of other Passflow apps, it is a
|
|
7
|
+
// comma-separated list of client IDs that includes the SPA's.
|
|
7
8
|
// A missing value throws a TypeError when this module loads.
|
|
8
9
|
export const verifier = createVerifier({
|
|
9
10
|
issuer: process.env.PASSFLOW_ISSUER,
|
|
10
|
-
audience: process.env.PASSFLOW_AUDIENCE,
|
|
11
|
+
audience: clientIds(process.env.PASSFLOW_AUDIENCE),
|
|
11
12
|
});
|
|
12
13
|
|
|
14
|
+
// Splits a comma-separated list of client IDs, trims each and drops empty entries. Nothing left counts as
|
|
15
|
+
// missing.
|
|
16
|
+
function clientIds(value: string | undefined): string[] | undefined {
|
|
17
|
+
const ids = (value ?? '')
|
|
18
|
+
.split(',')
|
|
19
|
+
.map((id) => id.trim())
|
|
20
|
+
.filter((id) => id !== '');
|
|
21
|
+
return ids.length > 0 ? ids : undefined;
|
|
22
|
+
}
|
|
23
|
+
|
|
13
24
|
// The SPA's origin, the one origin the API's CORS allows. APP_BASE_URL is the SPA's URL, for example
|
|
14
25
|
// http://localhost:5173.
|
|
15
26
|
const appBaseUrl = process.env.APP_BASE_URL;
|
|
@@ -20,7 +20,7 @@ This stack keeps the user's tokens in browser storage. That is how `@passflow/re
|
|
|
20
20
|
|
|
21
21
|
## 3. `PASSFLOW_AUDIENCE` is the SPA app's client ID
|
|
22
22
|
|
|
23
|
-
- **Rule:** the API's `PASSFLOW_AUDIENCE` has the same value as `VITE_PASSFLOW_APP_ID`, and `PASSFLOW_ISSUER` the same as `VITE_PASSFLOW_URL`.
|
|
23
|
+
- **Rule:** the API's `PASSFLOW_AUDIENCE` has the same value as `VITE_PASSFLOW_APP_ID`, and `PASSFLOW_ISSUER` the same as `VITE_PASSFLOW_URL`. When the API also accepts the access tokens of other Passflow apps, `PASSFLOW_AUDIENCE` is a comma-separated list of client IDs that includes `VITE_PASSFLOW_APP_ID`; each entry is an app's client ID.
|
|
24
24
|
- **Why:** the access tokens the SPA gets carry `aud = [app ID]`. An invented audience (`api`, a URL) matches no token, so every call gets 401.
|
|
25
25
|
- **Instead:** take both values from the env file the developer filled in. If one is missing, tell the developer; never make one up.
|
|
26
26
|
- **Checked:** no. A wrong value shows as 401 `invalid_token` on every signed-in call.
|