@udibo/oauth2 0.15.0 → 0.15.1

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.
@@ -52,6 +52,7 @@ import { deleteCookie, getCookie, setCookie } from "hono/cookie";
52
52
  import { assertMaxBodyBytes, DEFAULT_MAX_BODY_BYTES, readBoundedBody, } from "../../../utils/_body.js";
53
53
  import { InvalidRequestError, InvalidTokenError, isOAuth2Error, TemporarilyUnavailableError, } from "../../../errors.js";
54
54
  import { defaultFetch } from "../../../utils/_default-fetch.js";
55
+ import { inboundRequestWithHeaders } from "../../../utils/_inbound-request.js";
55
56
  import { timingSafeMatchIndex } from "../../../utils/_timing-safe.js";
56
57
  import { sha256Hash } from "../../../server/utils/hash.js";
57
58
  import { OAUTH2_CONTEXT_KEY } from "../_common.js";
@@ -1023,7 +1024,7 @@ export class HonoBff {
1023
1024
  }
1024
1025
  const headers = new Headers(c.req.raw.headers);
1025
1026
  headers.set("Authorization", `Bearer ${resolution.entry.data.tokens.accessToken}`);
1026
- c.req.raw = new Request(c.req.raw, { headers });
1027
+ c.req.raw = inboundRequestWithHeaders(c.req.raw, headers);
1027
1028
  await next();
1028
1029
  };
1029
1030
  }
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Not part of the public API. Copies a request the server received, for
3
+ * middleware that hands downstream handlers a changed `c.req.raw`.
4
+ *
5
+ * @module
6
+ */
7
+ /**
8
+ * `request` with `headers` in place of its own, keeping its URL, method, body
9
+ * stream and the client's abort signal. Built from those parts rather than
10
+ * `new Request(request, …)`, which throws on `@hono/node-server`'s lightweight
11
+ * request unless the adapter replaced the global `Request` (the Vite dev
12
+ * server's does not). The body moves to the copy, so reading it from
13
+ * `request` afterwards finds it used.
14
+ */
15
+ export declare function inboundRequestWithHeaders(request: Request, headers: Headers): Request;
@@ -0,0 +1,25 @@
1
+ /**
2
+ * Not part of the public API. Copies a request the server received, for
3
+ * middleware that hands downstream handlers a changed `c.req.raw`.
4
+ *
5
+ * @module
6
+ */
7
+ /**
8
+ * `request` with `headers` in place of its own, keeping its URL, method, body
9
+ * stream and the client's abort signal. Built from those parts rather than
10
+ * `new Request(request, …)`, which throws on `@hono/node-server`'s lightweight
11
+ * request unless the adapter replaced the global `Request` (the Vite dev
12
+ * server's does not). The body moves to the copy, so reading it from
13
+ * `request` afterwards finds it used.
14
+ */
15
+ export function inboundRequestWithHeaders(request, headers) {
16
+ const init = {
17
+ method: request.method,
18
+ headers,
19
+ body: request.body,
20
+ signal: request.signal,
21
+ redirect: request.redirect,
22
+ duplex: "half",
23
+ };
24
+ return new Request(request.url, init);
25
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@udibo/oauth2",
3
- "version": "0.15.0",
3
+ "version": "0.15.1",
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
  "keywords": [
6
6
  "authorization-server",