@udibo/oauth2 0.6.0 → 0.8.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/esm/_dnt.polyfills.d.ts +14 -0
- package/esm/_dnt.polyfills.js +11 -0
- package/esm/adapters/hono/bff/bff.d.ts +66 -3
- package/esm/adapters/hono/bff/bff.js +95 -12
- package/esm/client/_http.d.ts +5 -2
- package/esm/client/_http.js +6 -3
- package/esm/client/check.js +11 -32
- package/esm/client/direct-client.d.ts +41 -2
- package/esm/client/direct-client.js +41 -2
- package/esm/client/storage.d.ts +8 -1
- package/esm/server/authorization-server.d.ts +27 -2
- package/esm/server/authorization-server.js +29 -5
- package/esm/testing/contract/auth-request-storage.d.ts +26 -0
- package/esm/testing/contract/auth-request-storage.js +44 -7
- package/esm/testing/contract/mod.d.ts +1 -1
- package/esm/testing/contract/tenant.d.ts +49 -9
- package/esm/testing/contract/tenant.js +631 -5
- package/esm/testing/mod.d.ts +6 -5
- package/esm/testing/mod.js +5 -4
- package/esm/testing/tenant.d.ts +88 -16
- package/esm/testing/tenant.js +971 -57
- package/esm/utils/_body.d.ts +29 -0
- package/esm/utils/_body.js +66 -0
- package/package.json +1 -1
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Internal bounded request-body reader for the endpoints that parse a body
|
|
3
|
+
* before they have authenticated the caller.
|
|
4
|
+
*
|
|
5
|
+
* @module
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* The default cap on those bodies: 64 KiB. The largest legitimate field is a
|
|
9
|
+
* JWT (`id_token_hint`, `logout_token`, an introspected access token), and a
|
|
10
|
+
* token that also travels in an `Authorization` header already has to fit
|
|
11
|
+
* the 8–16 KiB header limits common to servers and proxies.
|
|
12
|
+
*/
|
|
13
|
+
export declare const DEFAULT_MAX_BODY_BYTES: number;
|
|
14
|
+
/**
|
|
15
|
+
* Throws a `RangeError` naming `option` unless `maxBodyBytes` is a positive
|
|
16
|
+
* safe integer.
|
|
17
|
+
*/
|
|
18
|
+
export declare function assertMaxBodyBytes(maxBodyBytes: number, option: string): void;
|
|
19
|
+
/**
|
|
20
|
+
* Reads `request`'s body, counting bytes as they arrive, and returns `null`
|
|
21
|
+
* once it exceeds `maxBytes` — cancelling the stream rather than draining it.
|
|
22
|
+
* A `Content-Length` over the cap is refused without reading; one under it is
|
|
23
|
+
* not trusted. Consumes the body unless `keepReadable` is set, which reads a
|
|
24
|
+
* clone and leaves the original readable (a refusal cancels both). Rejects if
|
|
25
|
+
* the stream errors or was already read.
|
|
26
|
+
*/
|
|
27
|
+
export declare function readBoundedBody(request: Request, maxBytes: number, options?: {
|
|
28
|
+
keepReadable?: boolean;
|
|
29
|
+
}): Promise<Uint8Array<ArrayBuffer> | null>;
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Internal bounded request-body reader for the endpoints that parse a body
|
|
3
|
+
* before they have authenticated the caller.
|
|
4
|
+
*
|
|
5
|
+
* @module
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* The default cap on those bodies: 64 KiB. The largest legitimate field is a
|
|
9
|
+
* JWT (`id_token_hint`, `logout_token`, an introspected access token), and a
|
|
10
|
+
* token that also travels in an `Authorization` header already has to fit
|
|
11
|
+
* the 8–16 KiB header limits common to servers and proxies.
|
|
12
|
+
*/
|
|
13
|
+
export const DEFAULT_MAX_BODY_BYTES = 64 * 1024;
|
|
14
|
+
/**
|
|
15
|
+
* Throws a `RangeError` naming `option` unless `maxBodyBytes` is a positive
|
|
16
|
+
* safe integer.
|
|
17
|
+
*/
|
|
18
|
+
export function assertMaxBodyBytes(maxBodyBytes, option) {
|
|
19
|
+
if (!Number.isSafeInteger(maxBodyBytes) || maxBodyBytes < 1) {
|
|
20
|
+
throw new RangeError(`${option} must be a positive integer, got ${maxBodyBytes}`);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Reads `request`'s body, counting bytes as they arrive, and returns `null`
|
|
25
|
+
* once it exceeds `maxBytes` — cancelling the stream rather than draining it.
|
|
26
|
+
* A `Content-Length` over the cap is refused without reading; one under it is
|
|
27
|
+
* not trusted. Consumes the body unless `keepReadable` is set, which reads a
|
|
28
|
+
* clone and leaves the original readable (a refusal cancels both). Rejects if
|
|
29
|
+
* the stream errors or was already read.
|
|
30
|
+
*/
|
|
31
|
+
export async function readBoundedBody(request, maxBytes, options = {}) {
|
|
32
|
+
if (!request.body)
|
|
33
|
+
return new Uint8Array();
|
|
34
|
+
if (Number(request.headers.get("content-length")) > maxBytes) {
|
|
35
|
+
request.body.cancel().catch(() => { });
|
|
36
|
+
return null;
|
|
37
|
+
}
|
|
38
|
+
const body = options.keepReadable ? request.clone().body : request.body;
|
|
39
|
+
const bytes = await readUpTo(body, maxBytes);
|
|
40
|
+
if (!bytes && options.keepReadable)
|
|
41
|
+
request.body.cancel().catch(() => { });
|
|
42
|
+
return bytes;
|
|
43
|
+
}
|
|
44
|
+
async function readUpTo(body, maxBytes) {
|
|
45
|
+
const reader = body.getReader();
|
|
46
|
+
const chunks = [];
|
|
47
|
+
let length = 0;
|
|
48
|
+
while (true) {
|
|
49
|
+
const { done, value } = await reader.read();
|
|
50
|
+
if (done)
|
|
51
|
+
break;
|
|
52
|
+
length += value.byteLength;
|
|
53
|
+
if (length > maxBytes) {
|
|
54
|
+
reader.cancel().catch(() => { });
|
|
55
|
+
return null;
|
|
56
|
+
}
|
|
57
|
+
chunks.push(value);
|
|
58
|
+
}
|
|
59
|
+
const bytes = new Uint8Array(length);
|
|
60
|
+
let offset = 0;
|
|
61
|
+
for (const chunk of chunks) {
|
|
62
|
+
bytes.set(chunk, offset);
|
|
63
|
+
offset += chunk.byteLength;
|
|
64
|
+
}
|
|
65
|
+
return bytes;
|
|
66
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@udibo/oauth2",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.8.0",
|
|
4
4
|
"description": "A flexible OAuth2 toolkit: framework-agnostic authorization & resource servers, a typed client, Hono adapters (including a backend-for-frontend), and React bindings.",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|