@sourceregistry/sveltekit-oidc 1.8.0 → 2.0.0

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 CHANGED
@@ -1,20 +1,18 @@
1
1
  # sveltekit-oidc
2
2
 
3
3
  [![npm version](https://img.shields.io/npm/v/@sourceregistry/sveltekit-oidc.svg)](https://www.npmjs.com/package/@sourceregistry/sveltekit-oidc)
4
- [![npm downloads](https://img.shields.io/npm/dm/@sourceregistry/sveltekit-oidc.svg)](https://www.npmjs.com/package/@sourceregistry/sveltekit-oidc)
5
4
  [![license](https://img.shields.io/npm/l/@sourceregistry/sveltekit-oidc.svg)](LICENSE)
6
- [![types](https://img.shields.io/npm/types/@sourceregistry/sveltekit-oidc.svg)](https://www.npmjs.com/package/@sourceregistry/sveltekit-oidc)
7
5
  [![Svelte](https://img.shields.io/badge/Svelte-5-ff3e00.svg)](https://svelte.dev/)
8
- [![publint](https://img.shields.io/badge/publint-passing-brightgreen.svg)](https://publint.dev/@sourceregistry/sveltekit-oidc)
9
6
 
10
- OIDC authentication helpers for SvelteKit with:
7
+ OIDC authentication and session management for SvelteKit.
11
8
 
12
- - server-side login, callback, logout, and session refresh flows
13
- - token endpoint auth support for `none`, `client_secret_basic`, `client_secret_post`, `client_secret_jwt`, and `private_key_jwt`
14
- - back-channel logout support through a revocation store
15
- - encrypted cookie-backed sessions and PKCE/state protection
16
- - a `handle` hook for attaching auth state to `event.locals`
17
- - a small `OIDCContext` provider for client-side auth state and session lifecycle handling
9
+ The library keeps three concerns separate:
10
+
11
+ - provider protocol data: validated ID token claims and optional UserInfo
12
+ - persisted authentication: tokens and the resolved application identity
13
+ - request data: application-owned authorization loaded once per request
14
+
15
+ It implements the protocol itself and does not depend on `openid-client`.
18
16
 
19
17
  ## Install
20
18
 
@@ -22,197 +20,173 @@ OIDC authentication helpers for SvelteKit with:
22
20
  npm install @sourceregistry/sveltekit-oidc
23
21
  ```
24
22
 
25
- ## Server Setup
23
+ ## Configure
26
24
 
27
25
  ```ts
28
26
  // src/lib/server/auth.ts
29
- import { createOIDC } from '@sourceregistry/sveltekit-oidc/server';
27
+ import {createOIDC} from '@sourceregistry/sveltekit-oidc/server';
28
+
29
+ type Identity = {
30
+ sub: string;
31
+ email?: string;
32
+ name?: string;
33
+ roles: string[];
34
+ permissions?: string[];
35
+ };
30
36
 
31
- export const oidc = createOIDC({
32
- issuer: 'https://your-idp.example.com',
37
+ type RequestData = {
38
+ permissions: string[];
39
+ };
40
+
41
+ export const oidc = createOIDC<Identity, RequestData>({
42
+ issuer: 'https://identity.example.com',
33
43
  clientId: process.env.OIDC_CLIENT_ID!,
34
44
  clientSecret: process.env.OIDC_CLIENT_SECRET!,
35
- cookieSecret: process.env.OIDC_COOKIE_SECRET!,
36
45
  clientAuthMethod: 'client_secret_basic',
37
- loginPath: '/auth/login',
38
- redirectPath: '/auth/callback',
39
- scope: 'openid profile email offline_access',
40
- backChannelLogoutStore: 'memory',
41
- cookieOptions: {
42
- secure: process.env.NODE_ENV === 'production'
43
- }
46
+ cookieSecret: process.env.OIDC_COOKIE_SECRET!,
47
+ scope: ['openid', 'profile', 'email', 'offline_access'],
48
+
49
+ resolveIdentity: ({idTokenClaims, userInfo}) => ({
50
+ sub: idTokenClaims.sub,
51
+ email: userInfo?.email ?? idTokenClaims.email,
52
+ name: userInfo?.name ?? idTokenClaims.name,
53
+ roles: Array.isArray(userInfo?.roles ?? idTokenClaims.roles)
54
+ ? ((userInfo?.roles ?? idTokenClaims.roles) as string[])
55
+ : []
56
+ }),
57
+
58
+ beforeSessionPersist: async ({session, reason}) => {
59
+ await synchronizeUser(session.identity, reason);
60
+ },
61
+
62
+ loadRequestData: async ({session, event}) => ({
63
+ permissions: await loadPermissions(session.sub!, event)
64
+ }),
65
+
66
+ createPublicSession: ({base, data}) => ({
67
+ ...base,
68
+ identity: {
69
+ ...base.identity,
70
+ permissions: data?.permissions ?? []
71
+ }
72
+ })
44
73
  });
45
74
  ```
46
75
 
47
- ```ts
48
- // src/hooks.server.ts
49
- import { oidc } from '$lib/server/auth';
50
-
51
- export const handle = oidc.handle;
52
- ```
76
+ The extension points have deliberately literal names:
53
77
 
54
- ```ts
55
- // src/routes/auth/login/+server.ts
56
- import { oidc } from '$lib/server/auth';
78
+ | Extension point | When it runs | Persisted |
79
+ | ---------------------- | --------------------------------------------------------------- | ----------------------- |
80
+ | `resolveIdentity` | After provider data is validated, on login and refresh | Its result is persisted |
81
+ | `beforeSessionPersist` | Immediately before a login or refreshed session is written | Side effects only |
82
+ | `loadRequestData` | Once while `handle` builds an authenticated request context | Never |
83
+ | `createPublicSession` | When `getPublicSession` or `toPublicSession` projects a session | Never |
57
84
 
58
- export const GET = oidc.loginHandler();
59
- ```
85
+ Both login and refresh are explicit in the callback context:
60
86
 
61
87
  ```ts
62
- // src/routes/auth/callback/+server.ts
63
- import { oidc } from '$lib/server/auth';
64
-
65
- export const GET = oidc.callbackHandler({
66
- redirectTo: '/'
67
- });
88
+ beforeSessionPersist: async ({session, reason}) => {
89
+ if (reason === 'login') {
90
+ await recordLogin(session.identity);
91
+ }
92
+ };
68
93
  ```
69
94
 
70
- ```ts
71
- // src/routes/auth/logout/+server.ts
72
- import { oidc } from '$lib/server/auth';
73
-
74
- export const POST = oidc.logoutHandler();
75
- ```
95
+ ## SvelteKit hook
76
96
 
77
97
  ```ts
78
- // src/routes/auth/backchannel-logout/+server.ts
79
- import { oidc } from '$lib/server/auth';
98
+ // src/hooks.server.ts
99
+ import {oidc} from '$lib/server/auth';
80
100
 
81
- export const POST = oidc.backChannelLogoutHandler();
101
+ export const handle = oidc.handle;
82
102
  ```
83
103
 
84
- ## Actions
85
-
86
- If you prefer form actions instead of dedicated routes:
104
+ For every request, `handle` exposes:
87
105
 
88
106
  ```ts
89
- // src/routes/+page.server.ts
90
- import { oidc } from '$lib/server/auth';
91
-
92
- export const actions = oidc.createActions();
107
+ event.locals.oidc.session; // persisted OIDC session
108
+ event.locals.oidc.identity; // resolved identity
109
+ event.locals.oidc.data; // request-only application data
93
110
  ```
94
111
 
95
- ## Load Session
112
+ Type the locals directly from the configured instance:
96
113
 
97
114
  ```ts
98
- // src/routes/+layout.server.ts
99
- import { oidc } from '$lib/server/auth';
115
+ // src/app.d.ts
116
+ import type {OIDCLocals} from '@sourceregistry/sveltekit-oidc/server';
117
+ import type {oidc} from '$lib/server/auth';
100
118
 
101
- export async function load(event) {
102
- return {
103
- session: await oidc.getPublicSession(event),
104
- sessionManagement: await oidc.getSessionManagementConfig()
105
- };
119
+ declare global {
120
+ namespace App {
121
+ interface Locals {
122
+ oidc?: OIDCLocals<typeof oidc>;
123
+ }
124
+ }
106
125
  }
107
- ```
108
-
109
- ## Client Setup
110
-
111
- ```html
112
- <script lang="ts">
113
- import { OIDCContext } from '@sourceregistry/sveltekit-oidc';
114
- let { data } = $props();
115
- </script>
116
126
 
117
- <OIDCContext
118
- session={data.session}
119
- config={data.sessionManagement}
120
- logoutPath="/auth/logout"
121
- monitorSession={false}
122
- redirectIfUnauthenticated={false}
123
- >
124
- <Account />
125
- </OIDCContext>
127
+ export {};
126
128
  ```
127
129
 
128
- ```html
129
- <!-- src/lib/Account.svelte -->
130
- <script lang="ts">
131
- import { useOIDC } from '@sourceregistry/sveltekit-oidc';
130
+ ## Routes
132
131
 
133
- const oidc = useOIDC();
134
- </script>
135
-
136
- {#if oidc.isAuthenticated}
137
- <p>Signed in as {oidc.user?.email ?? oidc.user?.name ?? oidc.session?.sub}</p>
138
- <form method="POST" action="/auth/logout">
139
- <button type="submit">Sign out</button>
140
- </form>
141
- {:else}
142
- <a href="/auth/login?returnTo=%2Faccount">Sign in</a>
143
- {/if}
132
+ ```ts
133
+ // src/routes/auth/login/+server.ts
134
+ import {oidc} from '$lib/server/auth';
135
+ export const GET = oidc.loginHandler();
144
136
  ```
145
137
 
146
- `OIDCContext` handles:
147
-
148
- - local expiry redirects
149
- - `check_session_iframe` polling when the provider advertises it
150
- - targeted session revalidation when a token reaches its renewal window
151
- - optional periodic session revalidation when `revalidateIntervalMs` is explicitly configured
152
- - a client context for nested auth-aware components through `useOIDC()` / `getOIDCContext()`
153
-
154
- `oidc.getPublicSession(event)` automatically registers the `oidc:session` dependency used by
155
- `OIDCContext`, so the standard setup above does not re-run unrelated page loads. If you destructure
156
- the load event, pass both `cookies` and `depends`: `oidc.getPublicSession({cookies, depends})`.
157
-
158
- When `oidc.handle` has already loaded an enriched session for the current request, project that
159
- session without reading or enriching it again:
160
-
161
138
  ```ts
162
- const session = oidc.toPublicSession(event.locals.oidc?.session ?? null, event.depends);
139
+ // src/routes/auth/callback/+server.ts
140
+ import {oidc} from '$lib/server/auth';
141
+ export const GET = oidc.callbackHandler();
163
142
  ```
164
143
 
165
- Periodic revalidation is disabled by default to avoid unnecessary page updates. Set
166
- `revalidateIntervalMs` to a positive interval only when you need polling in addition to token-expiry
167
- and provider session monitoring. Existing integrations that pass only `cookies` remain compatible;
168
- their expiry-driven revalidation falls back to `invalidateAll()`.
144
+ ```ts
145
+ // src/routes/auth/logout/+server.ts
146
+ import {oidc} from '$lib/server/auth';
147
+ export const POST = oidc.logoutHandler();
148
+ ```
169
149
 
170
- Set `monitorSession={false}` when you want to keep the client context but leave remote session
171
- revocation checks to your server-side guard or another mechanism. This disables
172
- `check_session_iframe` polling without changing the provider metadata exposed through the context.
150
+ ```ts
151
+ // src/routes/auth/backchannel-logout/+server.ts
152
+ import {oidc} from '$lib/server/auth';
153
+ export const POST = oidc.backChannelLogoutHandler();
154
+ ```
173
155
 
174
- ## Typed Custom Claims
156
+ The underlying operations are also available directly when a route needs custom behavior:
175
157
 
176
- `createOIDC` infers a `TClaims` type from whatever `transformClaims` / `transformUser` / `transformSession` return, and threads it through the session, `event.locals.oidc`, `OIDCPublicSession`, and the client context — no casts needed.
158
+ - `login(event, options)`
159
+ - `handleCallback(event)`
160
+ - `logout(event, options)`
161
+ - `handleBackChannelLogout(event)`
162
+ - `getSession(event)`
163
+ - `requireAuth(event)`
164
+ - `clearSession(cookies)`
177
165
 
178
- ```ts
179
- // src/lib/server/auth.ts
180
- export const oidc = createOIDC({
181
- issuer: 'https://your-idp.example.com',
182
- clientId: process.env.OIDC_CLIENT_ID!,
183
- cookieSecret: process.env.OIDC_COOKIE_SECRET!,
184
- transformClaims: (claims) => ({
185
- ...claims,
186
- roles: (claims.roles as string[]) ?? [],
187
- tenant: claims.tenant as string | undefined
188
- })
189
- });
190
- ```
166
+ ## Public session
191
167
 
192
- Wire `App.Locals` so `event.locals.oidc` is fully typed everywhere — `OIDCLocals` infers everything directly from the instance:
168
+ Load a token-free session for the browser:
193
169
 
194
170
  ```ts
195
- // src/app.d.ts
196
- import type { OIDCLocals } from '@sourceregistry/sveltekit-oidc/server';
197
- import { oidc } from '$lib/server/auth';
171
+ // src/routes/+layout.server.ts
172
+ import {oidc} from '$lib/server/auth';
198
173
 
199
- declare global {
200
- namespace App {
201
- interface Locals {
202
- oidc?: OIDCLocals<typeof oidc>;
203
- }
204
- }
174
+ export async function load(event) {
175
+ return {
176
+ session: oidc.toPublicSession(event.locals.oidc, event.depends),
177
+ sessionManagement: await oidc.getSessionManagementConfig()
178
+ };
205
179
  }
206
-
207
- export {};
208
180
  ```
209
181
 
210
- Now `event.locals.oidc?.claims?.roles` is `string[]` and `?.tenant` is `string | undefined` in every hook, load function, and action — no separate type aliases needed.
182
+ `toPublicSession` projects the request context already loaded by `handle`. It does not read the
183
+ store, refresh tokens, or load application data again. `createPublicSession` receives both the
184
+ persisted session and `loadRequestData` result, but only exposes what the application explicitly
185
+ returns. `getPublicSession(event)` is available when the hook has not already loaded the context.
211
186
 
212
- `OIDCContext` is a generic component, but Svelte doesn't support passing explicit type arguments in markup — `TClaims` is inferred from the `session` prop instead. Since `data.session` comes from `oidc.getPublicSession(event)`, the type flows through automatically:
187
+ ## Client context
213
188
 
214
- ```html
215
- <!-- src/routes/+layout.svelte -->
189
+ ```svelte
216
190
  <script lang="ts">
217
191
  import { OIDCContext } from '@sourceregistry/sveltekit-oidc';
218
192
  let { data, children } = $props();
@@ -223,103 +197,51 @@ Now `event.locals.oidc?.claims?.roles` is `string[]` and `?.tenant` is `string |
223
197
  </OIDCContext>
224
198
  ```
225
199
 
226
- ```html
227
- <!-- src/lib/Account.svelte -->
200
+ ```svelte
228
201
  <script lang="ts">
229
202
  import { useOIDC } from '@sourceregistry/sveltekit-oidc';
230
-
231
- const auth = useOIDC(); // TClaims inferred from App.Locals.oidc
203
+ const oidc = useOIDC();
232
204
  </script>
233
205
 
234
- {#if auth.isAuthenticated}
235
- <p>Roles: {auth.claims?.roles.join(', ')}</p>
206
+ {#if oidc.isAuthenticated}
207
+ <p>Signed in as {oidc.identity?.email ?? oidc.identity?.name}</p>
236
208
  {/if}
237
209
  ```
238
210
 
239
- If `transformClaims` (and friends) are omitted, `TClaims` defaults to `OIDCUserClaims` — existing setups keep working unchanged.
211
+ `OIDCContext` supports local expiry handling, targeted SvelteKit revalidation,
212
+ `check_session_iframe` monitoring, and local or provider logout.
240
213
 
241
- ## Typed Custom Session
214
+ ## Session stores
242
215
 
243
- Backend apps commonly stash application-specific data on the session itself (e.g. `tenantId`, `permissions`) not just inside `claims`/`user`. A second generic, `TSession`, is inferred from `transformSession`'s return type and threads through the session store, cookies, `event.locals.oidc`, and `handleCallback`'s result — again with no casts:
216
+ Without `sessionStore`, the encrypted session is stored in the cookie. For server-side sessions:
244
217
 
245
218
  ```ts
246
- // src/lib/server/auth.ts
247
- import { createOIDC, type OIDCSession, type OIDCUserClaims } from '@sourceregistry/sveltekit-oidc/server';
248
-
249
- type AppClaims = OIDCUserClaims & { tenant?: string };
250
- type AppSession = OIDCSession<AppClaims> & {
251
- tenantId: string;
252
- permissions: string[];
253
- };
254
-
255
- export const oidc = createOIDC({
256
- issuer: 'https://your-idp.example.com',
257
- clientId: process.env.OIDC_CLIENT_ID!,
258
- cookieSecret: process.env.OIDC_COOKIE_SECRET!,
259
- transformClaims: (claims) => ({ ...claims, tenant: claims.tenant as string | undefined }),
260
- transformSession: (session): AppSession => ({
261
- ...session,
262
- tenantId: session.claims?.tenant ?? 'default',
263
- permissions: session.user?.roles ?? []
264
- })
265
- });
266
- ```
267
-
268
- `app.d.ts` stays a one-liner — `OIDCLocals` picks up both `TClaims` and `TSession` from the instance:
269
-
270
- ```ts
271
- // src/app.d.ts
272
- import type { OIDCLocals } from '@sourceregistry/sveltekit-oidc/server';
273
- import { oidc } from '$lib/server/auth';
274
-
275
- declare global {
276
- namespace App {
277
- interface Locals {
278
- oidc?: OIDCLocals<typeof oidc>;
279
- }
219
+ import type {OIDCSessionStore} from '@sourceregistry/sveltekit-oidc/server';
220
+
221
+ const sessionStore: OIDCSessionStore<Identity> = {
222
+ get: (id) => redis.get(`session:${id}`),
223
+ set: async (id, session) => {
224
+ await redis.set(`session:${id}`, session);
225
+ },
226
+ delete: async (id) => {
227
+ await redis.delete(`session:${id}`);
280
228
  }
281
- }
282
-
283
- export {};
284
- ```
285
-
286
- Now `event.locals.oidc?.session?.tenantId` is `string` and `?.permissions` is `string[]` everywhere — and `oidc.requireAuth(event)` / `handleCallback`'s `onsuccess` resolve to `AppSession` directly.
287
-
288
- Use `OIDCInferClaims` / `OIDCInferSession` when you need the types explicitly in non-Svelte code (utility functions, API helpers, etc.):
289
-
290
- ```ts
291
- import type { OIDCInferClaims, OIDCInferSession } from '@sourceregistry/sveltekit-oidc/server';
292
- import type { oidc } from '$lib/server/auth';
293
-
294
- type AppClaims = OIDCInferClaims<typeof oidc>;
295
- type AppSession = OIDCInferSession<typeof oidc>;
229
+ };
296
230
  ```
297
231
 
298
- If `transformSession` is omitted, `TSession` defaults to `OIDCSession<TClaims>` existing setups keep working unchanged.
299
-
300
- ## Example App
301
-
302
- This repository now includes a runnable example under [src/routes](C:/Users/alexa/WebstormProjects/github.com/SourceRegistry/sveltekit-oidc/src/routes) and [src/hooks.server.ts](C:/Users/alexa/WebstormProjects/github.com/SourceRegistry/sveltekit-oidc/src/hooks.server.ts).
303
-
304
- Set these environment variables to enable it:
232
+ Use a shared `backChannelLogoutStore` when back-channel logout must work across multiple instances.
233
+ The built-in `'memory'` stores are intended for local development or single-process deployments.
305
234
 
306
- - `OIDC_ISSUER`
307
- - `OIDC_CLIENT_ID`
308
- - `OIDC_COOKIE_SECRET`
309
- - optional: `OIDC_CLIENT_SECRET`
310
- - optional: `OIDC_SCOPE`
311
- - optional: `OIDC_POST_LOGOUT_REDIRECT_URI`
235
+ ## Security behavior
312
236
 
313
- ## Notes
237
+ - Authorization Code flow uses PKCE, state, and nonce.
238
+ - ID tokens are verified against provider JWKS and require matching issuer, audience, nonce, `exp`, and `iat`.
239
+ - UserInfo `sub` must match the validated ID token subject.
240
+ - Cookie sessions use authenticated encryption.
241
+ - Return and post-logout redirect values are restricted to same-origin paths.
242
+ - Local sessions have an eight-hour maximum lifetime by default.
243
+ - Refresh is automatic while a valid refresh token is available.
244
+ - Client authentication supports `none`, `client_secret_basic`, `client_secret_post`, `client_secret_jwt`, and `private_key_jwt`.
314
245
 
315
- - `cookieSecret` should be a strong random secret and must stay stable across instances.
316
- - Built-in `returnTo` and logout redirect values are restricted to same-origin paths. Use your own callback `onsuccess` logic if you need custom redirect policy.
317
- - `clockSkewSeconds` defaults to `30` and tolerates small clock drift between your app and the identity provider.
318
- - Local browser sessions expire after 8 hours by default (`sessionMaxAgeSeconds`). They also end when an unrefreshable access token expires; set a shorter value for higher-risk applications.
319
- - `createInMemoryBackChannelLogoutStore()` is suitable for local development or single-instance deployments. Use Redis, SQL, or another shared store for production.
320
- - The library validates `id_token` and `logout_token` values through `@sourceregistry/node-jwt` and provider JWKS metadata. ID tokens must contain `exp`, `iat`, and a matching nonce; UserInfo subjects must match the validated ID token.
321
- - `groups` are normalized onto the session from `groups` and `roles` claims when present.
322
- - Use `transformClaims`, `transformUser`, and `transformSession` to project provider-specific claims into your own session shape.
323
- - `check_session_iframe` monitoring only runs when `monitorSession` is enabled, the provider advertises that endpoint, and the session includes `session_state`.
324
- - Refresh token handling is automatic when a valid refresh token is present.
325
- - `event.locals.oidc` is attached by the hook; wire it in `app.d.ts` with `OIDCLocals<typeof oidc>` — see [Typed Custom Claims](#typed-custom-claims).
246
+ Application code can normalize provider-specific data in `resolveIdentity`, but cannot replace the
247
+ validated ID token claims used by the protocol implementation.
@@ -5,7 +5,7 @@
5
5
  } from '../server/index.js';
6
6
  </script>
7
7
 
8
- <script lang="ts" generics="TClaims extends OIDCUserClaims = OIDCUserClaims">
8
+ <script lang="ts" generics="TIdentity extends OIDCUserClaims = OIDCUserClaims">
9
9
  import {beforeNavigate, invalidate, invalidateAll} from '$app/navigation';
10
10
  import {tick} from 'svelte';
11
11
  import type {Snippet} from 'svelte';
@@ -34,7 +34,7 @@
34
34
  onDebug,
35
35
  children
36
36
  }: {
37
- session?: OIDCPublicSession<TClaims> | null;
37
+ session?: OIDCPublicSession<TIdentity> | null;
38
38
  config: OIDCSessionManagementConfig;
39
39
  loginPath?: string;
40
40
  logoutPath?: string;
@@ -70,18 +70,15 @@
70
70
  Boolean(monitorSession && session?.isAuthenticated && session?.sessionState && iframeUrl)
71
71
  );
72
72
 
73
- const context = setOIDCContext<TClaims>({
73
+ const context = setOIDCContext<TIdentity>({
74
74
  get isAuthenticated() {
75
75
  return Boolean(session?.isAuthenticated);
76
76
  },
77
77
  get session() {
78
78
  return session;
79
79
  },
80
- get user() {
81
- return session?.user;
82
- },
83
- get claims() {
84
- return session?.claims;
80
+ get identity() {
81
+ return session?.identity;
85
82
  },
86
83
  get groups() {
87
84
  return session?.groups ?? [];
@@ -1,8 +1,8 @@
1
1
  import type { OIDCPublicSession, OIDCSessionManagementConfig, OIDCUserClaims } from '../server/index.js';
2
2
  import type { Snippet } from 'svelte';
3
- declare function $$render<TClaims extends OIDCUserClaims = OIDCUserClaims>(): {
3
+ declare function $$render<TIdentity extends OIDCUserClaims = OIDCUserClaims>(): {
4
4
  props: {
5
- session?: OIDCPublicSession<TClaims> | null;
5
+ session?: OIDCPublicSession<TIdentity> | null;
6
6
  config: OIDCSessionManagementConfig;
7
7
  loginPath?: string;
8
8
  logoutPath?: string;
@@ -10,8 +10,8 @@ declare function $$render<TClaims extends OIDCUserClaims = OIDCUserClaims>(): {
10
10
  monitorSession?: boolean;
11
11
  revalidateIntervalMs?: number;
12
12
  renewalLeadTimeMs?: number;
13
- redirectOnExpired?: "none" | "login" | "logout" | "reload";
14
- redirectOnRevoked?: "none" | "login" | "logout" | "reload";
13
+ redirectOnExpired?: "login" | "none" | "logout" | "reload";
14
+ redirectOnRevoked?: "login" | "none" | "logout" | "reload";
15
15
  redirectIfUnauthenticated?: boolean;
16
16
  /** Receives token-safe lifecycle events for diagnosing session changes. */
17
17
  onDebug?: (event: {
@@ -25,20 +25,20 @@ declare function $$render<TClaims extends OIDCUserClaims = OIDCUserClaims>(): {
25
25
  slots: {};
26
26
  events: {};
27
27
  };
28
- declare class __sveltets_Render<TClaims extends OIDCUserClaims = OIDCUserClaims> {
29
- props(): ReturnType<typeof $$render<TClaims>>['props'];
30
- events(): ReturnType<typeof $$render<TClaims>>['events'];
31
- slots(): ReturnType<typeof $$render<TClaims>>['slots'];
28
+ declare class __sveltets_Render<TIdentity extends OIDCUserClaims = OIDCUserClaims> {
29
+ props(): ReturnType<typeof $$render<TIdentity>>['props'];
30
+ events(): ReturnType<typeof $$render<TIdentity>>['events'];
31
+ slots(): ReturnType<typeof $$render<TIdentity>>['slots'];
32
32
  bindings(): "";
33
33
  exports(): {};
34
34
  }
35
35
  interface $$IsomorphicComponent {
36
- new <TClaims extends OIDCUserClaims = OIDCUserClaims>(options: import('svelte').ComponentConstructorOptions<ReturnType<__sveltets_Render<TClaims>['props']>>): import('svelte').SvelteComponent<ReturnType<__sveltets_Render<TClaims>['props']>, ReturnType<__sveltets_Render<TClaims>['events']>, ReturnType<__sveltets_Render<TClaims>['slots']>> & {
37
- $$bindings?: ReturnType<__sveltets_Render<TClaims>['bindings']>;
38
- } & ReturnType<__sveltets_Render<TClaims>['exports']>;
39
- <TClaims extends OIDCUserClaims = OIDCUserClaims>(internal: unknown, props: ReturnType<__sveltets_Render<TClaims>['props']> & {}): ReturnType<__sveltets_Render<TClaims>['exports']>;
36
+ new <TIdentity extends OIDCUserClaims = OIDCUserClaims>(options: import('svelte').ComponentConstructorOptions<ReturnType<__sveltets_Render<TIdentity>['props']>>): import('svelte').SvelteComponent<ReturnType<__sveltets_Render<TIdentity>['props']>, ReturnType<__sveltets_Render<TIdentity>['events']>, ReturnType<__sveltets_Render<TIdentity>['slots']>> & {
37
+ $$bindings?: ReturnType<__sveltets_Render<TIdentity>['bindings']>;
38
+ } & ReturnType<__sveltets_Render<TIdentity>['exports']>;
39
+ <TIdentity extends OIDCUserClaims = OIDCUserClaims>(internal: unknown, props: ReturnType<__sveltets_Render<TIdentity>['props']> & {}): ReturnType<__sveltets_Render<TIdentity>['exports']>;
40
40
  z_$$bindings?: ReturnType<__sveltets_Render<any>['bindings']>;
41
41
  }
42
42
  declare const OIDCContext: $$IsomorphicComponent;
43
- type OIDCContext<TClaims extends OIDCUserClaims = OIDCUserClaims> = InstanceType<typeof OIDCContext<TClaims>>;
43
+ type OIDCContext<TIdentity extends OIDCUserClaims = OIDCUserClaims> = InstanceType<typeof OIDCContext<TIdentity>>;
44
44
  export default OIDCContext;
@@ -1,13 +1,12 @@
1
1
  import type { OIDCDiscoveryDocument, OIDCHandleLocals, OIDCPublicSession, OIDCUserClaims } from '../server/index.js';
2
- type LocalsClaims = App.Locals extends {
3
- oidc?: OIDCHandleLocals<infer C, any>;
4
- } ? C : OIDCUserClaims;
5
- export type OIDCClientContextValue<TClaims extends OIDCUserClaims = OIDCUserClaims> = {
2
+ type LocalsIdentity = App.Locals extends {
3
+ oidc?: OIDCHandleLocals<infer I, any>;
4
+ } ? I : OIDCUserClaims;
5
+ export type OIDCClientContextValue<TIdentity extends OIDCUserClaims = OIDCUserClaims> = {
6
6
  isAuthenticated: boolean;
7
- session: OIDCPublicSession<TClaims> | null;
8
- user: OIDCPublicSession<TClaims>['user'];
9
- claims: OIDCPublicSession<TClaims>['claims'];
10
- groups: OIDCPublicSession<TClaims>['groups'];
7
+ session: OIDCPublicSession<TIdentity> | null;
8
+ identity: OIDCPublicSession<TIdentity>['identity'] | undefined;
9
+ groups: OIDCPublicSession<TIdentity>['groups'];
11
10
  issuer: string;
12
11
  metadata?: Pick<OIDCDiscoveryDocument, 'issuer' | 'check_session_iframe' | 'end_session_endpoint' | 'backchannel_logout_supported' | 'backchannel_logout_session_supported'>;
13
12
  status: 'authenticated' | 'unauthenticated' | 'expired' | 'revoked';
@@ -16,7 +15,7 @@ export type OIDCClientContextValue<TClaims extends OIDCUserClaims = OIDCUserClai
16
15
  logout: (clearSessionOnly?: boolean) => Promise<void>;
17
16
  revalidate: () => Promise<void>;
18
17
  };
19
- export declare function setOIDCContext<TClaims extends OIDCUserClaims = OIDCUserClaims>(value: OIDCClientContextValue<TClaims>): OIDCClientContextValue<TClaims>;
20
- export declare function getOIDCContext<TClaims extends OIDCUserClaims = LocalsClaims>(): OIDCClientContextValue<TClaims>;
21
- export declare function useOIDC<TClaims extends OIDCUserClaims = LocalsClaims>(): OIDCClientContextValue<TClaims>;
18
+ export declare function setOIDCContext<TIdentity extends OIDCUserClaims = OIDCUserClaims>(value: OIDCClientContextValue<TIdentity>): OIDCClientContextValue<TIdentity>;
19
+ export declare function getOIDCContext<TIdentity extends OIDCUserClaims = LocalsIdentity>(): OIDCClientContextValue<TIdentity>;
20
+ export declare function useOIDC<TIdentity extends OIDCUserClaims = LocalsIdentity>(): OIDCClientContextValue<TIdentity>;
22
21
  export {};
@@ -1,3 +1,3 @@
1
1
  export { default as OIDCContext } from './OIDCContext.svelte';
2
2
  export { getOIDCContext, useOIDC } from './context.js';
3
- export type { OIDCInferClaims, OIDCInferSession, OIDCLocals, OIDCPublicSession, OIDCSessionManagementConfig, OIDCUserClaims } from '../server/index.js';
3
+ export type { OIDCInferIdentity, OIDCInferSession, OIDCLocals, OIDCPublicSession, OIDCSessionManagementConfig, OIDCUserClaims } from '../server/index.js';
@@ -1,2 +1,2 @@
1
- import type { CookieOptions, OIDCCookies, OIDCSession, OIDCUserClaims } from './types.js';
2
- export declare function createOIDCCookieStore<TClaims extends OIDCUserClaims = OIDCUserClaims, TSession extends OIDCSession<TClaims> = OIDCSession<TClaims>>(cookieSecret: string, sessionCookieName: string, stateCookieName: string, cookieOptions: CookieOptions): OIDCCookies<TClaims, TSession>;
1
+ import type { CookieOptions, OIDCCookies, OIDCUserClaims } from './types.js';
2
+ export declare function createOIDCCookieStore<TIdentity extends OIDCUserClaims = OIDCUserClaims>(cookieSecret: string, sessionCookieName: string, stateCookieName: string, cookieOptions: CookieOptions): OIDCCookies<TIdentity>;
@@ -1,5 +1,5 @@
1
- import type { OIDCInstance, OIDCOptions, OIDCSession, OIDCUserClaims } from './types.js';
1
+ import type { OIDCInstance, OIDCOptions, OIDCUserClaims } from './types.js';
2
2
  export type * from './types.js';
3
3
  export { createInMemoryBackChannelLogoutStore, createInMemorySessionStore } from './store.js';
4
- export declare function createOIDC<TClaims extends OIDCUserClaims = OIDCUserClaims, TSession extends OIDCSession<TClaims> = OIDCSession<TClaims>>(options: OIDCOptions<TClaims, TSession>): OIDCInstance<TClaims, TSession>;
4
+ export declare function createOIDC<TIdentity extends OIDCUserClaims = OIDCUserClaims, TRequestData = undefined>(options: OIDCOptions<TIdentity, TRequestData>): OIDCInstance<TIdentity, TRequestData>;
5
5
  export declare const OpenIDConnect: typeof createOIDC;