@udibo/oauth2 0.21.2 → 0.21.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.
@@ -26,6 +26,12 @@ export interface HonoResourceServerVariables<Client extends ClientInterface, Use
26
26
  /** The authenticated OAuth2 context set by the protect middleware. */
27
27
  [OAUTH2_CONTEXT_KEY]: AuthenticatedContext<Client, User, S>;
28
28
  }
29
+ /**
30
+ * Answers with `response` while keeping the headers earlier middleware set on
31
+ * `c`, such as the `Set-Cookie` a BFF sets when a refresh rotates or ends the
32
+ * session. A middleware returning a bare `Response` would drop them.
33
+ */
34
+ export declare function respondInContext(c: Context, response: Response): Response;
29
35
  /**
30
36
  * Builds a Hono middleware that authenticates bearer tokens, stores the
31
37
  * authenticated context at {@link OAUTH2_CONTEXT_KEY}, and on failure returns
@@ -13,6 +13,14 @@ import { ResourceServer } from "../../server/resource-server.js";
13
13
  * context. Namespaced to avoid collisions with other middleware.
14
14
  */
15
15
  export const OAUTH2_CONTEXT_KEY = "@udibo/oauth2";
16
+ /**
17
+ * Answers with `response` while keeping the headers earlier middleware set on
18
+ * `c`, such as the `Set-Cookie` a BFF sets when a refresh rotates or ends the
19
+ * session. A middleware returning a bare `Response` would drop them.
20
+ */
21
+ export function respondInContext(c, response) {
22
+ return c.newResponse(response.body, response);
23
+ }
16
24
  /**
17
25
  * Builds a Hono middleware that authenticates bearer tokens, stores the
18
26
  * authenticated context at {@link OAUTH2_CONTEXT_KEY}, and on failure returns
@@ -26,7 +34,7 @@ export function createProtectMiddleware(server, requiredScope) {
26
34
  await next();
27
35
  }
28
36
  catch (error) {
29
- return server.handleAuthError(error);
37
+ return respondInContext(c, server.handleAuthError(error));
30
38
  }
31
39
  };
32
40
  }
@@ -45,7 +53,7 @@ export function createRequireScopeMiddleware(server, adapterName, requiredScope)
45
53
  server.assertScope(scope, requiredScope);
46
54
  }
47
55
  catch (error) {
48
- return server.handleAuthError(error);
56
+ return respondInContext(c, server.handleAuthError(error));
49
57
  }
50
58
  await next();
51
59
  };
@@ -63,7 +71,7 @@ export function createRequireMiddleware(server, adapterName, conditions) {
63
71
  server.assertAuthorized(context, conditions);
64
72
  }
65
73
  catch (error) {
66
- return server.handleAuthError(error);
74
+ return respondInContext(c, server.handleAuthError(error));
67
75
  }
68
76
  await next();
69
77
  };
@@ -55,7 +55,7 @@ import { defaultFetch } from "../../../utils/_default-fetch.js";
55
55
  import { inboundRequestWithHeaders } from "../../../utils/_inbound-request.js";
56
56
  import { timingSafeMatchIndex } from "../../../utils/_timing-safe.js";
57
57
  import { sha256Hash } from "../../../server/utils/hash.js";
58
- import { OAUTH2_CONTEXT_KEY } from "../_common.js";
58
+ import { OAUTH2_CONTEXT_KEY, respondInContext } from "../_common.js";
59
59
  import { DEFAULT_MAX_RETURN_TO_LENGTH, loginContinuation as computeLoginContinuation, safeReturnTo, } from "../../../utils/url.js";
60
60
  import { resolveCookieName, resolvePrefixConstrainedAttributes, } from "./cookie-prefix.js";
61
61
  import { DEFAULT_SESSION_MAX_AGE_MS, sessionStoreMaxAgeMs, supportsBackchannelLogout, supportsRefreshLock, } from "./session-store.js";
@@ -1208,7 +1208,7 @@ export class HonoBff {
1208
1208
  await next();
1209
1209
  }
1210
1210
  catch (error) {
1211
- return resourceServer.handleAuthError(error);
1211
+ return respondInContext(c, resourceServer.handleAuthError(error));
1212
1212
  }
1213
1213
  };
1214
1214
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@udibo/oauth2",
3
- "version": "0.21.2",
3
+ "version": "0.21.3",
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",