@oauth-spa-kit/server 2.0.5 → 2.0.6

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.
@@ -29,7 +29,7 @@ export interface OAuthHandlersConfig {
29
29
  export declare function createLoginHandler(config: OAuthHandlersConfig): (request: Request) => Promise<Response>;
30
30
  export declare function createCallbackHandler(config: OAuthHandlersConfig): (request: Request) => Promise<Response>;
31
31
  export declare function createSessionHandler(config: OAuthHandlersConfig): (request: Request) => Promise<Response>;
32
- export declare function createLogoutHandler(config: OAuthHandlersConfig): (_request: Request) => Promise<Response>;
32
+ export declare function createLogoutHandler(config: OAuthHandlersConfig): (request: Request) => Promise<Response>;
33
33
  export interface AuthorizationHeaderResult {
34
34
  header: string;
35
35
  /** Set only when the token was refreshed -- forward this Set-Cookie on your outgoing response. */
package/dist/handlers.js CHANGED
@@ -196,10 +196,15 @@ export function createSessionHandler(config) {
196
196
  };
197
197
  }
198
198
  export function createLogoutHandler(config) {
199
- // Takes a Request, unused, purely so all four handlers share the same
200
- // `(Request) => Promise<Response>` shape for callers that dispatch on a
201
- // uniform signature (see examples/react-spa/server.ts).
202
- return async function logoutHandler(_request) {
199
+ return async function logoutHandler(request) {
200
+ // Read before clearing: id_token_hint (OIDC RP-Initiated Logout 1.0 section 2) is what
201
+ // lets the AS resolve the requesting client and validate/honor post_logout_redirect_uri
202
+ // without an extra confirmation step -- a bare client_id query param proves nothing (any
203
+ // page could set it), so an AS that takes client identity seriously only trusts it when
204
+ // accompanied by the id_token_hint proving this really was that client's session. Without
205
+ // it, expect the AS to fall back to an interactive "are you sure?" prompt and/or drop
206
+ // post_logout_redirect_uri entirely instead of honoring it.
207
+ const session = await readSession(request, config.session);
203
208
  const headers = new Headers({ "content-type": "application/json" });
204
209
  headers.append("Set-Cookie", clearSessionHeader(config.session));
205
210
  const discovery = await resolveDiscovery(config).catch(() => null);
@@ -207,6 +212,9 @@ export function createLogoutHandler(config) {
207
212
  const endSessionUrl = new URL(discovery.end_session_endpoint);
208
213
  endSessionUrl.searchParams.set("client_id", config.oauth.clientId);
209
214
  endSessionUrl.searchParams.set("post_logout_redirect_uri", config.oauth.postLogoutRedirectUri);
215
+ if (session?.tokens.idToken) {
216
+ endSessionUrl.searchParams.set("id_token_hint", session.tokens.idToken);
217
+ }
210
218
  headers.set("Location", endSessionUrl.toString());
211
219
  return new Response(null, { status: 302, headers });
212
220
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@oauth-spa-kit/server",
3
- "version": "2.0.5",
3
+ "version": "2.0.6",
4
4
  "description": "BFF-pattern OAuth handlers: sealed HttpOnly-cookie sessions + login/callback/refresh/logout route factories, built on Web-standard Request/Response so they drop into Nitro, Next.js route handlers, Cloudflare Workers, or plain Node (via a small adapter).",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -22,7 +22,7 @@
22
22
  "node": ">=18"
23
23
  },
24
24
  "dependencies": {
25
- "@oauth-spa-kit/core": "2.0.5"
25
+ "@oauth-spa-kit/core": "2.0.6"
26
26
  },
27
27
  "devDependencies": {
28
28
  "typescript": "^5.6.0",