@oauth-spa-kit/server 2.0.4 → 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.
- package/dist/handlers.d.ts +13 -1
- package/dist/handlers.js +13 -4
- package/package.json +2 -2
package/dist/handlers.d.ts
CHANGED
|
@@ -13,11 +13,23 @@ export interface OAuthHandlersConfig {
|
|
|
13
13
|
refreshThresholdSeconds?: number;
|
|
14
14
|
defaultReturnTo?: string;
|
|
15
15
|
fetchImpl?: typeof fetch;
|
|
16
|
+
/**
|
|
17
|
+
* Called with the raw thrown error whenever the callback handler's token
|
|
18
|
+
* exchange or id_token verification fails, right before it's collapsed
|
|
19
|
+
* down to a short, URL-safe error code and redirected to
|
|
20
|
+
* `returnTo?login_error=...`. The full error (e.g. TokenExchangeError's
|
|
21
|
+
* `errorDescription`, or a JwtVerificationError's message) is never put in
|
|
22
|
+
* that URL -- it may embed the AS's free-text description -- so without
|
|
23
|
+
* this hook the only way to see *why* a login failed is to re-derive it
|
|
24
|
+
* from the AS's own server-side logs. Optional; defaults to a no-op, so
|
|
25
|
+
* existing consumers see no behavior change.
|
|
26
|
+
*/
|
|
27
|
+
onCallbackError?: (error: unknown) => void;
|
|
16
28
|
}
|
|
17
29
|
export declare function createLoginHandler(config: OAuthHandlersConfig): (request: Request) => Promise<Response>;
|
|
18
30
|
export declare function createCallbackHandler(config: OAuthHandlersConfig): (request: Request) => Promise<Response>;
|
|
19
31
|
export declare function createSessionHandler(config: OAuthHandlersConfig): (request: Request) => Promise<Response>;
|
|
20
|
-
export declare function createLogoutHandler(config: OAuthHandlersConfig): (
|
|
32
|
+
export declare function createLogoutHandler(config: OAuthHandlersConfig): (request: Request) => Promise<Response>;
|
|
21
33
|
export interface AuthorizationHeaderResult {
|
|
22
34
|
header: string;
|
|
23
35
|
/** Set only when the token was refreshed -- forward this Set-Cookie on your outgoing response. */
|
package/dist/handlers.js
CHANGED
|
@@ -135,6 +135,7 @@ export function createCallbackHandler(config) {
|
|
|
135
135
|
return new Response(null, { status: 302, headers });
|
|
136
136
|
}
|
|
137
137
|
catch (cause) {
|
|
138
|
+
config.onCallbackError?.(cause);
|
|
138
139
|
// Prefer the AS's own OAuth error code (e.g. "invalid_grant") over the
|
|
139
140
|
// full exception message -- short, stable, safe to put in a URL query
|
|
140
141
|
// param; the full message may embed the AS's free-text error_description.
|
|
@@ -195,10 +196,15 @@ export function createSessionHandler(config) {
|
|
|
195
196
|
};
|
|
196
197
|
}
|
|
197
198
|
export function createLogoutHandler(config) {
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
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);
|
|
202
208
|
const headers = new Headers({ "content-type": "application/json" });
|
|
203
209
|
headers.append("Set-Cookie", clearSessionHeader(config.session));
|
|
204
210
|
const discovery = await resolveDiscovery(config).catch(() => null);
|
|
@@ -206,6 +212,9 @@ export function createLogoutHandler(config) {
|
|
|
206
212
|
const endSessionUrl = new URL(discovery.end_session_endpoint);
|
|
207
213
|
endSessionUrl.searchParams.set("client_id", config.oauth.clientId);
|
|
208
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
|
+
}
|
|
209
218
|
headers.set("Location", endSessionUrl.toString());
|
|
210
219
|
return new Response(null, { status: 302, headers });
|
|
211
220
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@oauth-spa-kit/server",
|
|
3
|
-
"version": "2.0.
|
|
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.
|
|
25
|
+
"@oauth-spa-kit/core": "2.0.6"
|
|
26
26
|
},
|
|
27
27
|
"devDependencies": {
|
|
28
28
|
"typescript": "^5.6.0",
|