@passflow/node 0.1.1 → 0.1.3
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 +28 -21
- package/dist/express.cjs +2 -2
- package/dist/express.mjs +2 -2
- package/dist/fastify.cjs +2 -2
- package/dist/fastify.mjs +2 -2
- package/dist/hono.cjs +1 -2
- package/dist/hono.mjs +1 -2
- package/dist/index.d.cts +6 -2
- package/dist/index.d.mts +6 -2
- package/package.json +6 -6
package/README.md
CHANGED
|
@@ -21,7 +21,7 @@ app.get('/invoices', passflow.requireACR(AAL2), (req, res) => res.json({ sub: ge
|
|
|
21
21
|
app.post('/transfers', passflow.requireFresh(300), (_req, res) => res.json({ ok: true }));
|
|
22
22
|
```
|
|
23
23
|
|
|
24
|
-
`audience` is the ID of a Passflow application, or a list of them. The Passflow documentation has step-by-step tutorials for Express, Fastify and Hono (
|
|
24
|
+
`audience` is the ID of a Passflow application, or a list of them. The Passflow documentation has step-by-step tutorials for Express, Fastify and Hono ([Protect a Node API](https://docs.usepassflow.com/get-started/node-api)) and a runnable API in [`examples/resource-server`](https://github.com/usepassflow/go/tree/main/examples/resource-server).
|
|
25
25
|
|
|
26
26
|
## Use it with a framework
|
|
27
27
|
|
|
@@ -71,13 +71,13 @@ app.get('/invoices', passflow.requireACR(AAL2), (c) => c.json({ subject: getAuth
|
|
|
71
71
|
|
|
72
72
|
## Responses and CORS
|
|
73
73
|
|
|
74
|
-
| Situation
|
|
75
|
-
|
|
76
|
-
| No token, or not a `Bearer` token | 401
|
|
77
|
-
| Invalid or expired token
|
|
78
|
-
| Token below the required level
|
|
79
|
-
| Authentication too old
|
|
80
|
-
| Key set unavailable
|
|
74
|
+
| Situation | Status | `WWW-Authenticate` |
|
|
75
|
+
| --------------------------------- | ------ | ----------------------------------------------------------------- |
|
|
76
|
+
| No token, or not a `Bearer` token | 401 | `Bearer` |
|
|
77
|
+
| Invalid or expired token | 401 | `Bearer error="invalid_token"` |
|
|
78
|
+
| Token below the required level | 401 | `Bearer error="insufficient_user_authentication", acr_values="2"` |
|
|
79
|
+
| Authentication too old | 401 | `Bearer error="insufficient_user_authentication", max_age=300` |
|
|
80
|
+
| Key set unavailable | 503 | none |
|
|
81
81
|
|
|
82
82
|
Every rejection has `Cache-Control: no-store` and an empty body, and the middleware writes it directly, so your own error handler cannot drop the challenge. The browser SDK acts only on the step-up challenge, and the library never sends one for an authentication failure. Nothing from the token, the request or the key set URL appears in any error or response, and the package writes no logs.
|
|
83
83
|
|
|
@@ -102,12 +102,19 @@ app.use(cors(exposeChallengeHeader({ origin: 'https://app.example.com', credenti
|
|
|
102
102
|
|
|
103
103
|
```ts
|
|
104
104
|
type PassflowClaims = {
|
|
105
|
-
sub: string;
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
105
|
+
sub: string;
|
|
106
|
+
iss: string;
|
|
107
|
+
aud: string[];
|
|
108
|
+
exp: number;
|
|
109
|
+
iat?: number;
|
|
110
|
+
authTime?: number; // whole Unix seconds; absent when the claim is absent, not a number or beyond ±2^53
|
|
111
|
+
acr: string; // '0' when the claim is absent or not a string
|
|
112
|
+
amr: string[];
|
|
113
|
+
scopes: string[];
|
|
114
|
+
sid?: string;
|
|
115
|
+
type: string;
|
|
109
116
|
tenants: Record<string, TenantMembership>;
|
|
110
|
-
verifiedAt: number;
|
|
117
|
+
verifiedAt: number; // the verifier's clock at verification, in Unix seconds
|
|
111
118
|
raw: Record<string, unknown>;
|
|
112
119
|
};
|
|
113
120
|
```
|
|
@@ -118,20 +125,20 @@ type PassflowClaims = {
|
|
|
118
125
|
|
|
119
126
|
```js
|
|
120
127
|
createVerifier({
|
|
121
|
-
issuer: 'https://auth.example.com',
|
|
128
|
+
issuer: 'https://auth.example.com', // required, exact match
|
|
122
129
|
audience: ['7f3a9c21d4b8e6', 'b81e4d07a39c52'], // required: a string or a list; the token must name at least one
|
|
123
130
|
jwksUrl: 'https://auth.example.com/.well-known/jwks.json', // this is the default; OIDC discovery is not fetched
|
|
124
131
|
allowInsecureJwksUrl: false, // https is required except on loopback hosts, unless this is set
|
|
125
|
-
leewaySeconds: 30,
|
|
132
|
+
leewaySeconds: 30, // exp and nbf only
|
|
126
133
|
tokenTypes: ['access'],
|
|
127
134
|
now: () => new Date(),
|
|
128
135
|
jwks: {
|
|
129
|
-
maxAge: 600000,
|
|
136
|
+
maxAge: 600000, // ms; a set older than this keeps answering while it reloads in the background
|
|
130
137
|
minRefreshInterval: 30000, // ms; at most one attempt per interval for a background reload, after a failure or for an unknown kid
|
|
131
|
-
maxStale: 3600000,
|
|
132
|
-
maxBytes: 1048576,
|
|
133
|
-
timeout: 5000,
|
|
134
|
-
fetch,
|
|
138
|
+
maxStale: 3600000, // ms; how long after the last successful fetch a stale set is trusted
|
|
139
|
+
maxBytes: 1048576, // response body cap
|
|
140
|
+
timeout: 5000, // ms, an integer up to 2147483647
|
|
141
|
+
fetch, // replaces the global fetch, for proxies
|
|
135
142
|
},
|
|
136
143
|
});
|
|
137
144
|
```
|
|
@@ -162,7 +169,7 @@ await app.register(async (scope) => {
|
|
|
162
169
|
|
|
163
170
|
## Key set behaviour
|
|
164
171
|
|
|
165
|
-
The key set is fetched and cached by this package, with the same rules and defaults as the Go library `github.com/
|
|
172
|
+
The key set is fetched and cached by this package, with the same rules and defaults as the Go library `github.com/usepassflow/go/auth`, though the Go options are `time.Duration` values and these are milliseconds.
|
|
166
173
|
|
|
167
174
|
- A token's key is looked up by `kid` and the key type its algorithm requires. An unknown `kid` causes at most one refetch per `minRefreshInterval`, and a bad signature never causes one. The request with the unknown `kid` waits for that refetch, or joins one already running, and one verification never makes two fetches.
|
|
168
175
|
- A set older than `maxAge` answers immediately and starts a background reload, unless one is running or `minRefreshInterval` has not passed since the last attempt. A request waits for a reload only when there is no set, or the set is past `maxStale`.
|
package/dist/express.cjs
CHANGED
|
@@ -2,8 +2,8 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
|
2
2
|
const require_evaluate = require("./evaluate-C20MecTf.cjs");
|
|
3
3
|
// src/express.ts
|
|
4
4
|
/** Written directly and never through `next(err)`: a custom error handler would drop `WWW-Authenticate`. */
|
|
5
|
-
function send(res,
|
|
6
|
-
|
|
5
|
+
function send(res, rejection) {
|
|
6
|
+
res.status(rejection.status).set(rejection.headers).end();
|
|
7
7
|
}
|
|
8
8
|
/**
|
|
9
9
|
* Express 4 and 5 middleware. `authenticate` always verifies the presented token and replaces any claims on the
|
package/dist/express.mjs
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { a as guard, d as withChallengeHeader, n as assertVerifier, s as PassflowUsageError, t as assertRequirement } from "./evaluate-BTuol-Oa.mjs";
|
|
2
2
|
// src/express.ts
|
|
3
3
|
/** Written directly and never through `next(err)`: a custom error handler would drop `WWW-Authenticate`. */
|
|
4
|
-
function send(res,
|
|
5
|
-
|
|
4
|
+
function send(res, rejection) {
|
|
5
|
+
res.status(rejection.status).set(rejection.headers).end();
|
|
6
6
|
}
|
|
7
7
|
/**
|
|
8
8
|
* Express 4 and 5 middleware. `authenticate` always verifies the presented token and replaces any claims on the
|
package/dist/fastify.cjs
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
2
|
const require_evaluate = require("./evaluate-C20MecTf.cjs");
|
|
3
3
|
// src/fastify.ts
|
|
4
|
-
function send(reply,
|
|
5
|
-
|
|
4
|
+
function send(reply, rejection) {
|
|
5
|
+
reply.code(rejection.status).headers(rejection.headers).send();
|
|
6
6
|
}
|
|
7
7
|
/**
|
|
8
8
|
* Hooks for one verifier, with no plugin and no decoration, callable any number of times: the way to use a second
|
package/dist/fastify.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { a as guard, d as withChallengeHeader, n as assertVerifier, s as PassflowUsageError, t as assertRequirement } from "./evaluate-BTuol-Oa.mjs";
|
|
2
2
|
// src/fastify.ts
|
|
3
|
-
function send(reply,
|
|
4
|
-
|
|
3
|
+
function send(reply, rejection) {
|
|
4
|
+
reply.code(rejection.status).headers(rejection.headers).send();
|
|
5
5
|
}
|
|
6
6
|
/**
|
|
7
7
|
* Hooks for one verifier, with no plugin and no decoration, callable any number of times: the way to use a second
|
package/dist/hono.cjs
CHANGED
|
@@ -2,8 +2,7 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
|
2
2
|
const require_evaluate = require("./evaluate-C20MecTf.cjs");
|
|
3
3
|
// src/hono.ts
|
|
4
4
|
/** `c.body` rather than a thrown HTTPException, so headers `hono/cors` already set survive the rejection. */
|
|
5
|
-
function send(c,
|
|
6
|
-
const { status, headers } = decision;
|
|
5
|
+
function send(c, { status, headers }) {
|
|
7
6
|
return c.body(null, status, headers);
|
|
8
7
|
}
|
|
9
8
|
/**
|
package/dist/hono.mjs
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import { a as guard, d as withChallengeHeader, n as assertVerifier, s as PassflowUsageError, t as assertRequirement } from "./evaluate-BTuol-Oa.mjs";
|
|
2
2
|
// src/hono.ts
|
|
3
3
|
/** `c.body` rather than a thrown HTTPException, so headers `hono/cors` already set survive the rejection. */
|
|
4
|
-
function send(c,
|
|
5
|
-
const { status, headers } = decision;
|
|
4
|
+
function send(c, { status, headers }) {
|
|
6
5
|
return c.body(null, status, headers);
|
|
7
6
|
}
|
|
8
7
|
/**
|
package/dist/index.d.cts
CHANGED
|
@@ -83,6 +83,10 @@ type Decision = {
|
|
|
83
83
|
status: 401 | 500 | 503;
|
|
84
84
|
headers: Record<string, string>;
|
|
85
85
|
};
|
|
86
|
+
/** A rejected `Decision`: a `ResponseInit` as it stands (`new Response(null, rejection)`). */
|
|
87
|
+
type Rejection = Extract<Decision, {
|
|
88
|
+
kind: 'reject';
|
|
89
|
+
}>;
|
|
86
90
|
/**
|
|
87
91
|
* Decides one requirement against claims. No claims means the middleware was composed wrongly, so the answer
|
|
88
92
|
* is a 500 with no challenge: never a step-up, which the SDK would try to satisfy, and never a 401, because a
|
|
@@ -97,7 +101,7 @@ export declare function evaluate(claims: PassflowClaims | undefined, requirement
|
|
|
97
101
|
export declare function authenticate(verifier: Verifier, authorization: string | undefined | null, existing?: PassflowClaims): Promise<{
|
|
98
102
|
claims: PassflowClaims;
|
|
99
103
|
} | {
|
|
100
|
-
reject:
|
|
104
|
+
reject: Rejection;
|
|
101
105
|
}>;
|
|
102
106
|
type VerifierConfig = {
|
|
103
107
|
/** Required, exact match against `iss`. */
|
|
@@ -138,4 +142,4 @@ type VerifierConfig = {
|
|
|
138
142
|
* built per request would defeat it.
|
|
139
143
|
*/
|
|
140
144
|
export declare function createVerifier(config: VerifierConfig): Verifier;
|
|
141
|
-
export { type Decision, type PassflowAuthErrorCode, type PassflowClaims, type Requirement, type TenantMembership, type Verifier, type VerifierConfig, rolesOf, verifiedBy };
|
|
145
|
+
export { type Decision, type PassflowAuthErrorCode, type PassflowClaims, type Rejection, type Requirement, type TenantMembership, type Verifier, type VerifierConfig, rolesOf, verifiedBy };
|
package/dist/index.d.mts
CHANGED
|
@@ -83,6 +83,10 @@ type Decision = {
|
|
|
83
83
|
status: 401 | 500 | 503;
|
|
84
84
|
headers: Record<string, string>;
|
|
85
85
|
};
|
|
86
|
+
/** A rejected `Decision`: a `ResponseInit` as it stands (`new Response(null, rejection)`). */
|
|
87
|
+
type Rejection = Extract<Decision, {
|
|
88
|
+
kind: 'reject';
|
|
89
|
+
}>;
|
|
86
90
|
/**
|
|
87
91
|
* Decides one requirement against claims. No claims means the middleware was composed wrongly, so the answer
|
|
88
92
|
* is a 500 with no challenge: never a step-up, which the SDK would try to satisfy, and never a 401, because a
|
|
@@ -97,7 +101,7 @@ export declare function evaluate(claims: PassflowClaims | undefined, requirement
|
|
|
97
101
|
export declare function authenticate(verifier: Verifier, authorization: string | undefined | null, existing?: PassflowClaims): Promise<{
|
|
98
102
|
claims: PassflowClaims;
|
|
99
103
|
} | {
|
|
100
|
-
reject:
|
|
104
|
+
reject: Rejection;
|
|
101
105
|
}>;
|
|
102
106
|
type VerifierConfig = {
|
|
103
107
|
/** Required, exact match against `iss`. */
|
|
@@ -138,4 +142,4 @@ type VerifierConfig = {
|
|
|
138
142
|
* built per request would defeat it.
|
|
139
143
|
*/
|
|
140
144
|
export declare function createVerifier(config: VerifierConfig): Verifier;
|
|
141
|
-
export { type Decision, type PassflowAuthErrorCode, type PassflowClaims, type Requirement, type TenantMembership, type Verifier, type VerifierConfig, rolesOf, verifiedBy };
|
|
145
|
+
export { type Decision, type PassflowAuthErrorCode, type PassflowClaims, type Rejection, type Requirement, type TenantMembership, type Verifier, type VerifierConfig, rolesOf, verifiedBy };
|
package/package.json
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@passflow/node",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.3",
|
|
4
4
|
"description": "Passflow authorization primitives for Node.js resource servers: token verification, ACR floors, auth_time freshness and RFC 9470 step-up challenges, with Express, Fastify and Hono adapters.",
|
|
5
5
|
"license": "MIT",
|
|
6
|
-
"homepage": "https://github.com/
|
|
6
|
+
"homepage": "https://github.com/usepassflow/go/tree/main/examples/resource-server",
|
|
7
7
|
"bugs": {
|
|
8
|
-
"email": "
|
|
8
|
+
"email": "support@passflow.cloud"
|
|
9
9
|
},
|
|
10
10
|
"type": "module",
|
|
11
11
|
"sideEffects": false,
|
|
@@ -84,7 +84,7 @@
|
|
|
84
84
|
},
|
|
85
85
|
"devDependencies": {
|
|
86
86
|
"@arethetypeswrong/core": "0.18.5",
|
|
87
|
-
"@biomejs/biome": "
|
|
87
|
+
"@biomejs/biome": "2.6.4",
|
|
88
88
|
"@types/express": "5.0.6",
|
|
89
89
|
"@types/node": "^22.18.0",
|
|
90
90
|
"express": "5.3.0",
|
|
@@ -92,8 +92,8 @@
|
|
|
92
92
|
"hono": "4.13.14",
|
|
93
93
|
"publint": "0.3.25",
|
|
94
94
|
"tsdown": "0.23.4",
|
|
95
|
-
"typescript": "^
|
|
96
|
-
"vitest": "^
|
|
95
|
+
"typescript": "^7.0.2",
|
|
96
|
+
"vitest": "^5.0.5"
|
|
97
97
|
},
|
|
98
98
|
"scripts": {
|
|
99
99
|
"build": "tsdown",
|