@eventuras/fides-auth-next 0.8.0 → 0.8.1
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/auth.d.ts +3 -3
- package/dist/auth.d.ts.map +1 -1
- package/dist/auth.js.map +1 -1
- package/dist/heartbeat-handler.js.map +1 -1
- package/dist/index.d.ts +9 -9
- package/dist/index.d.ts.map +1 -1
- package/dist/oidc-callback.js.map +1 -1
- package/dist/oidc-login.js.map +1 -1
- package/dist/oidc-logout.js.map +1 -1
- package/package.json +4 -4
package/dist/auth.d.ts
CHANGED
|
@@ -6,9 +6,9 @@
|
|
|
6
6
|
import { AuthorizedFetchError, type AuthorizedFetchErrorReason, type AuthorizedFetchOptions, type AuthorizedFetchResult, type ClearSessionOptions, type ReadSessionResult, type RefreshSessionResult, type SessionSecret, type SessionStore, type StoredSession } from '@eventuras/fides-auth/server';
|
|
7
7
|
import type { OAuthConfig } from '@eventuras/fides-auth/oauth';
|
|
8
8
|
import type { CreateSessionOptions, Session } from '@eventuras/fides-auth/types';
|
|
9
|
-
import { type OidcCallbackConfig } from './oidc-callback';
|
|
10
|
-
import { type OidcLoginConfig } from './oidc-login';
|
|
11
|
-
import { type OidcLogoutConfig } from './oidc-logout';
|
|
9
|
+
import { type OidcCallbackConfig } from './oidc-callback.js';
|
|
10
|
+
import { type OidcLoginConfig } from './oidc-login.js';
|
|
11
|
+
import { type OidcLogoutConfig } from './oidc-logout.js';
|
|
12
12
|
export type { ClearSessionOptions, ReadSessionResult, RefreshSessionResult, SessionSecret };
|
|
13
13
|
export type { SessionStore, StoredSession };
|
|
14
14
|
export type { AuthorizedFetchErrorReason, AuthorizedFetchOptions, AuthorizedFetchResult };
|
package/dist/auth.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"auth.d.ts","sourceRoot":"","sources":["../src/auth.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAEL,oBAAoB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C,CAAC,CAAC,GACtC,OAAO,CAAC,qBAAqB,CAAC,CAAC,CAAC,CAAC,CAAC;IAErC,eAAe,CAAC,OAAO,EAAE,OAAO,EAAE,OAAO,CAAC,EAAE,KAAK,CAAC,eAAe,CAAC,GAAG,OAAO,CAAC,QAAQ,CAAC,CAAC;IACvF,kBAAkB,CAAC,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,KAAK,CAAC,kBAAkB,CAAC,GAAG,OAAO,CAAC,QAAQ,CAAC,CAAC;IAC5F,gBAAgB,CAAC,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,KAAK,CAAC,gBAAgB,CAAC,GAAG,OAAO,CAAC,QAAQ,CAAC,CAAC;IACxF,eAAe,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,QAAQ,CAAC,CAAC;CACtD;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,eAAe,CAAC,EAAE,MAAM,EAAE,WAAW,EAAE,YAAY,EAAE,EAAE,eAAe,GAAG,SAAS,CA+EjG"}
|
package/dist/auth.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"auth.js","names":["handleOidcLogin","handleOidcCallback","handleOidcLogout","handleHeartbeat"],"sources":["../src/auth.ts"],"sourcesContent":["/**\n * The session helpers and route handlers, bound to one secret and OAuth config.\n * No module state: the config lives in the returned object, so a module that\n * Next loads more than once behaves the same.\n */\n\nimport {\n authorizedFetch,\n AuthorizedFetchError,\n clearSession,\n persistSession,\n refreshSessionInStore,\n serverPersistence,\n tryReadSession,\n tryRefreshSessionInStore,\n type AuthorizedFetchErrorReason,\n type AuthorizedFetchOptions,\n type AuthorizedFetchResult,\n type ClearSessionOptions,\n type ReadSessionResult,\n type RefreshSessionResult,\n type SessionPersistence,\n type SessionSecret,\n type SessionStore,\n type StoredSession,\n} from '@eventuras/fides-auth/server';\nimport type { OAuthConfig } from '@eventuras/fides-auth/oauth';\nimport type { CreateSessionOptions, Session } from '@eventuras/fides-auth/types';\nimport { cookies } from 'next/headers';\nimport { cache } from 'react';\n\nimport { nextCookieStore } from './cookie-store';\nimport { handleHeartbeat } from './heartbeat-handler';\nimport { handleOidcCallback, type OidcCallbackConfig } from './oidc-callback';\nimport { handleOidcLogin, type OidcLoginConfig } from './oidc-login';\nimport { handleOidcLogout, type OidcLogoutConfig } from './oidc-logout';\n\n// So consumers can name the helpers' types without reaching past this package.\nexport type { ClearSessionOptions, ReadSessionResult, RefreshSessionResult, SessionSecret };\nexport type { SessionStore, StoredSession };\nexport type { AuthorizedFetchErrorReason, AuthorizedFetchOptions, AuthorizedFetchResult };\nexport { AuthorizedFetchError };\n\nexport interface FidesAuthConfig {\n /** Session encryption secret, e.g. 64 hex chars. Also seals the login transaction. */\n secret: SessionSecret;\n\n /** OAuth/OIDC configuration. */\n oauthConfig: OAuthConfig;\n\n /**\n * Keeps sessions in this store, encrypted under `secret`; the cookie holds only a handle.\n * Omit to keep them in encrypted cookies.\n */\n sessionStore?: SessionStore;\n}\n\n/** A handler's config minus what the factory binds. */\ntype Bound<T> = Omit<T, 'oauthConfig' | 'secret' | 'persistence'>;\n\nexport type BoundAuthorizedFetchOptions<T = undefined> = Omit<\n AuthorizedFetchOptions<T>,\n 'refresh'\n> & {\n /**\n * `false` skips the refresh, so a 401 is an `http_error`. Use it in a Server Component:\n * Next won't let it write cookies, and a refresh that can't be saved spends the refresh token.\n */\n refresh?: false;\n};\n\nexport interface FidesAuth {\n /** The current session, or null. Cached per render; the access token may have expired. */\n getCurrentSession(): Promise<Session<any> | null>;\n\n /** The current session, or why there is none. Shares the cache with `getCurrentSession`. */\n tryGetCurrentSession(): Promise<ReadSessionResult>;\n\n /** Refreshes the session and saves it. Null on any failure. */\n refreshCurrentSession(options?: CreateSessionOptions): Promise<Session | null>;\n\n /** Refreshes the session and, on failure, says why. Prefer it over `refreshCurrentSession`. */\n tryRefreshCurrentSession(options?: CreateSessionOptions): Promise<RefreshSessionResult>;\n\n /** Persists a new session. Returns the session cookie's value: the encrypted session, or the handle. */\n createAndPersistSession(session: Session): Promise<string>;\n\n /** Deletes the session cookies and, with a `sessionStore`, the record. `trigger` defaults to `logout`. */\n clearCurrentSession(options?: ClearSessionOptions): Promise<void>;\n\n /**\n * `authorizedFetch` that, on a 401, refreshes the session and retries once.\n * Parallel calls in one request share one refresh. The refresh writes cookies, so it works\n * only in Server Actions and Route Handlers; pass `refresh: false` in a Server Component.\n */\n authorizedFetch<T = undefined>(\n session: Session,\n url: string | URL,\n options: BoundAuthorizedFetchOptions<T>,\n ): Promise<AuthorizedFetchResult<T>>;\n\n handleOidcLogin(request: Request, options?: Bound<OidcLoginConfig>): Promise<Response>;\n handleOidcCallback(request: Request, options: Bound<OidcCallbackConfig>): Promise<Response>;\n handleOidcLogout(request: Request, options: Bound<OidcLogoutConfig>): Promise<Response>;\n handleHeartbeat(request: Request): Promise<Response>;\n}\n\n/**\n * Creates the app's auth helpers. Call it once and import the result.\n *\n * @example\n * ```ts\n * // lib/auth.ts\n * export const auth = createFidesAuth({ secret: process.env.SESSION_SECRET!, oauthConfig });\n *\n * // app/api/auth/login/route.ts\n * export const GET = (request: Request) => auth.handleOidcLogin(request);\n *\n * // A server component\n * const session = await auth.getCurrentSession();\n * ```\n */\nexport function createFidesAuth({ secret, oauthConfig, sessionStore }: FidesAuthConfig): FidesAuth {\n // One per instance, so refreshes of one session are shared across requests. Built on first use.\n let persistence: SessionPersistence | undefined;\n const serverSessions = (): SessionPersistence | undefined => {\n if (sessionStore) persistence ??= serverPersistence({ store: sessionStore, secret });\n return persistence;\n };\n /** Where sessions live: the store, or else the cookies under `secret`. */\n const storage = (): SessionSecret | SessionPersistence => serverSessions() ?? secret;\n\n const tryGetCurrentSession = cache(\n async (): Promise<ReadSessionResult> => tryReadSession(await nextCookieStore(), storage()),\n );\n const getCurrentSession = cache(async () => (await tryGetCurrentSession()).session);\n\n // Keyed by the request's cookies, so parallel 401s don't each spend the refresh token.\n // Needed with a store too, which joins only refreshes that overlap.\n const refreshes = new WeakMap<object, Promise<RefreshSessionResult>>();\n const refreshOncePerRequest = async (): Promise<RefreshSessionResult> => {\n const requestCookies = await cookies();\n let refresh = refreshes.get(requestCookies);\n if (!refresh) {\n refresh = nextCookieStore().then((store) =>\n tryRefreshSessionInStore(store, oauthConfig, storage()),\n );\n refreshes.set(requestCookies, refresh);\n }\n return refresh;\n };\n\n return {\n getCurrentSession,\n tryGetCurrentSession,\n\n refreshCurrentSession: async (options = {}) =>\n refreshSessionInStore(await nextCookieStore(), oauthConfig, storage(), options),\n\n tryRefreshCurrentSession: async (options = {}) =>\n tryRefreshSessionInStore(await nextCookieStore(), oauthConfig, storage(), options),\n\n createAndPersistSession: async (session) =>\n persistSession(await nextCookieStore(), session, storage()),\n\n clearCurrentSession: async (options = {}) => {\n // The sid comes from the per-render cache, so correlating the logout costs nothing.\n const sid = options.sid ?? (await tryGetCurrentSession()).session?.sid;\n await clearSession(await nextCookieStore(), {\n trigger: options.trigger ?? 'logout',\n sid,\n persistence: serverSessions(),\n });\n },\n\n authorizedFetch: (session, url, options) =>\n authorizedFetch(session, url, {\n ...options,\n refresh: options.refresh === false ? undefined : refreshOncePerRequest,\n }),\n\n // Login only seals the transaction cookie, so it takes the secret alone.\n handleOidcLogin: (request, options = {}) =>\n handleOidcLogin(request, { ...options, oauthConfig, secret }),\n handleOidcCallback: (request, options) =>\n handleOidcCallback(request, {\n ...options,\n oauthConfig,\n secret,\n persistence: serverSessions(),\n }),\n handleOidcLogout: (request, options) =>\n handleOidcLogout(request, {\n ...options,\n oauthConfig,\n secret,\n persistence: serverSessions(),\n }),\n handleHeartbeat: (request) =>\n handleHeartbeat(request, { oauthConfig, secret, persistence: serverSessions() }),\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA0HA,SAAgB,gBAAgB,EAAE,QAAQ,aAAa,gBAA4C;CAEjG,IAAI;CACJ,MAAM,uBAAuD;EAC3D,IAAI,cAAc,gBAAgB,kBAAkB;GAAE,OAAO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qB,SAAS,YAC5BC,qBAAmB,SAAS;GAC1B,GAAG;GACH;GACA;GACA,aAAa,eAAe;EAC9B,CAAC;EACH,mBAAmB,SAAS,YAC1BC,mBAAiB,SAAS;GACxB,GAAG;GACH;GACA;GACA,aAAa,eAAe;EAC9B,CAAC;EACH,kBAAkB,YAChBC,kBAAgB,SAAS;GAAE;GAAa;GAAQ,aAAa,eAAe;EAAE,CAAC;CACnF;AACF"}
|
|
1
|
+
{"version":3,"file":"auth.js","names":["handleOidcLogin","handleOidcCallback","handleOidcLogout","handleHeartbeat"],"sources":["../src/auth.ts"],"sourcesContent":["/**\n * The session helpers and route handlers, bound to one secret and OAuth config.\n * No module state: the config lives in the returned object, so a module that\n * Next loads more than once behaves the same.\n */\n\nimport {\n authorizedFetch,\n AuthorizedFetchError,\n clearSession,\n persistSession,\n refreshSessionInStore,\n serverPersistence,\n tryReadSession,\n tryRefreshSessionInStore,\n type AuthorizedFetchErrorReason,\n type AuthorizedFetchOptions,\n type AuthorizedFetchResult,\n type ClearSessionOptions,\n type ReadSessionResult,\n type RefreshSessionResult,\n type SessionPersistence,\n type SessionSecret,\n type SessionStore,\n type StoredSession,\n} from '@eventuras/fides-auth/server';\nimport type { OAuthConfig } from '@eventuras/fides-auth/oauth';\nimport type { CreateSessionOptions, Session } from '@eventuras/fides-auth/types';\nimport { cookies } from 'next/headers';\nimport { cache } from 'react';\n\nimport { nextCookieStore } from './cookie-store.js';\nimport { handleHeartbeat } from './heartbeat-handler.js';\nimport { handleOidcCallback, type OidcCallbackConfig } from './oidc-callback.js';\nimport { handleOidcLogin, type OidcLoginConfig } from './oidc-login.js';\nimport { handleOidcLogout, type OidcLogoutConfig } from './oidc-logout.js';\n\n// So consumers can name the helpers' types without reaching past this package.\nexport type { ClearSessionOptions, ReadSessionResult, RefreshSessionResult, SessionSecret };\nexport type { SessionStore, StoredSession };\nexport type { AuthorizedFetchErrorReason, AuthorizedFetchOptions, AuthorizedFetchResult };\nexport { AuthorizedFetchError };\n\nexport interface FidesAuthConfig {\n /** Session encryption secret, e.g. 64 hex chars. Also seals the login transaction. */\n secret: SessionSecret;\n\n /** OAuth/OIDC configuration. */\n oauthConfig: OAuthConfig;\n\n /**\n * Keeps sessions in this store, encrypted under `secret`; the cookie holds only a handle.\n * Omit to keep them in encrypted cookies.\n */\n sessionStore?: SessionStore;\n}\n\n/** A handler's config minus what the factory binds. */\ntype Bound<T> = Omit<T, 'oauthConfig' | 'secret' | 'persistence'>;\n\nexport type BoundAuthorizedFetchOptions<T = undefined> = Omit<\n AuthorizedFetchOptions<T>,\n 'refresh'\n> & {\n /**\n * `false` skips the refresh, so a 401 is an `http_error`. Use it in a Server Component:\n * Next won't let it write cookies, and a refresh that can't be saved spends the refresh token.\n */\n refresh?: false;\n};\n\nexport interface FidesAuth {\n /** The current session, or null. Cached per render; the access token may have expired. */\n getCurrentSession(): Promise<Session<any> | null>;\n\n /** The current session, or why there is none. Shares the cache with `getCurrentSession`. */\n tryGetCurrentSession(): Promise<ReadSessionResult>;\n\n /** Refreshes the session and saves it. Null on any failure. */\n refreshCurrentSession(options?: CreateSessionOptions): Promise<Session | null>;\n\n /** Refreshes the session and, on failure, says why. Prefer it over `refreshCurrentSession`. */\n tryRefreshCurrentSession(options?: CreateSessionOptions): Promise<RefreshSessionResult>;\n\n /** Persists a new session. Returns the session cookie's value: the encrypted session, or the handle. */\n createAndPersistSession(session: Session): Promise<string>;\n\n /** Deletes the session cookies and, with a `sessionStore`, the record. `trigger` defaults to `logout`. */\n clearCurrentSession(options?: ClearSessionOptions): Promise<void>;\n\n /**\n * `authorizedFetch` that, on a 401, refreshes the session and retries once.\n * Parallel calls in one request share one refresh. The refresh writes cookies, so it works\n * only in Server Actions and Route Handlers; pass `refresh: false` in a Server Component.\n */\n authorizedFetch<T = undefined>(\n session: Session,\n url: string | URL,\n options: BoundAuthorizedFetchOptions<T>,\n ): Promise<AuthorizedFetchResult<T>>;\n\n handleOidcLogin(request: Request, options?: Bound<OidcLoginConfig>): Promise<Response>;\n handleOidcCallback(request: Request, options: Bound<OidcCallbackConfig>): Promise<Response>;\n handleOidcLogout(request: Request, options: Bound<OidcLogoutConfig>): Promise<Response>;\n handleHeartbeat(request: Request): Promise<Response>;\n}\n\n/**\n * Creates the app's auth helpers. Call it once and import the result.\n *\n * @example\n * ```ts\n * // lib/auth.ts\n * export const auth = createFidesAuth({ secret: process.env.SESSION_SECRET!, oauthConfig });\n *\n * // app/api/auth/login/route.ts\n * export const GET = (request: Request) => auth.handleOidcLogin(request);\n *\n * // A server component\n * const session = await auth.getCurrentSession();\n * ```\n */\nexport function createFidesAuth({ secret, oauthConfig, sessionStore }: FidesAuthConfig): FidesAuth {\n // One per instance, so refreshes of one session are shared across requests. Built on first use.\n let persistence: SessionPersistence | undefined;\n const serverSessions = (): SessionPersistence | undefined => {\n if (sessionStore) persistence ??= serverPersistence({ store: sessionStore, secret });\n return persistence;\n };\n /** Where sessions live: the store, or else the cookies under `secret`. */\n const storage = (): SessionSecret | SessionPersistence => serverSessions() ?? secret;\n\n const tryGetCurrentSession = cache(\n async (): Promise<ReadSessionResult> => tryReadSession(await nextCookieStore(), storage()),\n );\n const getCurrentSession = cache(async () => (await tryGetCurrentSession()).session);\n\n // Keyed by the request's cookies, so parallel 401s don't each spend the refresh token.\n // Needed with a store too, which joins only refreshes that overlap.\n const refreshes = new WeakMap<object, Promise<RefreshSessionResult>>();\n const refreshOncePerRequest = async (): Promise<RefreshSessionResult> => {\n const requestCookies = await cookies();\n let refresh = refreshes.get(requestCookies);\n if (!refresh) {\n refresh = nextCookieStore().then((store) =>\n tryRefreshSessionInStore(store, oauthConfig, storage()),\n );\n refreshes.set(requestCookies, refresh);\n }\n return refresh;\n };\n\n return {\n getCurrentSession,\n tryGetCurrentSession,\n\n refreshCurrentSession: async (options = {}) =>\n refreshSessionInStore(await nextCookieStore(), oauthConfig, storage(), options),\n\n tryRefreshCurrentSession: async (options = {}) =>\n tryRefreshSessionInStore(await nextCookieStore(), oauthConfig, storage(), options),\n\n createAndPersistSession: async (session) =>\n persistSession(await nextCookieStore(), session, storage()),\n\n clearCurrentSession: async (options = {}) => {\n // The sid comes from the per-render cache, so correlating the logout costs nothing.\n const sid = options.sid ?? (await tryGetCurrentSession()).session?.sid;\n await clearSession(await nextCookieStore(), {\n trigger: options.trigger ?? 'logout',\n sid,\n persistence: serverSessions(),\n });\n },\n\n authorizedFetch: (session, url, options) =>\n authorizedFetch(session, url, {\n ...options,\n refresh: options.refresh === false ? undefined : refreshOncePerRequest,\n }),\n\n // Login only seals the transaction cookie, so it takes the secret alone.\n handleOidcLogin: (request, options = {}) =>\n handleOidcLogin(request, { ...options, oauthConfig, secret }),\n handleOidcCallback: (request, options) =>\n handleOidcCallback(request, {\n ...options,\n oauthConfig,\n secret,\n persistence: serverSessions(),\n }),\n handleOidcLogout: (request, options) =>\n handleOidcLogout(request, {\n ...options,\n oauthConfig,\n secret,\n persistence: serverSessions(),\n }),\n handleHeartbeat: (request) =>\n handleHeartbeat(request, { oauthConfig, secret, persistence: serverSessions() }),\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA0HA,SAAgB,gBAAgB,EAAE,QAAQ,aAAa,gBAA4C;CAEjG,IAAI;CACJ,MAAM,uBAAuD;EAC3D,IAAI,cAAc,gBAAgB,kBAAkB;GAAE,OAAO;GAAc;EAAO,CAAC;EACnF,OAAO;CACT;;CAEA,MAAM,gBAAoD,eAAe,KAAK;CAE9E,MAAM,uBAAuB,MAC3B,YAAwC,eAAe,MAAM,gBAAgB,GAAG,QAAQ,CAAC,CAC3F;CACA,MAAM,oBAAoB,MAAM,aAAa,MAAM,qBAAqB,EAAA,CAAG,OAAO;CAIlF,MAAM,4BAAY,IAAI,QAA+C;CACrE,MAAM,wBAAwB,YAA2C;EACvE,MAAM,iBAAiB,MAAM,QAAQ;EACrC,IAAI,UAAU,UAAU,IAAI,cAAc;EAC1C,IAAI,CAAC,SAAS;GACZ,UAAU,gBAAgB,CAAC,CAAC,MAAM,UAChC,yBAAyB,OAAO,aAAa,QAAQ,CAAC,CACxD;GACA,UAAU,IAAI,gBAAgB,OAAO;EACvC;EACA,OAAO;CACT;CAEA,OAAO;EACL;EACA;EAEA,uBAAuB,OAAO,UAAU,CAAC,MACvC,sBAAsB,MAAM,gBAAgB,GAAG,aAAa,QAAQ,GAAG,OAAO;EAEhF,0BAA0B,OAAO,UAAU,CAAC,MAC1C,yBAAyB,MAAM,gBAAgB,GAAG,aAAa,QAAQ,GAAG,OAAO;EAEnF,yBAAyB,OAAO,YAC9B,eAAe,MAAM,gBAAgB,GAAG,SAAS,QAAQ,CAAC;EAE5D,qBAAqB,OAAO,UAAU,CAAC,MAAM;GAE3C,MAAM,MAAM,QAAQ,QAAQ,MAAM,qBAAqB,EAAA,CAAG,SAAS;GACnE,MAAM,aAAa,MAAM,gBAAgB,GAAG;IAC1C,SAAS,QAAQ,WAAW;IAC5B;IACA,aAAa,eAAe;GAC9B,CAAC;EACH;EAEA,kBAAkB,SAAS,KAAK,YAC9B,gBAAgB,SAAS,KAAK;GAC5B,GAAG;GACH,SAAS,QAAQ,YAAY,QAAQ,KAAA,IAAY;EACnD,CAAC;EAGH,kBAAkB,SAAS,UAAU,CAAC,MACpCA,kBAAgB,SAAS;GAAE,GAAG;GAAS;GAAa;EAAO,CAAC;EAC9D,qBAAqB,SAAS,YAC5BC,qBAAmB,SAAS;GAC1B,GAAG;GACH;GACA;GACA,aAAa,eAAe;EAC9B,CAAC;EACH,mBAAmB,SAAS,YAC1BC,mBAAiB,SAAS;GACxB,GAAG;GACH;GACA;GACA,aAAa,eAAe;EAC9B,CAAC;EACH,kBAAkB,YAChBC,kBAAgB,SAAS;GAAE;GAAa;GAAQ,aAAa,eAAe;EAAE,CAAC;CACnF;AACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"heartbeat-handler.js","names":["coreHandleHeartbeat"],"sources":["../src/heartbeat-handler.ts"],"sourcesContent":["/**\n * Server-side heartbeat handler for Next.js route handlers — a thin wrapper over\n * the framework-agnostic handler in `@eventuras/fides-auth/server`, wiring it to\n * the Next cookie store and the global POST rate limiter.\n *\n * Pairs with the client-side `useHeartbeat` hook: when the user is active, the\n * client POSTs here, and this handler exchanges the current refresh token for a\n * fresh access token (and rotated refresh token, if the IdP rotates).\n */\n\nimport {\n handleHeartbeat as coreHandleHeartbeat,\n type SessionPersistence,\n type SessionSecret,\n} from '@eventuras/fides-auth/server';\nimport type { OAuthConfig } from '@eventuras/fides-auth/oauth';\n\nimport { nextCookieStore } from './cookie-store';\nimport { globalPOSTRateLimit } from './request';\n\nexport interface HeartbeatHandlerConfig {\n /** OAuth/OIDC configuration used to refresh the access token. */\n oauthConfig: OAuthConfig;\n\n /** Session encryption secret. */\n secret: SessionSecret;\n\n /** Where the session lives. Defaults to the cookies under `secret`; see `serverPersistence`. */\n persistence?: SessionPersistence;\n}\n\n/**\n * Handles a heartbeat request in a Next.js route handler. `createFidesAuth`\n * returns this with `oauthConfig` and `secret` bound.\n *\n * @example\n * ```ts\n * // app/(auth)/api/auth/heartbeat/route.ts\n * import { handleHeartbeat } from '@eventuras/fides-auth-next/heartbeat-handler';\n * import { oauthConfig } from '@/utils/oauthConfig';\n *\n * export async function POST(request: Request) {\n * return handleHeartbeat(request, { oauthConfig, secret: process.env.SESSION_SECRET! });\n * }\n * ```\n */\nexport async function handleHeartbeat(\n request: Request,\n config: HeartbeatHandlerConfig,\n): Promise<Response> {\n return coreHandleHeartbeat(request, {\n oauthConfig: config.oauthConfig,\n secret: config.secret,\n persistence: config.persistence,\n cookies: await nextCookieStore(),\n rateLimit: globalPOSTRateLimit,\n });\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AA8CA,eAAsB,gBACpB,SACA,QACmB;CACnB,OAAOA,kBAAoB,SAAS;EAClC,aAAa,OAAO;EACpB,QAAQ,OAAO;EACf,aAAa,OAAO;EACpB,SAAS,MAAM,gBAAgB;EAC/B,WAAW;CACb,CAAC;AACH"}
|
|
1
|
+
{"version":3,"file":"heartbeat-handler.js","names":["coreHandleHeartbeat"],"sources":["../src/heartbeat-handler.ts"],"sourcesContent":["/**\n * Server-side heartbeat handler for Next.js route handlers — a thin wrapper over\n * the framework-agnostic handler in `@eventuras/fides-auth/server`, wiring it to\n * the Next cookie store and the global POST rate limiter.\n *\n * Pairs with the client-side `useHeartbeat` hook: when the user is active, the\n * client POSTs here, and this handler exchanges the current refresh token for a\n * fresh access token (and rotated refresh token, if the IdP rotates).\n */\n\nimport {\n handleHeartbeat as coreHandleHeartbeat,\n type SessionPersistence,\n type SessionSecret,\n} from '@eventuras/fides-auth/server';\nimport type { OAuthConfig } from '@eventuras/fides-auth/oauth';\n\nimport { nextCookieStore } from './cookie-store.js';\nimport { globalPOSTRateLimit } from './request.js';\n\nexport interface HeartbeatHandlerConfig {\n /** OAuth/OIDC configuration used to refresh the access token. */\n oauthConfig: OAuthConfig;\n\n /** Session encryption secret. */\n secret: SessionSecret;\n\n /** Where the session lives. Defaults to the cookies under `secret`; see `serverPersistence`. */\n persistence?: SessionPersistence;\n}\n\n/**\n * Handles a heartbeat request in a Next.js route handler. `createFidesAuth`\n * returns this with `oauthConfig` and `secret` bound.\n *\n * @example\n * ```ts\n * // app/(auth)/api/auth/heartbeat/route.ts\n * import { handleHeartbeat } from '@eventuras/fides-auth-next/heartbeat-handler';\n * import { oauthConfig } from '@/utils/oauthConfig';\n *\n * export async function POST(request: Request) {\n * return handleHeartbeat(request, { oauthConfig, secret: process.env.SESSION_SECRET! });\n * }\n * ```\n */\nexport async function handleHeartbeat(\n request: Request,\n config: HeartbeatHandlerConfig,\n): Promise<Response> {\n return coreHandleHeartbeat(request, {\n oauthConfig: config.oauthConfig,\n secret: config.secret,\n persistence: config.persistence,\n cookies: await nextCookieStore(),\n rateLimit: globalPOSTRateLimit,\n });\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AA8CA,eAAsB,gBACpB,SACA,QACmB;CACnB,OAAOA,kBAAoB,SAAS;EAClC,aAAa,OAAO;EACpB,QAAQ,OAAO;EACf,aAAa,OAAO;EACpB,SAAS,MAAM,gBAAgB;EAC/B,WAAW;CACb,CAAC;AACH"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
export * from './cookie-store';
|
|
2
|
-
export * from './request';
|
|
3
|
-
export * from './auth';
|
|
4
|
-
export * from './cookies';
|
|
5
|
-
export * from './oidc-callback';
|
|
6
|
-
export * from './oidc-login';
|
|
7
|
-
export * from './oidc-logout';
|
|
8
|
-
export * from './heartbeat-handler';
|
|
9
|
-
export * from './store';
|
|
1
|
+
export * from './cookie-store.js';
|
|
2
|
+
export * from './request.js';
|
|
3
|
+
export * from './auth.js';
|
|
4
|
+
export * from './cookies.js';
|
|
5
|
+
export * from './oidc-callback.js';
|
|
6
|
+
export * from './oidc-login.js';
|
|
7
|
+
export * from './oidc-logout.js';
|
|
8
|
+
export * from './heartbeat-handler.js';
|
|
9
|
+
export * from './store/index.js';
|
|
10
10
|
export * from '@eventuras/fides-auth/oauth';
|
|
11
11
|
export type { OAuthConfig } from '@eventuras/fides-auth/oauth';
|
|
12
12
|
export * from '@eventuras/fides-auth/logger';
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,cAAc,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,cAAc,mBAAmB,CAAC;AAClC,cAAc,cAAc,CAAC;AAC7B,cAAc,WAAW,CAAC;AAC1B,cAAc,cAAc,CAAC;AAC7B,cAAc,oBAAoB,CAAC;AACnC,cAAc,iBAAiB,CAAC;AAChC,cAAc,kBAAkB,CAAC;AACjC,cAAc,wBAAwB,CAAC;AAGvC,cAAc,kBAAkB,CAAC;AAGjC,cAAc,6BAA6B,CAAC;AAC5C,YAAY,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAC;AAC/D,cAAc,8BAA8B,CAAC;AAC7C,cAAc,sCAAsC,CAAC;AACrD,cAAc,uCAAuC,CAAC;AACtD,cAAc,0CAA0C,CAAC;AACzD,cAAc,oCAAoC,CAAC;AACnD,cAAc,6BAA6B,CAAC;AAC5C,cAAc,6BAA6B,CAAC;AAC5C,OAAO;AACL,mGAAmG;AACnG,WAAW,GACZ,MAAM,kCAAkC,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"oidc-callback.js","names":["coreHandleOidcCallback"],"sources":["../src/oidc-callback.ts"],"sourcesContent":["/**\n * OIDC callback handler for Next.js route handlers — a thin wrapper over the\n * framework-agnostic handler in `@eventuras/fides-auth/server`, wiring it to the\n * Next cookie store and the global GET rate limiter.\n */\n\nimport {\n handleOidcCallback as coreHandleOidcCallback,\n type SessionPersistence,\n type SessionSecret,\n} from '@eventuras/fides-auth/server';\nimport type { MapSession, OAuthConfig } from '@eventuras/fides-auth/oauth';\n\nimport { nextCookieStore } from './cookie-store';\nimport { globalGETRateLimit } from './request';\n\nexport interface OidcCallbackConfig {\n /** OAuth/OIDC configuration (issuer, clientId, clientSecret, redirect_uri, scope) */\n oauthConfig: OAuthConfig;\n\n /** Opens the login transaction and encrypts the session. Must match the login's. */\n secret: SessionSecret;\n\n /** Where the session lives. Defaults to the cookies under `secret`; see `serverPersistence`. */\n persistence?: SessionPersistence;\n\n /** Public application URL (used to reconstruct the callback URL and validate redirects) */\n applicationUrl: string;\n\n /**\n * Name of the ID token claim that contains user roles.\n * @default 'roles'\n */\n rolesClaim?: string;\n\n /** Changes the session before it is stored, e.g. to add `data`. See {@link MapSession}. */\n mapSession?: MapSession;\n\n /**\n * Default path to redirect to after login if no returnTo cookie is set.\n * @default '/'\n */\n defaultRedirectPath?: string;\n\n /**\n * Optional function to validate the returnTo path.\n * If not provided, only same-origin paths are allowed.\n */\n validateReturnTo?: (path: string) => boolean;\n\n /**\n * Reserved for backwards compatibility. Currently not applied — the session\n * cookie lifetime is fixed by the default cookie options.\n */\n sessionDurationDays?: number;\n}\n\n/**\n * Handles the OIDC callback in a Next.js route handler. `createFidesAuth` returns\n * this with `oauthConfig` and `secret` bound.\n *\n * @example\n * ```ts\n * // In app/api/auth/callback/oidc/route.ts\n * import { handleOidcCallback } from '@eventuras/fides-auth-next/oidc-callback';\n *\n * export async function GET(request: Request) {\n * return handleOidcCallback(request, {\n * oauthConfig,\n * secret: process.env.SESSION_SECRET!,\n * applicationUrl: 'https://example.com',\n * rolesClaim: 'roles',\n * });\n * }\n * ```\n */\nexport async function handleOidcCallback(\n request: Request,\n config: OidcCallbackConfig,\n): Promise<Response> {\n // Map explicitly rather than spreading: sessionDurationDays is accepted for\n // backwards compatibility but the core handler doesn't take it.\n return coreHandleOidcCallback(request, {\n oauthConfig: config.oauthConfig,\n secret: config.secret,\n persistence: config.persistence,\n applicationUrl: config.applicationUrl,\n rolesClaim: config.rolesClaim,\n mapSession: config.mapSession,\n defaultRedirectPath: config.defaultRedirectPath,\n validateReturnTo: config.validateReturnTo,\n cookies: await nextCookieStore(),\n rateLimit: globalGETRateLimit,\n });\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AA4EA,eAAsB,mBACpB,SACA,QACmB;CAGnB,OAAOA,qBAAuB,SAAS;EACrC,aAAa,OAAO;EACpB,QAAQ,OAAO;EACf,aAAa,OAAO;EACpB,gBAAgB,OAAO;EACvB,YAAY,OAAO;EACnB,YAAY,OAAO;EACnB,qBAAqB,OAAO;EAC5B,kBAAkB,OAAO;EACzB,SAAS,MAAM,gBAAgB;EAC/B,WAAW;CACb,CAAC;AACH"}
|
|
1
|
+
{"version":3,"file":"oidc-callback.js","names":["coreHandleOidcCallback"],"sources":["../src/oidc-callback.ts"],"sourcesContent":["/**\n * OIDC callback handler for Next.js route handlers — a thin wrapper over the\n * framework-agnostic handler in `@eventuras/fides-auth/server`, wiring it to the\n * Next cookie store and the global GET rate limiter.\n */\n\nimport {\n handleOidcCallback as coreHandleOidcCallback,\n type SessionPersistence,\n type SessionSecret,\n} from '@eventuras/fides-auth/server';\nimport type { MapSession, OAuthConfig } from '@eventuras/fides-auth/oauth';\n\nimport { nextCookieStore } from './cookie-store.js';\nimport { globalGETRateLimit } from './request.js';\n\nexport interface OidcCallbackConfig {\n /** OAuth/OIDC configuration (issuer, clientId, clientSecret, redirect_uri, scope) */\n oauthConfig: OAuthConfig;\n\n /** Opens the login transaction and encrypts the session. Must match the login's. */\n secret: SessionSecret;\n\n /** Where the session lives. Defaults to the cookies under `secret`; see `serverPersistence`. */\n persistence?: SessionPersistence;\n\n /** Public application URL (used to reconstruct the callback URL and validate redirects) */\n applicationUrl: string;\n\n /**\n * Name of the ID token claim that contains user roles.\n * @default 'roles'\n */\n rolesClaim?: string;\n\n /** Changes the session before it is stored, e.g. to add `data`. See {@link MapSession}. */\n mapSession?: MapSession;\n\n /**\n * Default path to redirect to after login if no returnTo cookie is set.\n * @default '/'\n */\n defaultRedirectPath?: string;\n\n /**\n * Optional function to validate the returnTo path.\n * If not provided, only same-origin paths are allowed.\n */\n validateReturnTo?: (path: string) => boolean;\n\n /**\n * Reserved for backwards compatibility. Currently not applied — the session\n * cookie lifetime is fixed by the default cookie options.\n */\n sessionDurationDays?: number;\n}\n\n/**\n * Handles the OIDC callback in a Next.js route handler. `createFidesAuth` returns\n * this with `oauthConfig` and `secret` bound.\n *\n * @example\n * ```ts\n * // In app/api/auth/callback/oidc/route.ts\n * import { handleOidcCallback } from '@eventuras/fides-auth-next/oidc-callback';\n *\n * export async function GET(request: Request) {\n * return handleOidcCallback(request, {\n * oauthConfig,\n * secret: process.env.SESSION_SECRET!,\n * applicationUrl: 'https://example.com',\n * rolesClaim: 'roles',\n * });\n * }\n * ```\n */\nexport async function handleOidcCallback(\n request: Request,\n config: OidcCallbackConfig,\n): Promise<Response> {\n // Map explicitly rather than spreading: sessionDurationDays is accepted for\n // backwards compatibility but the core handler doesn't take it.\n return coreHandleOidcCallback(request, {\n oauthConfig: config.oauthConfig,\n secret: config.secret,\n persistence: config.persistence,\n applicationUrl: config.applicationUrl,\n rolesClaim: config.rolesClaim,\n mapSession: config.mapSession,\n defaultRedirectPath: config.defaultRedirectPath,\n validateReturnTo: config.validateReturnTo,\n cookies: await nextCookieStore(),\n rateLimit: globalGETRateLimit,\n });\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AA4EA,eAAsB,mBACpB,SACA,QACmB;CAGnB,OAAOA,qBAAuB,SAAS;EACrC,aAAa,OAAO;EACpB,QAAQ,OAAO;EACf,aAAa,OAAO;EACpB,gBAAgB,OAAO;EACvB,YAAY,OAAO;EACnB,YAAY,OAAO;EACnB,qBAAqB,OAAO;EAC5B,kBAAkB,OAAO;EACzB,SAAS,MAAM,gBAAgB;EAC/B,WAAW;CACb,CAAC;AACH"}
|
package/dist/oidc-login.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"oidc-login.js","names":["coreHandleOidcLogin"],"sources":["../src/oidc-login.ts"],"sourcesContent":["/**\n * OIDC login initiation for Next.js route handlers — a thin wrapper over the\n * framework-agnostic handler in `@eventuras/fides-auth/server`, wiring it to the\n * Next cookie store and the global GET rate limiter.\n */\n\nimport {\n handleOidcLogin as coreHandleOidcLogin,\n type OidcLoginConfig as CoreOidcLoginConfig,\n type SessionSecret,\n} from '@eventuras/fides-auth/server';\nimport type { OAuthConfig } from '@eventuras/fides-auth/oauth';\n\nimport { nextCookieStore } from './cookie-store';\nimport { globalGETRateLimit } from './request';\n\nexport interface OidcLoginConfig {\n /** OAuth/OIDC configuration */\n oauthConfig: OAuthConfig;\n\n /** Seals the login transaction. Must match the callback's. */\n secret: SessionSecret;\n\n /**\n * Validates and sanitizes the returnTo parameter.\n * Should return a safe path or null to use the default.\n * @default Only allows relative paths starting with /\n */\n validateReturnTo?: (rawReturnTo: string) => string | null;\n\n /** Per-request authorization parameters, e.g. `prompt` or `login_hint`. Reserved keys throw. */\n authorizationParameters?: CoreOidcLoginConfig['authorizationParameters'];\n}\n\n/**\n * Handles OIDC login initiation in a Next.js route handler. `createFidesAuth`\n * returns this with `oauthConfig` and `secret` bound.\n *\n * @example\n * ```ts\n * // In app/api/auth/login/route.ts\n * import { handleOidcLogin } from '@eventuras/fides-auth-next/oidc-login';\n *\n * export async function GET(request: Request) {\n * return handleOidcLogin(request, { oauthConfig, secret: process.env.SESSION_SECRET! });\n * }\n * ```\n */\nexport async function handleOidcLogin(\n request: Request,\n config: OidcLoginConfig,\n): Promise<Response> {\n return coreHandleOidcLogin(request, {\n oauthConfig: config.oauthConfig,\n secret: config.secret,\n validateReturnTo: config.validateReturnTo,\n authorizationParameters: config.authorizationParameters,\n cookies: await nextCookieStore(),\n rateLimit: globalGETRateLimit,\n });\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAgDA,eAAsB,gBACpB,SACA,QACmB;CACnB,OAAOA,kBAAoB,SAAS;EAClC,aAAa,OAAO;EACpB,QAAQ,OAAO;EACf,kBAAkB,OAAO;EACzB,yBAAyB,OAAO;EAChC,SAAS,MAAM,gBAAgB;EAC/B,WAAW;CACb,CAAC;AACH"}
|
|
1
|
+
{"version":3,"file":"oidc-login.js","names":["coreHandleOidcLogin"],"sources":["../src/oidc-login.ts"],"sourcesContent":["/**\n * OIDC login initiation for Next.js route handlers — a thin wrapper over the\n * framework-agnostic handler in `@eventuras/fides-auth/server`, wiring it to the\n * Next cookie store and the global GET rate limiter.\n */\n\nimport {\n handleOidcLogin as coreHandleOidcLogin,\n type OidcLoginConfig as CoreOidcLoginConfig,\n type SessionSecret,\n} from '@eventuras/fides-auth/server';\nimport type { OAuthConfig } from '@eventuras/fides-auth/oauth';\n\nimport { nextCookieStore } from './cookie-store.js';\nimport { globalGETRateLimit } from './request.js';\n\nexport interface OidcLoginConfig {\n /** OAuth/OIDC configuration */\n oauthConfig: OAuthConfig;\n\n /** Seals the login transaction. Must match the callback's. */\n secret: SessionSecret;\n\n /**\n * Validates and sanitizes the returnTo parameter.\n * Should return a safe path or null to use the default.\n * @default Only allows relative paths starting with /\n */\n validateReturnTo?: (rawReturnTo: string) => string | null;\n\n /** Per-request authorization parameters, e.g. `prompt` or `login_hint`. Reserved keys throw. */\n authorizationParameters?: CoreOidcLoginConfig['authorizationParameters'];\n}\n\n/**\n * Handles OIDC login initiation in a Next.js route handler. `createFidesAuth`\n * returns this with `oauthConfig` and `secret` bound.\n *\n * @example\n * ```ts\n * // In app/api/auth/login/route.ts\n * import { handleOidcLogin } from '@eventuras/fides-auth-next/oidc-login';\n *\n * export async function GET(request: Request) {\n * return handleOidcLogin(request, { oauthConfig, secret: process.env.SESSION_SECRET! });\n * }\n * ```\n */\nexport async function handleOidcLogin(\n request: Request,\n config: OidcLoginConfig,\n): Promise<Response> {\n return coreHandleOidcLogin(request, {\n oauthConfig: config.oauthConfig,\n secret: config.secret,\n validateReturnTo: config.validateReturnTo,\n authorizationParameters: config.authorizationParameters,\n cookies: await nextCookieStore(),\n rateLimit: globalGETRateLimit,\n });\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAgDA,eAAsB,gBACpB,SACA,QACmB;CACnB,OAAOA,kBAAoB,SAAS;EAClC,aAAa,OAAO;EACpB,QAAQ,OAAO;EACf,kBAAkB,OAAO;EACzB,yBAAyB,OAAO;EAChC,SAAS,MAAM,gBAAgB;EAC/B,WAAW;CACb,CAAC;AACH"}
|
package/dist/oidc-logout.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"oidc-logout.js","names":["coreHandleOidcLogout"],"sources":["../src/oidc-logout.ts"],"sourcesContent":["/**\n * RP-initiated logout for Next.js route handlers — a thin wrapper over the\n * framework-agnostic handler in `@eventuras/fides-auth/server`, wiring it to the\n * Next cookie store and the global POST rate limiter.\n */\n\nimport {\n handleOidcLogout as coreHandleOidcLogout,\n type SessionPersistence,\n type SessionSecret,\n} from '@eventuras/fides-auth/server';\nimport type { OAuthConfig } from '@eventuras/fides-auth/oauth';\n\nimport { nextCookieStore } from './cookie-store';\nimport { globalPOSTRateLimit } from './request';\n\nexport interface OidcLogoutConfig {\n /** OAuth/OIDC configuration */\n oauthConfig: OAuthConfig;\n\n /** Session encryption secret. */\n secret: SessionSecret;\n\n /** Where the session lives. Defaults to the cookies under `secret`; see `serverPersistence`. */\n persistence?: SessionPersistence;\n\n /**\n * URI the provider redirects back to after logout. Must be registered with the\n * provider as a post-logout redirect URI.\n */\n postLogoutRedirectUri: string;\n\n /** Opaque value echoed back on the post-logout redirect. */\n state?: string;\n\n /** `logout_hint`, when the provider documents one. */\n logoutHint?: string;\n\n /** Whether to send `client_id`. Default true. */\n includeClientId?: boolean;\n\n /** Request methods that may trigger a logout. @default ['POST'] */\n allowedMethods?: string[];\n\n /** Public application URL, used to check the `Origin` header behind a proxy. */\n applicationUrl?: string;\n\n /**\n * Where to send the user when the provider advertises no end_session_endpoint.\n * @default postLogoutRedirectUri\n */\n fallbackRedirectUri?: string;\n}\n\n/**\n * Handles logout in a Next.js route handler: clears the session cookies and\n * redirects to the provider's end-session endpoint with `id_token_hint`.\n * `createFidesAuth` returns this with `oauthConfig` and `secret` bound.\n *\n * @example\n * ```ts\n * // In app/api/auth/logout/route.ts\n * import { handleOidcLogout } from '@eventuras/fides-auth-next/oidc-logout';\n *\n * export async function POST(request: Request) {\n * return handleOidcLogout(request, {\n * oauthConfig,\n * secret: process.env.SESSION_SECRET!,\n * postLogoutRedirectUri: 'https://example.com/',\n * });\n * }\n * ```\n */\nexport async function handleOidcLogout(\n request: Request,\n config: OidcLogoutConfig,\n): Promise<Response> {\n return coreHandleOidcLogout(request, {\n oauthConfig: config.oauthConfig,\n secret: config.secret,\n persistence: config.persistence,\n postLogoutRedirectUri: config.postLogoutRedirectUri,\n state: config.state,\n logoutHint: config.logoutHint,\n includeClientId: config.includeClientId,\n fallbackRedirectUri: config.fallbackRedirectUri,\n allowedMethods: config.allowedMethods,\n applicationUrl: config.applicationUrl,\n cookies: await nextCookieStore(),\n rateLimit: globalPOSTRateLimit,\n });\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAyEA,eAAsB,iBACpB,SACA,QACmB;CACnB,OAAOA,mBAAqB,SAAS;EACnC,aAAa,OAAO;EACpB,QAAQ,OAAO;EACf,aAAa,OAAO;EACpB,uBAAuB,OAAO;EAC9B,OAAO,OAAO;EACd,YAAY,OAAO;EACnB,iBAAiB,OAAO;EACxB,qBAAqB,OAAO;EAC5B,gBAAgB,OAAO;EACvB,gBAAgB,OAAO;EACvB,SAAS,MAAM,gBAAgB;EAC/B,WAAW;CACb,CAAC;AACH"}
|
|
1
|
+
{"version":3,"file":"oidc-logout.js","names":["coreHandleOidcLogout"],"sources":["../src/oidc-logout.ts"],"sourcesContent":["/**\n * RP-initiated logout for Next.js route handlers — a thin wrapper over the\n * framework-agnostic handler in `@eventuras/fides-auth/server`, wiring it to the\n * Next cookie store and the global POST rate limiter.\n */\n\nimport {\n handleOidcLogout as coreHandleOidcLogout,\n type SessionPersistence,\n type SessionSecret,\n} from '@eventuras/fides-auth/server';\nimport type { OAuthConfig } from '@eventuras/fides-auth/oauth';\n\nimport { nextCookieStore } from './cookie-store.js';\nimport { globalPOSTRateLimit } from './request.js';\n\nexport interface OidcLogoutConfig {\n /** OAuth/OIDC configuration */\n oauthConfig: OAuthConfig;\n\n /** Session encryption secret. */\n secret: SessionSecret;\n\n /** Where the session lives. Defaults to the cookies under `secret`; see `serverPersistence`. */\n persistence?: SessionPersistence;\n\n /**\n * URI the provider redirects back to after logout. Must be registered with the\n * provider as a post-logout redirect URI.\n */\n postLogoutRedirectUri: string;\n\n /** Opaque value echoed back on the post-logout redirect. */\n state?: string;\n\n /** `logout_hint`, when the provider documents one. */\n logoutHint?: string;\n\n /** Whether to send `client_id`. Default true. */\n includeClientId?: boolean;\n\n /** Request methods that may trigger a logout. @default ['POST'] */\n allowedMethods?: string[];\n\n /** Public application URL, used to check the `Origin` header behind a proxy. */\n applicationUrl?: string;\n\n /**\n * Where to send the user when the provider advertises no end_session_endpoint.\n * @default postLogoutRedirectUri\n */\n fallbackRedirectUri?: string;\n}\n\n/**\n * Handles logout in a Next.js route handler: clears the session cookies and\n * redirects to the provider's end-session endpoint with `id_token_hint`.\n * `createFidesAuth` returns this with `oauthConfig` and `secret` bound.\n *\n * @example\n * ```ts\n * // In app/api/auth/logout/route.ts\n * import { handleOidcLogout } from '@eventuras/fides-auth-next/oidc-logout';\n *\n * export async function POST(request: Request) {\n * return handleOidcLogout(request, {\n * oauthConfig,\n * secret: process.env.SESSION_SECRET!,\n * postLogoutRedirectUri: 'https://example.com/',\n * });\n * }\n * ```\n */\nexport async function handleOidcLogout(\n request: Request,\n config: OidcLogoutConfig,\n): Promise<Response> {\n return coreHandleOidcLogout(request, {\n oauthConfig: config.oauthConfig,\n secret: config.secret,\n persistence: config.persistence,\n postLogoutRedirectUri: config.postLogoutRedirectUri,\n state: config.state,\n logoutHint: config.logoutHint,\n includeClientId: config.includeClientId,\n fallbackRedirectUri: config.fallbackRedirectUri,\n allowedMethods: config.allowedMethods,\n applicationUrl: config.applicationUrl,\n cookies: await nextCookieStore(),\n rateLimit: globalPOSTRateLimit,\n });\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAyEA,eAAsB,iBACpB,SACA,QACmB;CACnB,OAAOA,mBAAqB,SAAS;EACnC,aAAa,OAAO;EACpB,QAAQ,OAAO;EACf,aAAa,OAAO;EACpB,uBAAuB,OAAO;EAC9B,OAAO,OAAO;EACd,YAAY,OAAO;EACnB,iBAAiB,OAAO;EACxB,qBAAqB,OAAO;EAC5B,gBAAgB,OAAO;EACvB,gBAAgB,OAAO;EACvB,SAAS,MAAM,gBAAgB;EAC/B,WAAW;CACb,CAAC;AACH"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@eventuras/fides-auth-next",
|
|
3
|
-
"version": "0.8.
|
|
3
|
+
"version": "0.8.1",
|
|
4
4
|
"description": "Next.js bindings for @eventuras/fides-auth",
|
|
5
5
|
"homepage": "https://github.com/losol/fides-auth/tree/main/packages/fides-auth-next#readme",
|
|
6
6
|
"bugs": {
|
|
@@ -58,9 +58,9 @@
|
|
|
58
58
|
"LICENSE"
|
|
59
59
|
],
|
|
60
60
|
"dependencies": {
|
|
61
|
-
"@eventuras/fides-auth-
|
|
62
|
-
"@eventuras/fides-auth
|
|
63
|
-
"@eventuras/fides-auth": "0.
|
|
61
|
+
"@eventuras/fides-auth-react": "0.1.9",
|
|
62
|
+
"@eventuras/fides-auth": "0.16.0",
|
|
63
|
+
"@eventuras/fides-auth-store": "0.3.1"
|
|
64
64
|
},
|
|
65
65
|
"devDependencies": {
|
|
66
66
|
"@testing-library/jest-dom": "7.0.1",
|