@passflow/node 0.1.0 → 0.1.2
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/package.json +7 -8
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 (`docs/tutorials/node-backend.md`) and a runnable API in `examples/resource-server
|
|
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 (`docs/tutorials/node-backend.md`) 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/package.json
CHANGED
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@passflow/node",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.2",
|
|
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
|
-
"
|
|
7
|
-
|
|
8
|
-
"
|
|
9
|
-
"directory": "sdk/node"
|
|
6
|
+
"homepage": "https://github.com/usepassflow/go/tree/main/examples/resource-server",
|
|
7
|
+
"bugs": {
|
|
8
|
+
"email": "support@passflow.cloud"
|
|
10
9
|
},
|
|
11
10
|
"type": "module",
|
|
12
11
|
"sideEffects": false,
|
|
@@ -85,7 +84,7 @@
|
|
|
85
84
|
},
|
|
86
85
|
"devDependencies": {
|
|
87
86
|
"@arethetypeswrong/core": "0.18.5",
|
|
88
|
-
"@biomejs/biome": "
|
|
87
|
+
"@biomejs/biome": "2.6.4",
|
|
89
88
|
"@types/express": "5.0.6",
|
|
90
89
|
"@types/node": "^22.18.0",
|
|
91
90
|
"express": "5.3.0",
|
|
@@ -93,8 +92,8 @@
|
|
|
93
92
|
"hono": "4.13.14",
|
|
94
93
|
"publint": "0.3.25",
|
|
95
94
|
"tsdown": "0.23.4",
|
|
96
|
-
"typescript": "^
|
|
97
|
-
"vitest": "^
|
|
95
|
+
"typescript": "^7.0.2",
|
|
96
|
+
"vitest": "^5.0.5"
|
|
98
97
|
},
|
|
99
98
|
"scripts": {
|
|
100
99
|
"build": "tsdown",
|