@oauth-spa-kit/server 1.0.0 → 1.0.2

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/README.md ADDED
@@ -0,0 +1,70 @@
1
+ # @oauth-spa-kit/server
2
+
3
+ BFF-pattern OAuth handlers: sealed `HttpOnly` cookie sessions plus
4
+ login/callback/session/logout route factories, built on Web-standard
5
+ `Request`/`Response` so they drop into Nitro, Next.js route handlers,
6
+ Cloudflare Workers, or plain Node (via a small adapter).
7
+
8
+ Part of [oauth-spa-kit](https://github.com/ehncraft/oauth-spa-kit) -- see the
9
+ root README for the full architecture and request flow (PAR, PKCE, DPoP,
10
+ `private_key_jwt`, no `client_secret`, FAPI 2.0 baseline). If you're on
11
+ Nuxt, use [`@oauth-spa-kit/nuxt`](https://www.npmjs.com/package/@oauth-spa-kit/nuxt)
12
+ instead, which wires these same handlers in as Nitro routes for you.
13
+
14
+ ## Install
15
+
16
+ ```bash
17
+ npm install @oauth-spa-kit/server
18
+ ```
19
+
20
+ ## Usage
21
+
22
+ ```ts
23
+ import {
24
+ createLoginHandler,
25
+ createCallbackHandler,
26
+ createSessionHandler,
27
+ createLogoutHandler,
28
+ getAuthorizationHeader,
29
+ type OAuthHandlersConfig,
30
+ } from "@oauth-spa-kit/server";
31
+
32
+ const config: OAuthHandlersConfig = {
33
+ oauth: {
34
+ authority: "https://idp.example.com",
35
+ clientId: "spa-kit-demo",
36
+ clientAuthentication: {
37
+ method: "private_key_jwt",
38
+ privateKey, // a non-extractable CryptoKey, PS256 or ES256
39
+ },
40
+ redirectUri: "https://app.example.com/auth/callback",
41
+ scope: "openid profile offline_access",
42
+ // dpop and par both default to true (FAPI 2.0 baseline)
43
+ },
44
+ session: {
45
+ password: process.env.OAUTH_SESSION_PASSWORD!, // >=32 chars
46
+ },
47
+ };
48
+
49
+ // Each returns a plain (Request) => Promise<Response> -- mount at
50
+ // GET /auth/login, GET /auth/callback, GET /auth/session, POST /auth/logout.
51
+ export const login = createLoginHandler(config);
52
+ export const callback = createCallbackHandler(config);
53
+ export const session = createSessionHandler(config);
54
+ export const logout = createLogoutHandler(config);
55
+
56
+ // From any other API route that needs to call an upstream resource server:
57
+ const authHeader = await getAuthorizationHeader(request, config);
58
+ ```
59
+
60
+ The SPA never sees an access or refresh token -- only `GET /auth/session`'s
61
+ `{ user }` response, backed by a sealed cookie the browser can't read or
62
+ exfiltrate via JS. See
63
+ [`@oauth-spa-kit/core`](https://www.npmjs.com/package/@oauth-spa-kit/core)
64
+ for the lower-level protocol primitives these handlers are built from, and
65
+ [`@oauth-spa-kit/react`](https://www.npmjs.com/package/@oauth-spa-kit/react)
66
+ for a client-side `useAuth()` hook that talks to these routes.
67
+
68
+ ## License
69
+
70
+ MIT
@@ -1,5 +1,5 @@
1
1
  import { type OAuthClientConfig } from "@oauth-spa-kit/core";
2
- import { type SessionConfig } from "./session";
2
+ import { type SessionConfig } from "./session.js";
3
3
  export interface OAuthHandlersConfig {
4
4
  oauth: OAuthClientConfig;
5
5
  session: SessionConfig;
package/dist/handlers.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { computeJwkThumbprint, createPkceParams, discoverOidcConfiguration, exchangeAuthorizationCode, exchangeRefreshToken, exportDpopKeyPair, fetchJwks, generateDpopKeyPair, importDpopKeyPair, pushAuthorizationRequest, verifyJwt, OAuthError, } from "@oauth-spa-kit/core";
2
- import { clearPkceStateHeader, readPkceState, writePkceStateHeader } from "./pkceState";
3
- import { clearSessionHeader, readSession, writeSessionHeader } from "./session";
2
+ import { clearPkceStateHeader, readPkceState, writePkceStateHeader } from "./pkceState.js";
3
+ import { clearSessionHeader, readSession, writeSessionHeader } from "./session.js";
4
4
  async function resolveDiscovery(config) {
5
5
  return config.oauth.discoveryDocument
6
6
  ?? discoverOidcConfiguration(config.oauth.authority, config.fetchImpl);
package/dist/index.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- export * from "./session";
2
- export * from "./handlers";
1
+ export * from "./session.js";
2
+ export * from "./handlers.js";
package/dist/index.js CHANGED
@@ -1,2 +1,2 @@
1
- export * from "./session";
2
- export * from "./handlers";
1
+ export * from "./session.js";
2
+ export * from "./handlers.js";
package/dist/pkceState.js CHANGED
@@ -1,5 +1,5 @@
1
- import { sealJson, unsealJson } from "./crypto";
2
- import { parseCookies, serializeCookie, expireCookie } from "./cookies";
1
+ import { sealJson, unsealJson } from "./crypto.js";
2
+ import { parseCookies, serializeCookie, expireCookie } from "./cookies.js";
3
3
  const COOKIE_NAME = "__oauth_pkce";
4
4
  const MAX_AGE_SECONDS = 5 * 60;
5
5
  export async function writePkceStateHeader(pkce, password) {
package/dist/session.js CHANGED
@@ -1,5 +1,5 @@
1
- import { sealJson, unsealJson } from "./crypto";
2
- import { parseCookies, serializeCookie, expireCookie } from "./cookies";
1
+ import { sealJson, unsealJson } from "./crypto.js";
2
+ import { parseCookies, serializeCookie, expireCookie } from "./cookies.js";
3
3
  const DEFAULTS = { cookieName: "__session", maxAgeSeconds: 30 * 24 * 60 * 60 };
4
4
  export async function readSession(request, config) {
5
5
  const cookieName = config.cookieName ?? DEFAULTS.cookieName;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@oauth-spa-kit/server",
3
- "version": "1.0.0",
3
+ "version": "1.0.2",
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": "1.0.0"
25
+ "@oauth-spa-kit/core": "1.0.2"
26
26
  },
27
27
  "devDependencies": {
28
28
  "typescript": "^5.6.0",