@eventuras/fides-auth-next 0.8.1 → 1.0.0-beta.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/README.md +162 -108
- package/dist/auth.d.ts +101 -54
- package/dist/auth.d.ts.map +1 -1
- package/dist/auth.js +65 -75
- package/dist/auth.js.map +1 -1
- package/dist/cookie-store.d.ts +3 -5
- package/dist/cookie-store.d.ts.map +1 -1
- package/dist/cookie-store.js +3 -8
- package/dist/cookie-store.js.map +1 -1
- package/dist/index.d.ts +4 -21
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -18
- package/package.json +9 -43
- package/dist/cookies.d.ts +0 -132
- package/dist/cookies.d.ts.map +0 -1
- package/dist/cookies.js +0 -220
- package/dist/cookies.js.map +0 -1
- package/dist/heartbeat-handler.d.ts +0 -36
- package/dist/heartbeat-handler.d.ts.map +0 -1
- package/dist/heartbeat-handler.js +0 -40
- package/dist/heartbeat-handler.js.map +0 -1
- package/dist/oidc-callback.d.ts +0 -60
- package/dist/oidc-callback.d.ts.map +0 -1
- package/dist/oidc-callback.js +0 -45
- package/dist/oidc-callback.js.map +0 -1
- package/dist/oidc-login.d.ts +0 -37
- package/dist/oidc-login.d.ts.map +0 -1
- package/dist/oidc-login.js +0 -36
- package/dist/oidc-login.js.map +0 -1
- package/dist/oidc-logout.d.ts +0 -56
- package/dist/oidc-logout.d.ts.map +0 -1
- package/dist/oidc-logout.js +0 -47
- package/dist/oidc-logout.js.map +0 -1
- package/dist/request.d.ts +0 -11
- package/dist/request.d.ts.map +0 -1
- package/dist/request.js +0 -43
- package/dist/request.js.map +0 -1
- package/dist/store/index.d.ts +0 -103
- package/dist/store/index.d.ts.map +0 -1
- package/dist/store/index.js +0 -3
package/dist/auth.js
CHANGED
|
@@ -1,97 +1,87 @@
|
|
|
1
1
|
import { nextCookieStore } from "./cookie-store.js";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import { handleOidcLogin as handleOidcLogin$1 } from "./oidc-login.js";
|
|
5
|
-
import { handleOidcLogout as handleOidcLogout$1 } from "./oidc-logout.js";
|
|
6
|
-
import { cookies } from "next/headers";
|
|
7
|
-
import { AuthorizedFetchError, authorizedFetch, clearSession, persistSession, refreshSessionInStore, serverPersistence, tryReadSession, tryRefreshSessionInStore } from "@eventuras/fides-auth/server";
|
|
2
|
+
import { createFidesAuth } from "@eventuras/fides-auth/server";
|
|
3
|
+
import { NextResponse } from "next/server";
|
|
8
4
|
import { cache } from "react";
|
|
9
5
|
// src/auth.ts
|
|
10
6
|
/**
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
* Next loads more than once behaves the same.
|
|
7
|
+
* A CookieStore over the proxied request's cookies, which records the writes
|
|
8
|
+
* so they can go both to the browser and to the forwarded request.
|
|
14
9
|
*/
|
|
10
|
+
function proxyCookieStore(request) {
|
|
11
|
+
const writes = /* @__PURE__ */ new Map();
|
|
12
|
+
return {
|
|
13
|
+
cookies: {
|
|
14
|
+
get: (name) => {
|
|
15
|
+
const written = writes.get(name);
|
|
16
|
+
if (written) return written.options?.maxAge === 0 ? null : written.value;
|
|
17
|
+
return request.cookies.get(name)?.value ?? null;
|
|
18
|
+
},
|
|
19
|
+
set: (name, value, options) => {
|
|
20
|
+
writes.set(name, {
|
|
21
|
+
value,
|
|
22
|
+
options
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
},
|
|
26
|
+
writes
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
/** Continues the request, carrying the cookie writes to the page and to the browser. */
|
|
30
|
+
function forward(request, writes) {
|
|
31
|
+
if (writes.size === 0) return NextResponse.next();
|
|
32
|
+
for (const [name, { value, options }] of writes) if (options?.maxAge === 0) request.cookies.delete(name);
|
|
33
|
+
else request.cookies.set(name, value);
|
|
34
|
+
const response = NextResponse.next({ request: { headers: request.headers } });
|
|
35
|
+
for (const [name, { value, options }] of writes) response.cookies.set(name, value, options);
|
|
36
|
+
return response;
|
|
37
|
+
}
|
|
15
38
|
/**
|
|
16
|
-
* Creates the app's auth
|
|
39
|
+
* Creates the app's auth instance. Call it once, in a module of its own, and
|
|
40
|
+
* import the result. It reads nothing from the environment: pass the secret and
|
|
41
|
+
* the provider config in.
|
|
17
42
|
*
|
|
18
43
|
* @example
|
|
19
44
|
* ```ts
|
|
20
45
|
* // lib/auth.ts
|
|
21
|
-
* export const auth = createFidesAuth({ secret: process.env.SESSION_SECRET
|
|
46
|
+
* export const auth = createFidesAuth({ oauthConfig, secret: process.env.SESSION_SECRET! });
|
|
22
47
|
*
|
|
23
48
|
* // app/api/auth/login/route.ts
|
|
24
49
|
* export const GET = (request: Request) => auth.handleOidcLogin(request);
|
|
25
50
|
*
|
|
26
|
-
* // A
|
|
27
|
-
* const session = await auth.
|
|
51
|
+
* // A Server Component
|
|
52
|
+
* const session = await auth.readSession();
|
|
28
53
|
* ```
|
|
29
54
|
*/
|
|
30
|
-
function createFidesAuth(
|
|
31
|
-
|
|
32
|
-
const
|
|
33
|
-
if (sessionStore) persistence ??= serverPersistence({
|
|
34
|
-
store: sessionStore,
|
|
35
|
-
secret
|
|
36
|
-
});
|
|
37
|
-
return persistence;
|
|
38
|
-
};
|
|
39
|
-
/** Where sessions live: the store, or else the cookies under `secret`. */
|
|
40
|
-
const storage = () => serverSessions() ?? secret;
|
|
41
|
-
const tryGetCurrentSession = cache(async () => tryReadSession(await nextCookieStore(), storage()));
|
|
42
|
-
const getCurrentSession = cache(async () => (await tryGetCurrentSession()).session);
|
|
43
|
-
const refreshes = /* @__PURE__ */ new WeakMap();
|
|
44
|
-
const refreshOncePerRequest = async () => {
|
|
45
|
-
const requestCookies = await cookies();
|
|
46
|
-
let refresh = refreshes.get(requestCookies);
|
|
47
|
-
if (!refresh) {
|
|
48
|
-
refresh = nextCookieStore().then((store) => tryRefreshSessionInStore(store, oauthConfig, storage()));
|
|
49
|
-
refreshes.set(requestCookies, refresh);
|
|
50
|
-
}
|
|
51
|
-
return refresh;
|
|
52
|
-
};
|
|
55
|
+
function createFidesAuth$1(config) {
|
|
56
|
+
const core = createFidesAuth(config);
|
|
57
|
+
const tryReadSession = cache(async () => core.tryReadSession(await nextCookieStore()));
|
|
53
58
|
return {
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
59
|
+
handleOidcLogin: async (request, options) => core.handleOidcLogin(request, await nextCookieStore(), options),
|
|
60
|
+
handleOidcCallback: async (request) => core.handleOidcCallback(request, await nextCookieStore()),
|
|
61
|
+
handleOidcLogout: async (request, options) => core.handleOidcLogout(request, await nextCookieStore(), options),
|
|
62
|
+
handleHeartbeat: async (request) => core.handleHeartbeat(request, await nextCookieStore()),
|
|
63
|
+
handleSessionInfo: async (request) => core.handleSessionInfo(request, await nextCookieStore()),
|
|
64
|
+
readSession: cache(async () => (await tryReadSession()).session),
|
|
65
|
+
tryReadSession,
|
|
66
|
+
getTokens: async () => core.getTokens(await nextCookieStore()),
|
|
67
|
+
refreshSession: async (options) => core.refreshSession(await nextCookieStore(), options),
|
|
68
|
+
createSession: async (tokens) => core.createSession(await nextCookieStore(), tokens),
|
|
69
|
+
updateSession: async (update) => core.updateSession(await nextCookieStore(), update),
|
|
70
|
+
clearSession: async (options) => core.clearSession(await nextCookieStore(), options),
|
|
71
|
+
endUserSessions: (user, options) => core.endUserSessions(user, options),
|
|
72
|
+
authorizedFetch: async (url, options) => core.authorizedFetch(await nextCookieStore(), url, options),
|
|
73
|
+
async refreshInProxy(request, { ifExpiresWithin = 60 } = {}) {
|
|
74
|
+
if (!request.cookies.has(core.cookieNames.session)) return NextResponse.next();
|
|
75
|
+
const { cookies, writes } = proxyCookieStore(request);
|
|
76
|
+
await core.refreshSession(cookies, { ifExpiresWithin });
|
|
77
|
+
return forward(request, writes);
|
|
78
|
+
},
|
|
79
|
+
get cookieNames() {
|
|
80
|
+
return core.cookieNames;
|
|
66
81
|
},
|
|
67
|
-
|
|
68
|
-
...options,
|
|
69
|
-
refresh: options.refresh === false ? void 0 : refreshOncePerRequest
|
|
70
|
-
}),
|
|
71
|
-
handleOidcLogin: (request, options = {}) => handleOidcLogin$1(request, {
|
|
72
|
-
...options,
|
|
73
|
-
oauthConfig,
|
|
74
|
-
secret
|
|
75
|
-
}),
|
|
76
|
-
handleOidcCallback: (request, options) => handleOidcCallback$1(request, {
|
|
77
|
-
...options,
|
|
78
|
-
oauthConfig,
|
|
79
|
-
secret,
|
|
80
|
-
persistence: serverSessions()
|
|
81
|
-
}),
|
|
82
|
-
handleOidcLogout: (request, options) => handleOidcLogout$1(request, {
|
|
83
|
-
...options,
|
|
84
|
-
oauthConfig,
|
|
85
|
-
secret,
|
|
86
|
-
persistence: serverSessions()
|
|
87
|
-
}),
|
|
88
|
-
handleHeartbeat: (request) => handleHeartbeat$1(request, {
|
|
89
|
-
oauthConfig,
|
|
90
|
-
secret,
|
|
91
|
-
persistence: serverSessions()
|
|
92
|
-
})
|
|
82
|
+
oidc: core.oidc
|
|
93
83
|
};
|
|
94
84
|
}
|
|
95
|
-
export {
|
|
85
|
+
export { createFidesAuth$1 as createFidesAuth };
|
|
96
86
|
|
|
97
87
|
//# sourceMappingURL=auth.js.map
|
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.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
|
+
{"version":3,"file":"auth.js","names":["createFidesAuth","createCoreFidesAuth"],"sources":["../src/auth.ts"],"sourcesContent":["/**\n * createFidesAuth for Next.js. The core instance takes a CookieStore on every\n * call; this one gets it from `cookies()` in next/headers, caches session reads\n * per render, and adds refreshInProxy for `proxy.ts`.\n */\n\nimport type { CookieOptions, Session, TokenResponse, Tokens } from '@eventuras/fides-auth';\nimport type { OidcClient } from '@eventuras/fides-auth/oidc';\nimport {\n createFidesAuth as createCoreFidesAuth,\n type CookieStore,\n type FidesAuthConfig,\n type FidesAuthorizedFetchOptions,\n type FidesReadResult,\n type FidesRefreshResult,\n type RefreshSessionOptions,\n} from '@eventuras/fides-auth/server';\nimport type { SessionClearedTrigger } from '@eventuras/fides-auth/session-events';\nimport { type NextRequest, NextResponse } from 'next/server';\nimport { cache } from 'react';\n\nimport { nextCookieStore } from './cookie-store.js';\n\n/** Options for {@link FidesAuth.refreshInProxy}. */\nexport interface RefreshInProxyOptions {\n /**\n * Refresh when the access token expires within this many seconds, or within\n * half its lifetime if that is shorter.\n * @default 60\n */\n ifExpiresWithin?: number;\n}\n\n/** The core instance's members, bound to the request's cookies. */\nexport interface FidesAuth {\n /** `GET`, with an optional `?returnTo=`. Redirects to the provider. */\n handleOidcLogin(\n request: Request,\n options?: { authorizationParameters?: Record<string, string> },\n ): Promise<Response>;\n /** The provider's redirect back. Starts the session and redirects to the return path. */\n handleOidcCallback(request: Request): Promise<Response>;\n /**\n * `POST`. Ends the session, revokes its refresh token where the provider has\n * a revocation endpoint, and redirects to the provider's end-session endpoint.\n */\n handleOidcLogout(\n request: Request,\n options?: { state?: string; logoutHint?: string },\n ): Promise<Response>;\n /** `POST`. Refreshes the session. 401 means it is over; 503 means the provider or the store failed. */\n handleHeartbeat(request: Request): Promise<Response>;\n /** `GET`. Whether there is a session, and whose. Never refreshes, never returns tokens. */\n handleSessionInfo(request: Request): Promise<Response>;\n\n /** The session, or null. Cached per render. */\n readSession(): Promise<Session | null>;\n /** The session, or why there is none. Cached per render, together with `readSession`. */\n tryReadSession(): Promise<FidesReadResult>;\n /** The session's tokens, or null without a session. The access token may have expired. */\n getTokens(): Promise<Tokens | null>;\n /**\n * Refreshes the tokens, or with `ifExpiresWithin` only when the access token\n * is about to expire. With cookie sessions this writes cookies, so it works\n * only in Server Actions and Route Handlers; pages get theirs from\n * `refreshInProxy`.\n */\n refreshSession(options?: RefreshSessionOptions): Promise<FidesRefreshResult>;\n /** Starts a session from a token response, for a login that doesn't go through the handlers. */\n createSession(tokens: TokenResponse): Promise<Session>;\n /** Changes the user or data. Null when there is no session. */\n updateSession(update: (session: Session) => Session | Promise<Session>): Promise<Session | null>;\n /**\n * Ends the session and revokes its refresh token where the provider has a\n * revocation endpoint. With a store, the record is deleted too. `trigger`\n * defaults to `'logout'`.\n */\n clearSession(options?: { trigger?: SessionClearedTrigger }): Promise<void>;\n /**\n * Ends every session of one user, wherever they are signed in, and revokes\n * their refresh tokens. `sub` is the provider's, from the ID token. Needs a\n * `sessionStore` with `findMatching`.\n *\n * @returns How many sessions it ended.\n */\n endUserSessions(\n user: { sub: string; iss?: string },\n options?: { trigger?: SessionClearedTrigger },\n ): Promise<number>;\n /**\n * Calls an API with the session's access token. It never refreshes, so it is\n * safe in a Server Component; a 401 is an `http_error`.\n */\n authorizedFetch<T = undefined>(\n url: string | URL,\n options: FidesAuthorizedFetchOptions<T>,\n ): Promise<{ response: Response; data: T }>;\n /**\n * For `proxy.ts`. Refreshes a session whose access token expires within\n * `ifExpiresWithin` seconds, or within half its lifetime if that is shorter,\n * before the page renders, since a Server Component can't save a refresh.\n * Sets the new cookies on the response and on the request it forwards, so\n * the page reads the refreshed session.\n *\n * A failed refresh leaves the session as it is. The next API call or\n * heartbeat shows a session that is over; ending it here could undo a refresh\n * that another instance completed with the same refresh token.\n */\n refreshInProxy(request: NextRequest, options?: RefreshInProxyOptions): Promise<NextResponse>;\n\n /** The session cookie's name, for a proxy that checks whether one is present. */\n readonly cookieNames: { session: string };\n /** The instance's OIDC client, for protocol calls it doesn't wrap. */\n readonly oidc: OidcClient;\n}\n\n/** A cookie written while the proxy handled a request. `maxAge: 0` deletes it. */\ninterface CookieWrite {\n value: string;\n options?: CookieOptions;\n}\n\n/**\n * A CookieStore over the proxied request's cookies, which records the writes\n * so they can go both to the browser and to the forwarded request.\n */\nfunction proxyCookieStore(request: NextRequest): {\n cookies: CookieStore;\n writes: Map<string, CookieWrite>;\n} {\n const writes = new Map<string, CookieWrite>();\n const cookies: CookieStore = {\n // A cookie written earlier in this request reads back, as it would in the browser.\n get: (name) => {\n const written = writes.get(name);\n if (written) return written.options?.maxAge === 0 ? null : written.value;\n return request.cookies.get(name)?.value ?? null;\n },\n set: (name, value, options) => {\n writes.set(name, { value, options });\n },\n };\n return { cookies, writes };\n}\n\n/** Continues the request, carrying the cookie writes to the page and to the browser. */\nfunction forward(request: NextRequest, writes: Map<string, CookieWrite>): NextResponse {\n if (writes.size === 0) return NextResponse.next();\n\n for (const [name, { value, options }] of writes) {\n if (options?.maxAge === 0) request.cookies.delete(name);\n else request.cookies.set(name, value);\n }\n const response = NextResponse.next({ request: { headers: request.headers } });\n // A delete is a set with `maxAge: 0`, so the browser gets it with the cookie's own attributes.\n for (const [name, { value, options }] of writes) response.cookies.set(name, value, options);\n return response;\n}\n\n/**\n * Creates the app's auth instance. Call it once, in a module of its own, and\n * import the result. It reads nothing from the environment: pass the secret and\n * the provider config in.\n *\n * @example\n * ```ts\n * // lib/auth.ts\n * export const auth = createFidesAuth({ oauthConfig, secret: process.env.SESSION_SECRET! });\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.readSession();\n * ```\n */\nexport function createFidesAuth(config: FidesAuthConfig): FidesAuth {\n const core = createCoreFidesAuth(config);\n\n const tryReadSession = cache(\n async (): Promise<FidesReadResult> => core.tryReadSession(await nextCookieStore()),\n );\n\n return {\n handleOidcLogin: async (request, options) =>\n core.handleOidcLogin(request, await nextCookieStore(), options),\n handleOidcCallback: async (request) => core.handleOidcCallback(request, await nextCookieStore()),\n handleOidcLogout: async (request, options) =>\n core.handleOidcLogout(request, await nextCookieStore(), options),\n handleHeartbeat: async (request) => core.handleHeartbeat(request, await nextCookieStore()),\n handleSessionInfo: async (request) => core.handleSessionInfo(request, await nextCookieStore()),\n\n readSession: cache(async () => (await tryReadSession()).session),\n tryReadSession,\n getTokens: async () => core.getTokens(await nextCookieStore()),\n refreshSession: async (options) => core.refreshSession(await nextCookieStore(), options),\n createSession: async (tokens) => core.createSession(await nextCookieStore(), tokens),\n updateSession: async (update) => core.updateSession(await nextCookieStore(), update),\n clearSession: async (options) => core.clearSession(await nextCookieStore(), options),\n endUserSessions: (user, options) => core.endUserSessions(user, options),\n authorizedFetch: async (url, options) =>\n core.authorizedFetch(await nextCookieStore(), url, options),\n\n async refreshInProxy(request, { ifExpiresWithin = 60 } = {}) {\n // Without a session cookie there is nothing to refresh, and nothing to decrypt.\n if (!request.cookies.has(core.cookieNames.session)) return NextResponse.next();\n\n const { cookies, writes } = proxyCookieStore(request);\n await core.refreshSession(cookies, { ifExpiresWithin });\n return forward(request, writes);\n },\n\n get cookieNames() {\n return core.cookieNames;\n },\n oidc: core.oidc,\n };\n}\n"],"mappings":";;;;;;;;;AA8HA,SAAS,iBAAiB,SAGxB;CACA,MAAM,yBAAS,IAAI,IAAyB;CAY5C,OAAO;EAAE,SAAA;GATP,MAAM,SAAS;IACb,MAAM,UAAU,OAAO,IAAI,IAAI;IAC/B,IAAI,SAAS,OAAO,QAAQ,SAAS,WAAW,IAAI,OAAO,QAAQ;IACnE,OAAO,QAAQ,QAAQ,IAAI,IAAI,CAAC,EAAE,SAAS;GAC7C;GACA,MAAM,MAAM,OAAO,YAAY;IAC7B,OAAO,IAAI,MAAM;KAAE;KAAO;IAAQ,CAAC;GACrC;EAEO;EAAS;CAAO;AAC3B;;AAGA,SAAS,QAAQ,SAAsB,QAAgD;CACrF,IAAI,OAAO,SAAS,GAAG,OAAO,aAAa,KAAK;CAEhD,KAAK,MAAM,CAAC,MAAM,EAAE,OAAO,cAAc,QACvC,IAAI,SAAS,WAAW,GAAG,QAAQ,QAAQ,OAAO,IAAI;MACjD,QAAQ,QAAQ,IAAI,MAAM,KAAK;CAEtC,MAAM,WAAW,aAAa,KAAK,EAAE,SAAS,EAAE,SAAS,QAAQ,QAAQ,EAAE,CAAC;CAE5E,KAAK,MAAM,CAAC,MAAM,EAAE,OAAO,cAAc,QAAQ,SAAS,QAAQ,IAAI,MAAM,OAAO,OAAO;CAC1F,OAAO;AACT;;;;;;;;;;;;;;;;;;AAmBA,SAAgBA,kBAAgB,QAAoC;CAClE,MAAM,OAAOC,gBAAoB,MAAM;CAEvC,MAAM,iBAAiB,MACrB,YAAsC,KAAK,eAAe,MAAM,gBAAgB,CAAC,CACnF;CAEA,OAAO;EACL,iBAAiB,OAAO,SAAS,YAC/B,KAAK,gBAAgB,SAAS,MAAM,gBAAgB,GAAG,OAAO;EAChE,oBAAoB,OAAO,YAAY,KAAK,mBAAmB,SAAS,MAAM,gBAAgB,CAAC;EAC/F,kBAAkB,OAAO,SAAS,YAChC,KAAK,iBAAiB,SAAS,MAAM,gBAAgB,GAAG,OAAO;EACjE,iBAAiB,OAAO,YAAY,KAAK,gBAAgB,SAAS,MAAM,gBAAgB,CAAC;EACzF,mBAAmB,OAAO,YAAY,KAAK,kBAAkB,SAAS,MAAM,gBAAgB,CAAC;EAE7F,aAAa,MAAM,aAAa,MAAM,eAAe,EAAA,CAAG,OAAO;EAC/D;EACA,WAAW,YAAY,KAAK,UAAU,MAAM,gBAAgB,CAAC;EAC7D,gBAAgB,OAAO,YAAY,KAAK,eAAe,MAAM,gBAAgB,GAAG,OAAO;EACvF,eAAe,OAAO,WAAW,KAAK,cAAc,MAAM,gBAAgB,GAAG,MAAM;EACnF,eAAe,OAAO,WAAW,KAAK,cAAc,MAAM,gBAAgB,GAAG,MAAM;EACnF,cAAc,OAAO,YAAY,KAAK,aAAa,MAAM,gBAAgB,GAAG,OAAO;EACnF,kBAAkB,MAAM,YAAY,KAAK,gBAAgB,MAAM,OAAO;EACtE,iBAAiB,OAAO,KAAK,YAC3B,KAAK,gBAAgB,MAAM,gBAAgB,GAAG,KAAK,OAAO;EAE5D,MAAM,eAAe,SAAS,EAAE,kBAAkB,OAAO,CAAC,GAAG;GAE3D,IAAI,CAAC,QAAQ,QAAQ,IAAI,KAAK,YAAY,OAAO,GAAG,OAAO,aAAa,KAAK;GAE7E,MAAM,EAAE,SAAS,WAAW,iBAAiB,OAAO;GACpD,MAAM,KAAK,eAAe,SAAS,EAAE,gBAAgB,CAAC;GACtD,OAAO,QAAQ,SAAS,MAAM;EAChC;EAEA,IAAI,cAAc;GAChB,OAAO,KAAK;EACd;EACA,MAAM,KAAK;CACb;AACF"}
|
package/dist/cookie-store.d.ts
CHANGED
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
import type { CookieStore } from '@eventuras/fides-auth/server';
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
* Must be called where `next/headers` `cookies()` is available: Server Actions,
|
|
7
|
-
* Route Handlers, or Server Components.
|
|
3
|
+
* A {@link CookieStore} over Next's `cookies()`, for the core instance from
|
|
4
|
+
* `@eventuras/fides-auth/server`. It works wherever `cookies()` does. A Server
|
|
5
|
+
* Component can read cookies but not set them, and Next throws on a write there.
|
|
8
6
|
*/
|
|
9
7
|
export declare function nextCookieStore(): Promise<CookieStore>;
|
|
10
8
|
//# sourceMappingURL=cookie-store.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cookie-store.d.ts","sourceRoot":"","sources":["../src/cookie-store.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,8BAA8B,CAAC;AAGhE
|
|
1
|
+
{"version":3,"file":"cookie-store.d.ts","sourceRoot":"","sources":["../src/cookie-store.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,8BAA8B,CAAC;AAGhE;;;;GAIG;AACH,wBAAsB,eAAe,IAAI,OAAO,CAAC,WAAW,CAAC,CAS5D"}
|
package/dist/cookie-store.js
CHANGED
|
@@ -1,11 +1,9 @@
|
|
|
1
1
|
import { cookies } from "next/headers";
|
|
2
2
|
// src/cookie-store.ts
|
|
3
3
|
/**
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
* Must be called where `next/headers` `cookies()` is available: Server Actions,
|
|
8
|
-
* Route Handlers, or Server Components.
|
|
4
|
+
* A {@link CookieStore} over Next's `cookies()`, for the core instance from
|
|
5
|
+
* `@eventuras/fides-auth/server`. It works wherever `cookies()` does. A Server
|
|
6
|
+
* Component can read cookies but not set them, and Next throws on a write there.
|
|
9
7
|
*/
|
|
10
8
|
async function nextCookieStore() {
|
|
11
9
|
const store = await cookies();
|
|
@@ -13,9 +11,6 @@ async function nextCookieStore() {
|
|
|
13
11
|
get: (name) => store.get(name)?.value ?? null,
|
|
14
12
|
set: (name, value, options) => {
|
|
15
13
|
store.set(name, value, options);
|
|
16
|
-
},
|
|
17
|
-
delete: (name) => {
|
|
18
|
-
store.delete(name);
|
|
19
14
|
}
|
|
20
15
|
};
|
|
21
16
|
}
|
package/dist/cookie-store.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cookie-store.js","names":[],"sources":["../src/cookie-store.ts"],"sourcesContent":["import type { CookieStore } from '@eventuras/fides-auth/server';\nimport { cookies } from 'next/headers';\n\n/**\n *
|
|
1
|
+
{"version":3,"file":"cookie-store.js","names":[],"sources":["../src/cookie-store.ts"],"sourcesContent":["import type { CookieStore } from '@eventuras/fides-auth/server';\nimport { cookies } from 'next/headers';\n\n/**\n * A {@link CookieStore} over Next's `cookies()`, for the core instance from\n * `@eventuras/fides-auth/server`. It works wherever `cookies()` does. A Server\n * Component can read cookies but not set them, and Next throws on a write there.\n */\nexport async function nextCookieStore(): Promise<CookieStore> {\n const store = await cookies();\n const cookieStore: CookieStore = {\n get: (name) => store.get(name)?.value ?? null,\n set: (name, value, options) => {\n store.set(name, value, options);\n },\n };\n return cookieStore;\n}\n"],"mappings":";;;;;;;AAQA,eAAsB,kBAAwC;CAC5D,MAAM,QAAQ,MAAM,QAAQ;CAO5B,OAAO;EALL,MAAM,SAAS,MAAM,IAAI,IAAI,CAAC,EAAE,SAAS;EACzC,MAAM,MAAM,OAAO,YAAY;GAC7B,MAAM,IAAI,MAAM,OAAO,OAAO;EAChC;CAEK;AACT"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,22 +1,5 @@
|
|
|
1
|
-
export
|
|
2
|
-
export
|
|
3
|
-
export
|
|
4
|
-
export
|
|
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
|
-
export * from '@eventuras/fides-auth/oauth';
|
|
11
|
-
export type { OAuthConfig } from '@eventuras/fides-auth/oauth';
|
|
12
|
-
export * from '@eventuras/fides-auth/logger';
|
|
13
|
-
export * from '@eventuras/fides-auth/session-events';
|
|
14
|
-
export * from '@eventuras/fides-auth/session-refresh';
|
|
15
|
-
export * from '@eventuras/fides-auth/session-validation';
|
|
16
|
-
export * from '@eventuras/fides-auth/silent-login';
|
|
17
|
-
export * from '@eventuras/fides-auth/utils';
|
|
18
|
-
export * from '@eventuras/fides-auth/types';
|
|
19
|
-
export {
|
|
20
|
-
/** @deprecated Only backs the deprecated default limiter. Use the handlers' `rateLimit` option. */
|
|
21
|
-
TokenBucket, } from '@eventuras/fides-auth/rate-limit';
|
|
1
|
+
export { createFidesAuth, type FidesAuth, type RefreshInProxyOptions, } from './auth.js';
|
|
2
|
+
export { nextCookieStore } from './cookie-store.js';
|
|
3
|
+
export type { Session, SessionInfo, TokenResponse, Tokens } from '@eventuras/fides-auth';
|
|
4
|
+
export type { CookieStore, FidesAuthConfig, FidesAuthorizedFetchOptions, FidesReadResult, FidesRefreshResult, MapSession, RefreshSessionOptions, SessionMatch, SessionStore, StoredSession, StoredSessionEntry, StoreFields, StoreSetContext, } from '@eventuras/fides-auth/server';
|
|
22
5
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,eAAe,EACf,KAAK,SAAS,EACd,KAAK,qBAAqB,GAC3B,MAAM,WAAW,CAAC;AACnB,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAGpD,YAAY,EAAE,OAAO,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AACzF,YAAY,EACV,WAAW,EACX,eAAe,EACf,2BAA2B,EAC3B,eAAe,EACf,kBAAkB,EAClB,UAAU,EACV,qBAAqB,EACrB,YAAY,EACZ,YAAY,EACZ,aAAa,EACb,kBAAkB,EAClB,WAAW,EACX,eAAe,GAChB,MAAM,8BAA8B,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,19 +1,3 @@
|
|
|
1
1
|
import { nextCookieStore } from "./cookie-store.js";
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
import { handleOidcCallback } from "./oidc-callback.js";
|
|
5
|
-
import { handleOidcLogin } from "./oidc-login.js";
|
|
6
|
-
import { handleOidcLogout } from "./oidc-logout.js";
|
|
7
|
-
import { AuthorizedFetchError, createFidesAuth } from "./auth.js";
|
|
8
|
-
import { ACCESS_TOKEN_COOKIE_NAME, COOKIE_INFO_BYTES, COOKIE_MAX_BYTES, CookieTooLargeError, ID_TOKEN_COOKIE_NAME, assertCookieWithinLimit, cookieByteSize, defaultOAuthCookieOptions, defaultSessionCookieOptions, deleteAccessTokenCookie, deleteAuthCookie, deleteAuthCookies, deleteSessionCookie, getAccessTokenCookie, getAuthCookie, getSessionCookie, setAccessTokenCookie, setAuthCookie, setSessionCookie } from "./cookies.js";
|
|
9
|
-
import { checkAuth, configureAuthLogger, createAuthStore, createAuthStoreHooks, initializeAuth, startSessionMonitor, useHeartbeat, useSessionMonitor } from "./store/index.js";
|
|
10
|
-
import { TokenBucket } from "@eventuras/fides-auth/rate-limit";
|
|
11
|
-
export * from "@eventuras/fides-auth/logger";
|
|
12
|
-
export * from "@eventuras/fides-auth/oauth";
|
|
13
|
-
export * from "@eventuras/fides-auth/session-events";
|
|
14
|
-
export * from "@eventuras/fides-auth/session-refresh";
|
|
15
|
-
export * from "@eventuras/fides-auth/session-validation";
|
|
16
|
-
export * from "@eventuras/fides-auth/silent-login";
|
|
17
|
-
export * from "@eventuras/fides-auth/utils";
|
|
18
|
-
export * from "@eventuras/fides-auth/types";
|
|
19
|
-
export { ACCESS_TOKEN_COOKIE_NAME, AuthorizedFetchError, COOKIE_INFO_BYTES, COOKIE_MAX_BYTES, CookieTooLargeError, ID_TOKEN_COOKIE_NAME, TokenBucket, assertCookieWithinLimit, checkAuth, configureAuthLogger, cookieByteSize, createAuthStore, createAuthStoreHooks, createFidesAuth, defaultOAuthCookieOptions, defaultSessionCookieOptions, deleteAccessTokenCookie, deleteAuthCookie, deleteAuthCookies, deleteSessionCookie, getAccessTokenCookie, getAuthCookie, getSessionCookie, globalGETRateLimit, globalPOSTRateLimit, handleHeartbeat, handleOidcCallback, handleOidcLogin, handleOidcLogout, initializeAuth, nextCookieStore, setAccessTokenCookie, setAuthCookie, setSessionCookie, startSessionMonitor, useHeartbeat, useSessionMonitor };
|
|
2
|
+
import { createFidesAuth } from "./auth.js";
|
|
3
|
+
export { createFidesAuth, nextCookieStore };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@eventuras/fides-auth-next",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "1.0.0-beta.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": {
|
|
@@ -17,38 +17,6 @@
|
|
|
17
17
|
".": {
|
|
18
18
|
"types": "./dist/index.d.ts",
|
|
19
19
|
"import": "./dist/index.js"
|
|
20
|
-
},
|
|
21
|
-
"./auth": {
|
|
22
|
-
"types": "./dist/auth.d.ts",
|
|
23
|
-
"import": "./dist/auth.js"
|
|
24
|
-
},
|
|
25
|
-
"./cookie-store": {
|
|
26
|
-
"types": "./dist/cookie-store.d.ts",
|
|
27
|
-
"import": "./dist/cookie-store.js"
|
|
28
|
-
},
|
|
29
|
-
"./request": {
|
|
30
|
-
"types": "./dist/request.d.ts",
|
|
31
|
-
"import": "./dist/request.js"
|
|
32
|
-
},
|
|
33
|
-
"./store": {
|
|
34
|
-
"types": "./dist/store/index.d.ts",
|
|
35
|
-
"import": "./dist/store/index.js"
|
|
36
|
-
},
|
|
37
|
-
"./oidc-callback": {
|
|
38
|
-
"types": "./dist/oidc-callback.d.ts",
|
|
39
|
-
"import": "./dist/oidc-callback.js"
|
|
40
|
-
},
|
|
41
|
-
"./oidc-login": {
|
|
42
|
-
"types": "./dist/oidc-login.d.ts",
|
|
43
|
-
"import": "./dist/oidc-login.js"
|
|
44
|
-
},
|
|
45
|
-
"./oidc-logout": {
|
|
46
|
-
"types": "./dist/oidc-logout.d.ts",
|
|
47
|
-
"import": "./dist/oidc-logout.js"
|
|
48
|
-
},
|
|
49
|
-
"./heartbeat-handler": {
|
|
50
|
-
"types": "./dist/heartbeat-handler.d.ts",
|
|
51
|
-
"import": "./dist/heartbeat-handler.js"
|
|
52
20
|
}
|
|
53
21
|
},
|
|
54
22
|
"main": "./dist/index.js",
|
|
@@ -57,25 +25,23 @@
|
|
|
57
25
|
"dist",
|
|
58
26
|
"LICENSE"
|
|
59
27
|
],
|
|
60
|
-
"dependencies": {
|
|
61
|
-
"@eventuras/fides-auth-react": "0.1.9",
|
|
62
|
-
"@eventuras/fides-auth": "0.16.0",
|
|
63
|
-
"@eventuras/fides-auth-store": "0.3.1"
|
|
64
|
-
},
|
|
65
28
|
"devDependencies": {
|
|
66
|
-
"@testing-library/jest-dom": "7.0.1",
|
|
67
29
|
"@types/react": "^19.3.0",
|
|
68
|
-
"jsdom": "30.1.3",
|
|
69
30
|
"react": "^19.3.1",
|
|
70
31
|
"typescript": "^7.0.2",
|
|
71
32
|
"vite": "^8.3.5",
|
|
72
33
|
"vitest": "^4.1.10",
|
|
73
|
-
"@eventuras/
|
|
74
|
-
"@eventuras/typescript-config": "1.0.0"
|
|
34
|
+
"@eventuras/fides-auth": "1.0.0-beta.1",
|
|
35
|
+
"@eventuras/typescript-config": "1.0.0",
|
|
36
|
+
"@eventuras/vite-config": "0.3.0"
|
|
75
37
|
},
|
|
76
38
|
"peerDependencies": {
|
|
77
39
|
"next": "^16.0.0",
|
|
78
|
-
"react": "^19.0.0"
|
|
40
|
+
"react": "^19.0.0",
|
|
41
|
+
"@eventuras/fides-auth": "^1.0.0-beta.1"
|
|
42
|
+
},
|
|
43
|
+
"engines": {
|
|
44
|
+
"node": ">=22"
|
|
79
45
|
},
|
|
80
46
|
"scripts": {
|
|
81
47
|
"build": "vite build && tsc --emitDeclarationOnly",
|
package/dist/cookies.d.ts
DELETED
|
@@ -1,132 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Cookie helpers for Next.js authentication flows.
|
|
3
|
-
*
|
|
4
|
-
* IMPORTANT: These functions can ONLY be used in:
|
|
5
|
-
* - Server Actions (functions marked with 'use server')
|
|
6
|
-
* - Route Handlers (files in app/api directory)
|
|
7
|
-
* - Server Components (async React components)
|
|
8
|
-
*
|
|
9
|
-
* They CANNOT be used in:
|
|
10
|
-
* - Client Components (marked with 'use client')
|
|
11
|
-
* - Middleware (use NextResponse.cookies instead)
|
|
12
|
-
* - Edge Runtime without proper configuration
|
|
13
|
-
*/
|
|
14
|
-
import type { CookieOptions } from '@eventuras/fides-auth/cookies';
|
|
15
|
-
export { COOKIE_INFO_BYTES, COOKIE_MAX_BYTES, CookieTooLargeError, ACCESS_TOKEN_COOKIE_NAME, ID_TOKEN_COOKIE_NAME, defaultSessionCookieOptions, defaultOAuthCookieOptions, cookieByteSize, assertCookieWithinLimit, } from '@eventuras/fides-auth/cookies';
|
|
16
|
-
export type { CookieOptions } from '@eventuras/fides-auth/cookies';
|
|
17
|
-
/**
|
|
18
|
-
* Sets a cookie with the given name and value.
|
|
19
|
-
*
|
|
20
|
-
* @param name - Cookie name
|
|
21
|
-
* @param value - Cookie value
|
|
22
|
-
* @param options - Cookie options (defaults to session cookie options)
|
|
23
|
-
*
|
|
24
|
-
* @example
|
|
25
|
-
* ```ts
|
|
26
|
-
* // In a server action or route handler
|
|
27
|
-
* await setAuthCookie('session', encryptedJwt);
|
|
28
|
-
*
|
|
29
|
-
* // With custom options
|
|
30
|
-
* await setAuthCookie(ACCESS_TOKEN_COOKIE_NAME, encryptedAccessToken, {
|
|
31
|
-
* maxAge: 60 * 60, // 1 hour
|
|
32
|
-
* });
|
|
33
|
-
* ```
|
|
34
|
-
*/
|
|
35
|
-
export declare function setAuthCookie(name: string, value: string, options?: CookieOptions): Promise<void>;
|
|
36
|
-
/**
|
|
37
|
-
* Gets a cookie value by name.
|
|
38
|
-
*
|
|
39
|
-
* @param name - Cookie name
|
|
40
|
-
* @returns Cookie value or null if not found
|
|
41
|
-
*
|
|
42
|
-
* @example
|
|
43
|
-
* ```ts
|
|
44
|
-
* // In a server action or route handler
|
|
45
|
-
* const sessionCookie = await getAuthCookie('session');
|
|
46
|
-
* if (sessionCookie) {
|
|
47
|
-
* // Validate and use session
|
|
48
|
-
* }
|
|
49
|
-
* ```
|
|
50
|
-
*/
|
|
51
|
-
export declare function getAuthCookie(name: string): Promise<string | null>;
|
|
52
|
-
/**
|
|
53
|
-
* Deletes a cookie by name.
|
|
54
|
-
*
|
|
55
|
-
* @param name - Cookie name to delete
|
|
56
|
-
*
|
|
57
|
-
* @example
|
|
58
|
-
* ```ts
|
|
59
|
-
* // In a server action or route handler
|
|
60
|
-
* await deleteAuthCookie('session');
|
|
61
|
-
* ```
|
|
62
|
-
*/
|
|
63
|
-
export declare function deleteAuthCookie(name: string): Promise<void>;
|
|
64
|
-
/**
|
|
65
|
-
* Deletes multiple cookies at once. The login transaction cookie is cleared by
|
|
66
|
-
* `clearTransaction` from `@eventuras/fides-auth/server`.
|
|
67
|
-
*
|
|
68
|
-
* @param names - Array of cookie names to delete
|
|
69
|
-
*
|
|
70
|
-
* @example
|
|
71
|
-
* ```ts
|
|
72
|
-
* await deleteAuthCookies(['session', ACCESS_TOKEN_COOKIE_NAME, ID_TOKEN_COOKIE_NAME]);
|
|
73
|
-
* ```
|
|
74
|
-
*/
|
|
75
|
-
export declare function deleteAuthCookies(names: string[]): Promise<void>;
|
|
76
|
-
/**
|
|
77
|
-
* Sets the session cookie with proper security settings.
|
|
78
|
-
* This is a convenience wrapper around setAuthCookie.
|
|
79
|
-
*
|
|
80
|
-
* @param encryptedJwt - The encrypted JWT session token
|
|
81
|
-
* @param options - Optional cookie options (merged with defaults)
|
|
82
|
-
*
|
|
83
|
-
* @example
|
|
84
|
-
* ```ts
|
|
85
|
-
* const jwt = await createEncryptedJWT(session, secret);
|
|
86
|
-
* await setSessionCookie(jwt);
|
|
87
|
-
* ```
|
|
88
|
-
*/
|
|
89
|
-
export declare function setSessionCookie(encryptedJwt: string, options?: Partial<CookieOptions>): Promise<void>;
|
|
90
|
-
/**
|
|
91
|
-
* Sets the access-token cookie ("session_at") with session cookie settings.
|
|
92
|
-
*
|
|
93
|
-
* @param encryptedJwt - The encrypted JWT wrapping the access token
|
|
94
|
-
* @param options - Optional cookie options (merged with session defaults)
|
|
95
|
-
*/
|
|
96
|
-
export declare function setAccessTokenCookie(encryptedJwt: string, options?: Partial<CookieOptions>): Promise<void>;
|
|
97
|
-
/**
|
|
98
|
-
* Gets the access-token cookie ("session_at") value, or null if absent.
|
|
99
|
-
*/
|
|
100
|
-
export declare function getAccessTokenCookie(): Promise<string | null>;
|
|
101
|
-
/**
|
|
102
|
-
* Deletes the access-token cookie ("session_at").
|
|
103
|
-
*/
|
|
104
|
-
export declare function deleteAccessTokenCookie(): Promise<void>;
|
|
105
|
-
/**
|
|
106
|
-
* Gets the current session cookie value.
|
|
107
|
-
* Returns null if no session cookie exists.
|
|
108
|
-
*
|
|
109
|
-
* @returns Encrypted JWT session token or null
|
|
110
|
-
*
|
|
111
|
-
* @example
|
|
112
|
-
* ```ts
|
|
113
|
-
* const sessionToken = await getSessionCookie();
|
|
114
|
-
* if (sessionToken) {
|
|
115
|
-
* const { status, session } = await validateSessionJwt(sessionToken, secret);
|
|
116
|
-
* // ...
|
|
117
|
-
* }
|
|
118
|
-
* ```
|
|
119
|
-
*/
|
|
120
|
-
export declare function getSessionCookie(): Promise<string | null>;
|
|
121
|
-
/**
|
|
122
|
-
* Deletes the session cookie.
|
|
123
|
-
* Use this when logging out or when session validation fails.
|
|
124
|
-
*
|
|
125
|
-
* @example
|
|
126
|
-
* ```ts
|
|
127
|
-
* await deleteSessionCookie();
|
|
128
|
-
* redirect('/');
|
|
129
|
-
* ```
|
|
130
|
-
*/
|
|
131
|
-
export declare function deleteSessionCookie(): Promise<void>;
|
|
132
|
-
//# sourceMappingURL=cookies.d.ts.map
|
package/dist/cookies.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"cookies.d.ts","sourceRoot":"","sources":["../src/cookies.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAQH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,+BAA+B,CAAC;AAQnE,OAAO,EACL,iBAAiB,EACjB,gBAAgB,EAChB,mBAAmB,EACnB,wBAAwB,EACxB,oBAAoB,EACpB,2BAA2B,EAC3B,yBAAyB,EACzB,cAAc,EACd,uBAAuB,GACxB,MAAM,+BAA+B,CAAC;AACvC,YAAY,EAAE,aAAa,EAAE,MAAM,+BAA+B,CAAC;AAInE;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAsB,aAAa,CACjC,IAAI,EAAE,MAAM,EACZ,KAAK,EAAE,MAAM,EACb,OAAO,GAAE,aAA2C,GACnD,OAAO,CAAC,IAAI,CAAC,CAuBf;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAsB,aAAa,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAgBxE;AAED;;;;;;;;;;GAUG;AACH,wBAAsB,gBAAgB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAUlE;AAED;;;;;;;;;;GAUG;AACH,wBAAsB,iBAAiB,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAatE;AAED;;;;;;;;;;;;GAYG;AACH,wBAAsB,gBAAgB,CACpC,YAAY,EAAE,MAAM,EACpB,OAAO,GAAE,OAAO,CAAC,aAAa,CAAM,GACnC,OAAO,CAAC,IAAI,CAAC,CAOf;AAED;;;;;GAKG;AACH,wBAAsB,oBAAoB,CACxC,YAAY,EAAE,MAAM,EACpB,OAAO,GAAE,OAAO,CAAC,aAAa,CAAM,GACnC,OAAO,CAAC,IAAI,CAAC,CAKf;AAED;;GAEG;AACH,wBAAsB,oBAAoB,IAAI,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAEnE;AAED;;GAEG;AACH,wBAAsB,uBAAuB,IAAI,OAAO,CAAC,IAAI,CAAC,CAE7D;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAsB,gBAAgB,IAAI,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAE/D;AAED;;;;;;;;;GASG;AACH,wBAAsB,mBAAmB,IAAI,OAAO,CAAC,IAAI,CAAC,CAGzD"}
|