@eventuras/fides-auth-next 0.7.2 → 0.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +122 -20
- package/dist/auth.d.ts +76 -0
- package/dist/auth.d.ts.map +1 -0
- package/dist/auth.js +97 -0
- package/dist/auth.js.map +1 -0
- package/dist/cookie-store.js +1 -2
- package/dist/cookies.d.ts +7 -8
- package/dist/cookies.d.ts.map +1 -1
- package/dist/cookies.js +8 -10
- package/dist/cookies.js.map +1 -1
- package/dist/heartbeat-handler.d.ts +8 -2
- package/dist/heartbeat-handler.d.ts.map +1 -1
- package/dist/heartbeat-handler.js +6 -4
- package/dist/heartbeat-handler.js.map +1 -1
- package/dist/index.d.ts +4 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -5
- package/dist/oidc-callback.d.ts +11 -2
- package/dist/oidc-callback.d.ts.map +1 -1
- package/dist/oidc-callback.js +7 -3
- package/dist/oidc-callback.js.map +1 -1
- package/dist/oidc-login.d.ts +8 -2
- package/dist/oidc-login.d.ts.map +1 -1
- package/dist/oidc-login.js +6 -4
- package/dist/oidc-login.js.map +1 -1
- package/dist/oidc-logout.d.ts +7 -0
- package/dist/oidc-logout.d.ts.map +1 -1
- package/dist/oidc-logout.js +5 -2
- package/dist/oidc-logout.js.map +1 -1
- package/dist/request.d.ts +8 -0
- package/dist/request.d.ts.map +1 -1
- package/dist/request.js +9 -2
- package/dist/request.js.map +1 -1
- package/package.json +13 -13
- package/dist/session.d.ts +0 -120
- package/dist/session.d.ts.map +0 -1
- package/dist/session.js +0 -152
- package/dist/session.js.map +0 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export * from './cookie-store';
|
|
2
2
|
export * from './request';
|
|
3
|
-
export * from './
|
|
3
|
+
export * from './auth';
|
|
4
4
|
export * from './cookies';
|
|
5
5
|
export * from './oidc-callback';
|
|
6
6
|
export * from './oidc-login';
|
|
@@ -16,5 +16,7 @@ export * from '@eventuras/fides-auth/session-validation';
|
|
|
16
16
|
export * from '@eventuras/fides-auth/silent-login';
|
|
17
17
|
export * from '@eventuras/fides-auth/utils';
|
|
18
18
|
export * from '@eventuras/fides-auth/types';
|
|
19
|
-
export {
|
|
19
|
+
export {
|
|
20
|
+
/** @deprecated Only backs the deprecated default limiter. Use the handlers' `rateLimit` option. */
|
|
21
|
+
TokenBucket, } from '@eventuras/fides-auth/rate-limit';
|
|
20
22
|
//# 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":"AACA,cAAc,gBAAgB,CAAC;AAC/B,cAAc,WAAW,CAAC;AAC1B,cAAc,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,cAAc,gBAAgB,CAAC;AAC/B,cAAc,WAAW,CAAC;AAC1B,cAAc,QAAQ,CAAC;AACvB,cAAc,WAAW,CAAC;AAC1B,cAAc,iBAAiB,CAAC;AAChC,cAAc,cAAc,CAAC;AAC7B,cAAc,eAAe,CAAC;AAC9B,cAAc,qBAAqB,CAAC;AAGpC,cAAc,SAAS,CAAC;AAGxB,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"}
|
package/dist/index.js
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
import { nextCookieStore } from "./cookie-store.js";
|
|
2
2
|
import { globalGETRateLimit, globalPOSTRateLimit } from "./request.js";
|
|
3
|
-
import {
|
|
4
|
-
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";
|
|
3
|
+
import { handleHeartbeat } from "./heartbeat-handler.js";
|
|
5
4
|
import { handleOidcCallback } from "./oidc-callback.js";
|
|
6
5
|
import { handleOidcLogin } from "./oidc-login.js";
|
|
7
6
|
import { handleOidcLogout } from "./oidc-logout.js";
|
|
8
|
-
import {
|
|
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
9
|
import { checkAuth, configureAuthLogger, createAuthStore, createAuthStoreHooks, initializeAuth, startSessionMonitor, useHeartbeat, useSessionMonitor } from "./store/index.js";
|
|
10
10
|
import { TokenBucket } from "@eventuras/fides-auth/rate-limit";
|
|
11
11
|
export * from "@eventuras/fides-auth/logger";
|
|
12
|
-
export * from "@eventuras/fides-auth/utils";
|
|
13
12
|
export * from "@eventuras/fides-auth/oauth";
|
|
14
13
|
export * from "@eventuras/fides-auth/session-events";
|
|
15
14
|
export * from "@eventuras/fides-auth/session-refresh";
|
|
16
15
|
export * from "@eventuras/fides-auth/session-validation";
|
|
17
16
|
export * from "@eventuras/fides-auth/silent-login";
|
|
17
|
+
export * from "@eventuras/fides-auth/utils";
|
|
18
18
|
export * from "@eventuras/fides-auth/types";
|
|
19
|
-
export { ACCESS_TOKEN_COOKIE_NAME, COOKIE_INFO_BYTES, COOKIE_MAX_BYTES, CookieTooLargeError, ID_TOKEN_COOKIE_NAME, TokenBucket, assertCookieWithinLimit, checkAuth,
|
|
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 };
|
package/dist/oidc-callback.d.ts
CHANGED
|
@@ -3,10 +3,15 @@
|
|
|
3
3
|
* framework-agnostic handler in `@eventuras/fides-auth/server`, wiring it to the
|
|
4
4
|
* Next cookie store and the global GET rate limiter.
|
|
5
5
|
*/
|
|
6
|
-
import type
|
|
6
|
+
import { type SessionPersistence, type SessionSecret } from '@eventuras/fides-auth/server';
|
|
7
|
+
import type { MapSession, OAuthConfig } from '@eventuras/fides-auth/oauth';
|
|
7
8
|
export interface OidcCallbackConfig {
|
|
8
9
|
/** OAuth/OIDC configuration (issuer, clientId, clientSecret, redirect_uri, scope) */
|
|
9
10
|
oauthConfig: OAuthConfig;
|
|
11
|
+
/** Opens the login transaction and encrypts the session. Must match the login's. */
|
|
12
|
+
secret: SessionSecret;
|
|
13
|
+
/** Where the session lives. Defaults to the cookies under `secret`; see `serverPersistence`. */
|
|
14
|
+
persistence?: SessionPersistence;
|
|
10
15
|
/** Public application URL (used to reconstruct the callback URL and validate redirects) */
|
|
11
16
|
applicationUrl: string;
|
|
12
17
|
/**
|
|
@@ -14,6 +19,8 @@ export interface OidcCallbackConfig {
|
|
|
14
19
|
* @default 'roles'
|
|
15
20
|
*/
|
|
16
21
|
rolesClaim?: string;
|
|
22
|
+
/** Changes the session before it is stored, e.g. to add `data`. See {@link MapSession}. */
|
|
23
|
+
mapSession?: MapSession;
|
|
17
24
|
/**
|
|
18
25
|
* Default path to redirect to after login if no returnTo cookie is set.
|
|
19
26
|
* @default '/'
|
|
@@ -31,7 +38,8 @@ export interface OidcCallbackConfig {
|
|
|
31
38
|
sessionDurationDays?: number;
|
|
32
39
|
}
|
|
33
40
|
/**
|
|
34
|
-
* Handles the OIDC callback in a Next.js route handler.
|
|
41
|
+
* Handles the OIDC callback in a Next.js route handler. `createFidesAuth` returns
|
|
42
|
+
* this with `oauthConfig` and `secret` bound.
|
|
35
43
|
*
|
|
36
44
|
* @example
|
|
37
45
|
* ```ts
|
|
@@ -41,6 +49,7 @@ export interface OidcCallbackConfig {
|
|
|
41
49
|
* export async function GET(request: Request) {
|
|
42
50
|
* return handleOidcCallback(request, {
|
|
43
51
|
* oauthConfig,
|
|
52
|
+
* secret: process.env.SESSION_SECRET!,
|
|
44
53
|
* applicationUrl: 'https://example.com',
|
|
45
54
|
* rolesClaim: 'roles',
|
|
46
55
|
* });
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"oidc-callback.d.ts","sourceRoot":"","sources":["../src/oidc-callback.ts"],"names":[],"mappings":"AAAA;;;;GAIG;
|
|
1
|
+
{"version":3,"file":"oidc-callback.d.ts","sourceRoot":"","sources":["../src/oidc-callback.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAEL,KAAK,kBAAkB,EACvB,KAAK,aAAa,EACnB,MAAM,8BAA8B,CAAC;AACtC,OAAO,KAAK,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAC;AAK3E,MAAM,WAAW,kBAAkB;IACjC,qFAAqF;IACrF,WAAW,EAAE,WAAW,CAAC;IAEzB,oFAAoF;IACpF,MAAM,EAAE,aAAa,CAAC;IAEtB,gGAAgG;IAChG,WAAW,CAAC,EAAE,kBAAkB,CAAC;IAEjC,2FAA2F;IAC3F,cAAc,EAAE,MAAM,CAAC;IAEvB;;;OAGG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;IAEpB,2FAA2F;IAC3F,UAAU,CAAC,EAAE,UAAU,CAAC;IAExB;;;OAGG;IACH,mBAAmB,CAAC,EAAE,MAAM,CAAC;IAE7B;;;OAGG;IACH,gBAAgB,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,OAAO,CAAC;IAE7C;;;OAGG;IACH,mBAAmB,CAAC,EAAE,MAAM,CAAC;CAC9B;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAsB,kBAAkB,CACtC,OAAO,EAAE,OAAO,EAChB,MAAM,EAAE,kBAAkB,GACzB,OAAO,CAAC,QAAQ,CAAC,CAenB"}
|
package/dist/oidc-callback.js
CHANGED
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
import { nextCookieStore } from "./cookie-store.js";
|
|
2
2
|
import { globalGETRateLimit } from "./request.js";
|
|
3
3
|
import { handleOidcCallback as handleOidcCallback$1 } from "@eventuras/fides-auth/server";
|
|
4
|
-
|
|
4
|
+
// src/oidc-callback.ts
|
|
5
5
|
/**
|
|
6
6
|
* OIDC callback handler for Next.js route handlers — a thin wrapper over the
|
|
7
7
|
* framework-agnostic handler in `@eventuras/fides-auth/server`, wiring it to the
|
|
8
8
|
* Next cookie store and the global GET rate limiter.
|
|
9
9
|
*/
|
|
10
10
|
/**
|
|
11
|
-
* Handles the OIDC callback in a Next.js route handler.
|
|
11
|
+
* Handles the OIDC callback in a Next.js route handler. `createFidesAuth` returns
|
|
12
|
+
* this with `oauthConfig` and `secret` bound.
|
|
12
13
|
*
|
|
13
14
|
* @example
|
|
14
15
|
* ```ts
|
|
@@ -18,6 +19,7 @@ import { handleOidcCallback as handleOidcCallback$1 } from "@eventuras/fides-aut
|
|
|
18
19
|
* export async function GET(request: Request) {
|
|
19
20
|
* return handleOidcCallback(request, {
|
|
20
21
|
* oauthConfig,
|
|
22
|
+
* secret: process.env.SESSION_SECRET!,
|
|
21
23
|
* applicationUrl: 'https://example.com',
|
|
22
24
|
* rolesClaim: 'roles',
|
|
23
25
|
* });
|
|
@@ -27,15 +29,17 @@ import { handleOidcCallback as handleOidcCallback$1 } from "@eventuras/fides-aut
|
|
|
27
29
|
async function handleOidcCallback(request, config) {
|
|
28
30
|
return handleOidcCallback$1(request, {
|
|
29
31
|
oauthConfig: config.oauthConfig,
|
|
32
|
+
secret: config.secret,
|
|
33
|
+
persistence: config.persistence,
|
|
30
34
|
applicationUrl: config.applicationUrl,
|
|
31
35
|
rolesClaim: config.rolesClaim,
|
|
36
|
+
mapSession: config.mapSession,
|
|
32
37
|
defaultRedirectPath: config.defaultRedirectPath,
|
|
33
38
|
validateReturnTo: config.validateReturnTo,
|
|
34
39
|
cookies: await nextCookieStore(),
|
|
35
40
|
rateLimit: globalGETRateLimit
|
|
36
41
|
});
|
|
37
42
|
}
|
|
38
|
-
//#endregion
|
|
39
43
|
export { handleOidcCallback };
|
|
40
44
|
|
|
41
45
|
//# sourceMappingURL=oidc-callback.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"oidc-callback.js","names":[],"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 {
|
|
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"}
|
package/dist/oidc-login.d.ts
CHANGED
|
@@ -3,19 +3,25 @@
|
|
|
3
3
|
* framework-agnostic handler in `@eventuras/fides-auth/server`, wiring it to the
|
|
4
4
|
* Next cookie store and the global GET rate limiter.
|
|
5
5
|
*/
|
|
6
|
+
import { type OidcLoginConfig as CoreOidcLoginConfig, type SessionSecret } from '@eventuras/fides-auth/server';
|
|
6
7
|
import type { OAuthConfig } from '@eventuras/fides-auth/oauth';
|
|
7
8
|
export interface OidcLoginConfig {
|
|
8
9
|
/** OAuth/OIDC configuration */
|
|
9
10
|
oauthConfig: OAuthConfig;
|
|
11
|
+
/** Seals the login transaction. Must match the callback's. */
|
|
12
|
+
secret: SessionSecret;
|
|
10
13
|
/**
|
|
11
14
|
* Validates and sanitizes the returnTo parameter.
|
|
12
15
|
* Should return a safe path or null to use the default.
|
|
13
16
|
* @default Only allows relative paths starting with /
|
|
14
17
|
*/
|
|
15
18
|
validateReturnTo?: (rawReturnTo: string) => string | null;
|
|
19
|
+
/** Per-request authorization parameters, e.g. `prompt` or `login_hint`. Reserved keys throw. */
|
|
20
|
+
authorizationParameters?: CoreOidcLoginConfig['authorizationParameters'];
|
|
16
21
|
}
|
|
17
22
|
/**
|
|
18
|
-
* Handles OIDC login initiation in a Next.js route handler.
|
|
23
|
+
* Handles OIDC login initiation in a Next.js route handler. `createFidesAuth`
|
|
24
|
+
* returns this with `oauthConfig` and `secret` bound.
|
|
19
25
|
*
|
|
20
26
|
* @example
|
|
21
27
|
* ```ts
|
|
@@ -23,7 +29,7 @@ export interface OidcLoginConfig {
|
|
|
23
29
|
* import { handleOidcLogin } from '@eventuras/fides-auth-next/oidc-login';
|
|
24
30
|
*
|
|
25
31
|
* export async function GET(request: Request) {
|
|
26
|
-
* return handleOidcLogin(request, { oauthConfig });
|
|
32
|
+
* return handleOidcLogin(request, { oauthConfig, secret: process.env.SESSION_SECRET! });
|
|
27
33
|
* }
|
|
28
34
|
* ```
|
|
29
35
|
*/
|
package/dist/oidc-login.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"oidc-login.d.ts","sourceRoot":"","sources":["../src/oidc-login.ts"],"names":[],"mappings":"AAAA;;;;GAIG;
|
|
1
|
+
{"version":3,"file":"oidc-login.d.ts","sourceRoot":"","sources":["../src/oidc-login.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAEL,KAAK,eAAe,IAAI,mBAAmB,EAC3C,KAAK,aAAa,EACnB,MAAM,8BAA8B,CAAC;AACtC,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAC;AAK/D,MAAM,WAAW,eAAe;IAC9B,+BAA+B;IAC/B,WAAW,EAAE,WAAW,CAAC;IAEzB,8DAA8D;IAC9D,MAAM,EAAE,aAAa,CAAC;IAEtB;;;;OAIG;IACH,gBAAgB,CAAC,EAAE,CAAC,WAAW,EAAE,MAAM,KAAK,MAAM,GAAG,IAAI,CAAC;IAE1D,gGAAgG;IAChG,uBAAuB,CAAC,EAAE,mBAAmB,CAAC,yBAAyB,CAAC,CAAC;CAC1E;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAsB,eAAe,CACnC,OAAO,EAAE,OAAO,EAChB,MAAM,EAAE,eAAe,GACtB,OAAO,CAAC,QAAQ,CAAC,CASnB"}
|
package/dist/oidc-login.js
CHANGED
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
import { nextCookieStore } from "./cookie-store.js";
|
|
2
2
|
import { globalGETRateLimit } from "./request.js";
|
|
3
3
|
import { handleOidcLogin as handleOidcLogin$1 } from "@eventuras/fides-auth/server";
|
|
4
|
-
|
|
4
|
+
// src/oidc-login.ts
|
|
5
5
|
/**
|
|
6
6
|
* OIDC login initiation for Next.js route handlers — a thin wrapper over the
|
|
7
7
|
* framework-agnostic handler in `@eventuras/fides-auth/server`, wiring it to the
|
|
8
8
|
* Next cookie store and the global GET rate limiter.
|
|
9
9
|
*/
|
|
10
10
|
/**
|
|
11
|
-
* Handles OIDC login initiation in a Next.js route handler.
|
|
11
|
+
* Handles OIDC login initiation in a Next.js route handler. `createFidesAuth`
|
|
12
|
+
* returns this with `oauthConfig` and `secret` bound.
|
|
12
13
|
*
|
|
13
14
|
* @example
|
|
14
15
|
* ```ts
|
|
@@ -16,19 +17,20 @@ import { handleOidcLogin as handleOidcLogin$1 } from "@eventuras/fides-auth/serv
|
|
|
16
17
|
* import { handleOidcLogin } from '@eventuras/fides-auth-next/oidc-login';
|
|
17
18
|
*
|
|
18
19
|
* export async function GET(request: Request) {
|
|
19
|
-
* return handleOidcLogin(request, { oauthConfig });
|
|
20
|
+
* return handleOidcLogin(request, { oauthConfig, secret: process.env.SESSION_SECRET! });
|
|
20
21
|
* }
|
|
21
22
|
* ```
|
|
22
23
|
*/
|
|
23
24
|
async function handleOidcLogin(request, config) {
|
|
24
25
|
return handleOidcLogin$1(request, {
|
|
25
26
|
oauthConfig: config.oauthConfig,
|
|
27
|
+
secret: config.secret,
|
|
26
28
|
validateReturnTo: config.validateReturnTo,
|
|
29
|
+
authorizationParameters: config.authorizationParameters,
|
|
27
30
|
cookies: await nextCookieStore(),
|
|
28
31
|
rateLimit: globalGETRateLimit
|
|
29
32
|
});
|
|
30
33
|
}
|
|
31
|
-
//#endregion
|
|
32
34
|
export { handleOidcLogin };
|
|
33
35
|
|
|
34
36
|
//# sourceMappingURL=oidc-login.js.map
|
package/dist/oidc-login.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"oidc-login.js","names":[],"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 {
|
|
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"}
|
package/dist/oidc-logout.d.ts
CHANGED
|
@@ -3,10 +3,15 @@
|
|
|
3
3
|
* framework-agnostic handler in `@eventuras/fides-auth/server`, wiring it to the
|
|
4
4
|
* Next cookie store and the global POST rate limiter.
|
|
5
5
|
*/
|
|
6
|
+
import { type SessionPersistence, type SessionSecret } from '@eventuras/fides-auth/server';
|
|
6
7
|
import type { OAuthConfig } from '@eventuras/fides-auth/oauth';
|
|
7
8
|
export interface OidcLogoutConfig {
|
|
8
9
|
/** OAuth/OIDC configuration */
|
|
9
10
|
oauthConfig: OAuthConfig;
|
|
11
|
+
/** Session encryption secret. */
|
|
12
|
+
secret: SessionSecret;
|
|
13
|
+
/** Where the session lives. Defaults to the cookies under `secret`; see `serverPersistence`. */
|
|
14
|
+
persistence?: SessionPersistence;
|
|
10
15
|
/**
|
|
11
16
|
* URI the provider redirects back to after logout. Must be registered with the
|
|
12
17
|
* provider as a post-logout redirect URI.
|
|
@@ -31,6 +36,7 @@ export interface OidcLogoutConfig {
|
|
|
31
36
|
/**
|
|
32
37
|
* Handles logout in a Next.js route handler: clears the session cookies and
|
|
33
38
|
* redirects to the provider's end-session endpoint with `id_token_hint`.
|
|
39
|
+
* `createFidesAuth` returns this with `oauthConfig` and `secret` bound.
|
|
34
40
|
*
|
|
35
41
|
* @example
|
|
36
42
|
* ```ts
|
|
@@ -40,6 +46,7 @@ export interface OidcLogoutConfig {
|
|
|
40
46
|
* export async function POST(request: Request) {
|
|
41
47
|
* return handleOidcLogout(request, {
|
|
42
48
|
* oauthConfig,
|
|
49
|
+
* secret: process.env.SESSION_SECRET!,
|
|
43
50
|
* postLogoutRedirectUri: 'https://example.com/',
|
|
44
51
|
* });
|
|
45
52
|
* }
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"oidc-logout.d.ts","sourceRoot":"","sources":["../src/oidc-logout.ts"],"names":[],"mappings":"AAAA;;;;GAIG;
|
|
1
|
+
{"version":3,"file":"oidc-logout.d.ts","sourceRoot":"","sources":["../src/oidc-logout.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAEL,KAAK,kBAAkB,EACvB,KAAK,aAAa,EACnB,MAAM,8BAA8B,CAAC;AACtC,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAC;AAK/D,MAAM,WAAW,gBAAgB;IAC/B,+BAA+B;IAC/B,WAAW,EAAE,WAAW,CAAC;IAEzB,iCAAiC;IACjC,MAAM,EAAE,aAAa,CAAC;IAEtB,gGAAgG;IAChG,WAAW,CAAC,EAAE,kBAAkB,CAAC;IAEjC;;;OAGG;IACH,qBAAqB,EAAE,MAAM,CAAC;IAE9B,4DAA4D;IAC5D,KAAK,CAAC,EAAE,MAAM,CAAC;IAEf,sDAAsD;IACtD,UAAU,CAAC,EAAE,MAAM,CAAC;IAEpB,iDAAiD;IACjD,eAAe,CAAC,EAAE,OAAO,CAAC;IAE1B,mEAAmE;IACnE,cAAc,CAAC,EAAE,MAAM,EAAE,CAAC;IAE1B,gFAAgF;IAChF,cAAc,CAAC,EAAE,MAAM,CAAC;IAExB;;;OAGG;IACH,mBAAmB,CAAC,EAAE,MAAM,CAAC;CAC9B;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAsB,gBAAgB,CACpC,OAAO,EAAE,OAAO,EAChB,MAAM,EAAE,gBAAgB,GACvB,OAAO,CAAC,QAAQ,CAAC,CAenB"}
|
package/dist/oidc-logout.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { nextCookieStore } from "./cookie-store.js";
|
|
2
2
|
import { globalPOSTRateLimit } from "./request.js";
|
|
3
3
|
import { handleOidcLogout as handleOidcLogout$1 } from "@eventuras/fides-auth/server";
|
|
4
|
-
|
|
4
|
+
// src/oidc-logout.ts
|
|
5
5
|
/**
|
|
6
6
|
* RP-initiated logout for Next.js route handlers — a thin wrapper over the
|
|
7
7
|
* framework-agnostic handler in `@eventuras/fides-auth/server`, wiring it to the
|
|
@@ -10,6 +10,7 @@ import { handleOidcLogout as handleOidcLogout$1 } from "@eventuras/fides-auth/se
|
|
|
10
10
|
/**
|
|
11
11
|
* Handles logout in a Next.js route handler: clears the session cookies and
|
|
12
12
|
* redirects to the provider's end-session endpoint with `id_token_hint`.
|
|
13
|
+
* `createFidesAuth` returns this with `oauthConfig` and `secret` bound.
|
|
13
14
|
*
|
|
14
15
|
* @example
|
|
15
16
|
* ```ts
|
|
@@ -19,6 +20,7 @@ import { handleOidcLogout as handleOidcLogout$1 } from "@eventuras/fides-auth/se
|
|
|
19
20
|
* export async function POST(request: Request) {
|
|
20
21
|
* return handleOidcLogout(request, {
|
|
21
22
|
* oauthConfig,
|
|
23
|
+
* secret: process.env.SESSION_SECRET!,
|
|
22
24
|
* postLogoutRedirectUri: 'https://example.com/',
|
|
23
25
|
* });
|
|
24
26
|
* }
|
|
@@ -27,6 +29,8 @@ import { handleOidcLogout as handleOidcLogout$1 } from "@eventuras/fides-auth/se
|
|
|
27
29
|
async function handleOidcLogout(request, config) {
|
|
28
30
|
return handleOidcLogout$1(request, {
|
|
29
31
|
oauthConfig: config.oauthConfig,
|
|
32
|
+
secret: config.secret,
|
|
33
|
+
persistence: config.persistence,
|
|
30
34
|
postLogoutRedirectUri: config.postLogoutRedirectUri,
|
|
31
35
|
state: config.state,
|
|
32
36
|
logoutHint: config.logoutHint,
|
|
@@ -38,7 +42,6 @@ async function handleOidcLogout(request, config) {
|
|
|
38
42
|
rateLimit: globalPOSTRateLimit
|
|
39
43
|
});
|
|
40
44
|
}
|
|
41
|
-
//#endregion
|
|
42
45
|
export { handleOidcLogout };
|
|
43
46
|
|
|
44
47
|
//# sourceMappingURL=oidc-logout.js.map
|
package/dist/oidc-logout.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"oidc-logout.js","names":[],"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 {
|
|
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"}
|
package/dist/request.d.ts
CHANGED
|
@@ -1,3 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @deprecated Keys on the raw `X-Forwarded-For` header, and requests without it pass.
|
|
3
|
+
* Pass your own limiter as `rateLimit` to the handlers in `@eventuras/fides-auth/server`.
|
|
4
|
+
*/
|
|
1
5
|
export declare function globalGETRateLimit(): Promise<boolean>;
|
|
6
|
+
/**
|
|
7
|
+
* @deprecated Keys on the raw `X-Forwarded-For` header, and requests without it pass.
|
|
8
|
+
* Pass your own limiter as `rateLimit` to the handlers in `@eventuras/fides-auth/server`.
|
|
9
|
+
*/
|
|
2
10
|
export declare function globalPOSTRateLimit(): Promise<boolean>;
|
|
3
11
|
//# sourceMappingURL=request.d.ts.map
|
package/dist/request.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"request.d.ts","sourceRoot":"","sources":["../src/request.ts"],"names":[],"mappings":"AAgBA,wBAAsB,kBAAkB,IAAI,OAAO,CAAC,OAAO,CAAC,CAiB3D;AAED,wBAAsB,mBAAmB,IAAI,OAAO,CAAC,OAAO,CAAC,CAiB5D"}
|
|
1
|
+
{"version":3,"file":"request.d.ts","sourceRoot":"","sources":["../src/request.ts"],"names":[],"mappings":"AAgBA;;;GAGG;AACH,wBAAsB,kBAAkB,IAAI,OAAO,CAAC,OAAO,CAAC,CAiB3D;AAED;;;GAGG;AACH,wBAAsB,mBAAmB,IAAI,OAAO,CAAC,OAAO,CAAC,CAiB5D"}
|
package/dist/request.js
CHANGED
|
@@ -1,13 +1,17 @@
|
|
|
1
1
|
import { headers } from "next/headers";
|
|
2
2
|
import { TokenBucket } from "@eventuras/fides-auth/rate-limit";
|
|
3
3
|
import { createLogger } from "@eventuras/fides-auth/logger";
|
|
4
|
-
|
|
4
|
+
// src/request.ts
|
|
5
5
|
var logger = createLogger({ namespace: "fides-auth-next:request" });
|
|
6
6
|
var globalBucket = null;
|
|
7
7
|
function getBucket() {
|
|
8
8
|
if (!globalBucket) globalBucket = new TokenBucket(100, 1);
|
|
9
9
|
return globalBucket;
|
|
10
10
|
}
|
|
11
|
+
/**
|
|
12
|
+
* @deprecated Keys on the raw `X-Forwarded-For` header, and requests without it pass.
|
|
13
|
+
* Pass your own limiter as `rateLimit` to the handlers in `@eventuras/fides-auth/server`.
|
|
14
|
+
*/
|
|
11
15
|
async function globalGETRateLimit() {
|
|
12
16
|
try {
|
|
13
17
|
const clientIP = (await headers()).get("X-Forwarded-For");
|
|
@@ -19,6 +23,10 @@ async function globalGETRateLimit() {
|
|
|
19
23
|
return true;
|
|
20
24
|
}
|
|
21
25
|
}
|
|
26
|
+
/**
|
|
27
|
+
* @deprecated Keys on the raw `X-Forwarded-For` header, and requests without it pass.
|
|
28
|
+
* Pass your own limiter as `rateLimit` to the handlers in `@eventuras/fides-auth/server`.
|
|
29
|
+
*/
|
|
22
30
|
async function globalPOSTRateLimit() {
|
|
23
31
|
try {
|
|
24
32
|
const clientIP = (await headers()).get("X-Forwarded-For");
|
|
@@ -30,7 +38,6 @@ async function globalPOSTRateLimit() {
|
|
|
30
38
|
return true;
|
|
31
39
|
}
|
|
32
40
|
}
|
|
33
|
-
//#endregion
|
|
34
41
|
export { globalGETRateLimit, globalPOSTRateLimit };
|
|
35
42
|
|
|
36
43
|
//# sourceMappingURL=request.js.map
|
package/dist/request.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"request.js","names":[],"sources":["../src/request.ts"],"sourcesContent":["import { headers } from 'next/headers';\nimport {TokenBucket} from '@eventuras/fides-auth/rate-limit';\nimport { createLogger } from '@eventuras/fides-auth/logger';\n\nconst logger = createLogger({ namespace: 'fides-auth-next:request' });\n\n// Initialize bucket lazily to avoid worker thread issues\nlet globalBucket: TokenBucket<string> | null = null;\n\nfunction getBucket(): TokenBucket<string> {\n if (!globalBucket) {\n globalBucket = new TokenBucket<string>(100, 1);\n }\n return globalBucket;\n}\n\nexport async function globalGETRateLimit(): Promise<boolean> {\n try {\n const headerStore = await headers();\n const clientIP = headerStore.get('X-Forwarded-For');\n if (clientIP === null) {\n return true;\n }\n return getBucket().consume(clientIP, 1);\n } catch (error) {\n // If worker thread crashes, allow the request through\n if (error instanceof Error && error.message.includes('worker')) {\n logger.error({ error }, 'Worker thread error in globalGETRateLimit');\n } else {\n logger.error({ error }, 'Unexpected error in globalGETRateLimit');\n }\n return true;\n }\n}\n\nexport async function globalPOSTRateLimit(): Promise<boolean> {\n try {\n const headerStore = await headers();\n const clientIP = headerStore.get('X-Forwarded-For');\n if (clientIP === null) {\n return true;\n }\n return getBucket().consume(clientIP, 3);\n } catch (error) {\n // If worker thread crashes, allow the request through\n if (error instanceof Error && error.message.includes('worker')) {\n logger.error({ error }, 'Worker thread error in globalPOSTRateLimit');\n } else {\n logger.error({ error }, 'Unexpected error in globalPOSTRateLimit');\n }\n return true;\n }\n}\n"],"mappings":";;;;AAIA,IAAM,SAAS,aAAa,EAAE,WAAW,0BAA0B,CAAC;AAGpE,IAAI,eAA2C;AAE/C,SAAS,YAAiC;CACxC,IAAI,CAAC,cACH,eAAe,IAAI,YAAoB,KAAK,CAAC;CAE/C,OAAO;AACT
|
|
1
|
+
{"version":3,"file":"request.js","names":[],"sources":["../src/request.ts"],"sourcesContent":["import { headers } from 'next/headers';\nimport {TokenBucket} from '@eventuras/fides-auth/rate-limit';\nimport { createLogger } from '@eventuras/fides-auth/logger';\n\nconst logger = createLogger({ namespace: 'fides-auth-next:request' });\n\n// Initialize bucket lazily to avoid worker thread issues\nlet globalBucket: TokenBucket<string> | null = null;\n\nfunction getBucket(): TokenBucket<string> {\n if (!globalBucket) {\n globalBucket = new TokenBucket<string>(100, 1);\n }\n return globalBucket;\n}\n\n/**\n * @deprecated Keys on the raw `X-Forwarded-For` header, and requests without it pass.\n * Pass your own limiter as `rateLimit` to the handlers in `@eventuras/fides-auth/server`.\n */\nexport async function globalGETRateLimit(): Promise<boolean> {\n try {\n const headerStore = await headers();\n const clientIP = headerStore.get('X-Forwarded-For');\n if (clientIP === null) {\n return true;\n }\n return getBucket().consume(clientIP, 1);\n } catch (error) {\n // If worker thread crashes, allow the request through\n if (error instanceof Error && error.message.includes('worker')) {\n logger.error({ error }, 'Worker thread error in globalGETRateLimit');\n } else {\n logger.error({ error }, 'Unexpected error in globalGETRateLimit');\n }\n return true;\n }\n}\n\n/**\n * @deprecated Keys on the raw `X-Forwarded-For` header, and requests without it pass.\n * Pass your own limiter as `rateLimit` to the handlers in `@eventuras/fides-auth/server`.\n */\nexport async function globalPOSTRateLimit(): Promise<boolean> {\n try {\n const headerStore = await headers();\n const clientIP = headerStore.get('X-Forwarded-For');\n if (clientIP === null) {\n return true;\n }\n return getBucket().consume(clientIP, 3);\n } catch (error) {\n // If worker thread crashes, allow the request through\n if (error instanceof Error && error.message.includes('worker')) {\n logger.error({ error }, 'Worker thread error in globalPOSTRateLimit');\n } else {\n logger.error({ error }, 'Unexpected error in globalPOSTRateLimit');\n }\n return true;\n }\n}\n"],"mappings":";;;;AAIA,IAAM,SAAS,aAAa,EAAE,WAAW,0BAA0B,CAAC;AAGpE,IAAI,eAA2C;AAE/C,SAAS,YAAiC;CACxC,IAAI,CAAC,cACH,eAAe,IAAI,YAAoB,KAAK,CAAC;CAE/C,OAAO;AACT;;;;;AAMA,eAAsB,qBAAuC;CAC3D,IAAI;EAEF,MAAM,YAAW,MADS,QAAQ,EAAA,CACL,IAAI,iBAAiB;EAClD,IAAI,aAAa,MACf,OAAO;EAET,OAAO,UAAU,CAAC,CAAC,QAAQ,UAAU,CAAC;CACxC,SAAS,OAAO;EAEd,IAAI,iBAAiB,SAAS,MAAM,QAAQ,SAAS,QAAQ,GAC3D,OAAO,MAAM,EAAE,MAAM,GAAG,2CAA2C;OAEnE,OAAO,MAAM,EAAE,MAAM,GAAG,wCAAwC;EAElE,OAAO;CACT;AACF;;;;;AAMA,eAAsB,sBAAwC;CAC5D,IAAI;EAEF,MAAM,YAAW,MADS,QAAQ,EAAA,CACL,IAAI,iBAAiB;EAClD,IAAI,aAAa,MACf,OAAO;EAET,OAAO,UAAU,CAAC,CAAC,QAAQ,UAAU,CAAC;CACxC,SAAS,OAAO;EAEd,IAAI,iBAAiB,SAAS,MAAM,QAAQ,SAAS,QAAQ,GAC3D,OAAO,MAAM,EAAE,MAAM,GAAG,4CAA4C;OAEpE,OAAO,MAAM,EAAE,MAAM,GAAG,yCAAyC;EAEnE,OAAO;CACT;AACF"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@eventuras/fides-auth-next",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.8.0",
|
|
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": {
|
|
@@ -18,9 +18,9 @@
|
|
|
18
18
|
"types": "./dist/index.d.ts",
|
|
19
19
|
"import": "./dist/index.js"
|
|
20
20
|
},
|
|
21
|
-
"./
|
|
22
|
-
"types": "./dist/
|
|
23
|
-
"import": "./dist/
|
|
21
|
+
"./auth": {
|
|
22
|
+
"types": "./dist/auth.d.ts",
|
|
23
|
+
"import": "./dist/auth.js"
|
|
24
24
|
},
|
|
25
25
|
"./cookie-store": {
|
|
26
26
|
"types": "./dist/cookie-store.d.ts",
|
|
@@ -58,20 +58,20 @@
|
|
|
58
58
|
"LICENSE"
|
|
59
59
|
],
|
|
60
60
|
"dependencies": {
|
|
61
|
-
"@eventuras/fides-auth-store": "0.
|
|
62
|
-
"@eventuras/fides-auth": "0.
|
|
63
|
-
"@eventuras/fides-auth
|
|
61
|
+
"@eventuras/fides-auth-store": "0.3.0",
|
|
62
|
+
"@eventuras/fides-auth-react": "0.1.8",
|
|
63
|
+
"@eventuras/fides-auth": "0.15.0"
|
|
64
64
|
},
|
|
65
65
|
"devDependencies": {
|
|
66
66
|
"@testing-library/jest-dom": "7.0.1",
|
|
67
|
-
"@types/react": "^19.
|
|
68
|
-
"jsdom": "30.
|
|
69
|
-
"react": "^19.
|
|
67
|
+
"@types/react": "^19.3.0",
|
|
68
|
+
"jsdom": "30.1.3",
|
|
69
|
+
"react": "^19.3.1",
|
|
70
70
|
"typescript": "^7.0.2",
|
|
71
|
-
"vite": "^8.
|
|
71
|
+
"vite": "^8.3.5",
|
|
72
72
|
"vitest": "^4.1.10",
|
|
73
|
-
"@eventuras/
|
|
74
|
-
"@eventuras/
|
|
73
|
+
"@eventuras/vite-config": "0.3.0",
|
|
74
|
+
"@eventuras/typescript-config": "1.0.0"
|
|
75
75
|
},
|
|
76
76
|
"peerDependencies": {
|
|
77
77
|
"next": "^16.0.0",
|
package/dist/session.d.ts
DELETED
|
@@ -1,120 +0,0 @@
|
|
|
1
|
-
import { type ClearSessionOptions, type ReadSessionResult, type RefreshSessionResult } from '@eventuras/fides-auth/server';
|
|
2
|
-
import type { Session, CreateSessionOptions } from '@eventuras/fides-auth/types';
|
|
3
|
-
import type { OAuthConfig } from '@eventuras/fides-auth/oauth';
|
|
4
|
-
export type { ClearSessionOptions, ReadSessionResult, RefreshSessionResult };
|
|
5
|
-
/**
|
|
6
|
-
* Creates an encrypted JWT containing session data.
|
|
7
|
-
*
|
|
8
|
-
* Pre-split API: this serializes the whole session, raw tokens included, into one
|
|
9
|
-
* value. Prefer {@link createAndPersistSession}, which splits the large JWTs across
|
|
10
|
-
* cookies instead of spending one cookie's byte budget on all of them.
|
|
11
|
-
*
|
|
12
|
-
* @param session - Session data (tokens, user, etc.)
|
|
13
|
-
* @param options - Configuration options (e.g., sessionDurationDays)
|
|
14
|
-
* @returns Encrypted JWT string
|
|
15
|
-
*/
|
|
16
|
-
export declare function createSession<TData = Record<string, unknown>>(session: Session<TData>, options?: CreateSessionOptions): Promise<string>;
|
|
17
|
-
/**
|
|
18
|
-
* Retrieves the current session from cookies, if any. Wraps the framework-
|
|
19
|
-
* agnostic {@link readSession} with React's `cache` so repeated calls within one
|
|
20
|
-
* server render share a single read.
|
|
21
|
-
*
|
|
22
|
-
* The session may carry an expired access token — check `accessTokenExpires`
|
|
23
|
-
* before using it, or refresh via `refreshCurrentSession`.
|
|
24
|
-
*
|
|
25
|
-
* @param _config - Unused; kept for backwards compatibility.
|
|
26
|
-
* @returns Session object or null if no session exists.
|
|
27
|
-
*
|
|
28
|
-
* @example
|
|
29
|
-
* ```ts
|
|
30
|
-
* const session = await getCurrentSession();
|
|
31
|
-
* if (session) console.log('User:', session.user);
|
|
32
|
-
* ```
|
|
33
|
-
*/
|
|
34
|
-
export declare const getCurrentSession: (_config?: OAuthConfig) => Promise<Session<any> | null>;
|
|
35
|
-
/**
|
|
36
|
-
* Reads the current session and, when there isn't one, says why.
|
|
37
|
-
*
|
|
38
|
-
* The reason comes from the package-wide vocabulary, so a proxy or a status
|
|
39
|
-
* route logs the same word for the same situation that the heartbeat endpoint
|
|
40
|
-
* logs — which is the point of having a vocabulary at all. Cached per render
|
|
41
|
-
* like {@link getCurrentSession}, and shared with it, so asking for the reason
|
|
42
|
-
* costs no extra decrypt.
|
|
43
|
-
*
|
|
44
|
-
* @example
|
|
45
|
-
* ```ts
|
|
46
|
-
* import {
|
|
47
|
-
* SESSION_EVENT,
|
|
48
|
-
* createLogger,
|
|
49
|
-
* logSessionEvent,
|
|
50
|
-
* tryGetCurrentSession,
|
|
51
|
-
* } from '@eventuras/fides-auth-next';
|
|
52
|
-
* import { redirect } from 'next/navigation';
|
|
53
|
-
*
|
|
54
|
-
* const logger = createLogger({ namespace: 'my-app:proxy' });
|
|
55
|
-
*
|
|
56
|
-
* const { session, reason } = await tryGetCurrentSession();
|
|
57
|
-
* if (!session) {
|
|
58
|
-
* logSessionEvent(logger, { event: SESSION_EVENT.REJECTED, reason, source: 'proxy' });
|
|
59
|
-
* redirect('/login');
|
|
60
|
-
* }
|
|
61
|
-
* ```
|
|
62
|
-
*/
|
|
63
|
-
export declare const tryGetCurrentSession: () => Promise<ReadSessionResult>;
|
|
64
|
-
/**
|
|
65
|
-
* Refreshes the current session using its refresh token and updates the cookies.
|
|
66
|
-
*
|
|
67
|
-
* @param config - OAuth configuration
|
|
68
|
-
* @param options - Session creation options
|
|
69
|
-
* @returns Updated session or null if refresh failed
|
|
70
|
-
*
|
|
71
|
-
* @example
|
|
72
|
-
* ```ts
|
|
73
|
-
* const updated = await refreshCurrentSession(oauthConfig);
|
|
74
|
-
* if (!updated) redirect('/login');
|
|
75
|
-
* ```
|
|
76
|
-
*/
|
|
77
|
-
export declare function refreshCurrentSession(config: OAuthConfig, options?: CreateSessionOptions): Promise<Session | null>;
|
|
78
|
-
/**
|
|
79
|
-
* Refreshes the current session and, on failure, says why.
|
|
80
|
-
*
|
|
81
|
-
* Prefer this over {@link refreshCurrentSession} anywhere the answer decides
|
|
82
|
-
* whether the user stays logged in: a bare null cannot tell "the provider says
|
|
83
|
-
* this refresh token is dead" apart from "we could not reach the provider", and
|
|
84
|
-
* ending a session on the second is how a provider blip becomes a logout.
|
|
85
|
-
*
|
|
86
|
-
* @example
|
|
87
|
-
* ```ts
|
|
88
|
-
* const result = await tryRefreshCurrentSession(oauthConfig);
|
|
89
|
-
* if (!result.ok && result.cause === 'invalid_grant') redirect('/login');
|
|
90
|
-
* // transport / idp_error: keep the session and retry.
|
|
91
|
-
* ```
|
|
92
|
-
*/
|
|
93
|
-
export declare function tryRefreshCurrentSession(config: OAuthConfig, options?: CreateSessionOptions): Promise<RefreshSessionResult>;
|
|
94
|
-
/**
|
|
95
|
-
* Creates and persists a new session across the session/session_at cookies.
|
|
96
|
-
*
|
|
97
|
-
* @param session - Session data
|
|
98
|
-
* @param _options - Session creation options (reserved; not currently applied)
|
|
99
|
-
* @returns The encrypted JWT stored in the main "session" cookie.
|
|
100
|
-
*
|
|
101
|
-
* @example
|
|
102
|
-
* ```ts
|
|
103
|
-
* await createAndPersistSession({
|
|
104
|
-
* tokens: { accessToken: tokens.access_token, refreshToken: tokens.refresh_token },
|
|
105
|
-
* user: { name: 'John Doe', email: 'john@example.com' },
|
|
106
|
-
* });
|
|
107
|
-
* ```
|
|
108
|
-
*/
|
|
109
|
-
export declare function createAndPersistSession(session: Session, _options?: CreateSessionOptions): Promise<string>;
|
|
110
|
-
/**
|
|
111
|
-
* Clears the current session by deleting the session cookies.
|
|
112
|
-
*
|
|
113
|
-
* @example
|
|
114
|
-
* ```ts
|
|
115
|
-
* await clearCurrentSession();
|
|
116
|
-
* redirect('/');
|
|
117
|
-
* ```
|
|
118
|
-
*/
|
|
119
|
-
export declare function clearCurrentSession(options?: ClearSessionOptions): Promise<void>;
|
|
120
|
-
//# sourceMappingURL=session.d.ts.map
|
package/dist/session.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"session.d.ts","sourceRoot":"","sources":["../src/session.ts"],"names":[],"mappings":"AACA,OAAO,EAOL,KAAK,mBAAmB,EACxB,KAAK,iBAAiB,EACtB,KAAK,oBAAoB,EAC1B,MAAM,8BAA8B,CAAC;AACtC,OAAO,KAAK,EAAE,OAAO,EAAE,oBAAoB,EAAE,MAAM,6BAA6B,CAAC;AACjF,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAC;AAU/D,YAAY,EAAE,mBAAmB,EAAE,iBAAiB,EAAE,oBAAoB,EAAE,CAAC;AAE7E;;;;;;;;;;GAUG;AACH,wBAAsB,aAAa,CAAC,KAAK,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EACjE,OAAO,EAAE,OAAO,CAAC,KAAK,CAAC,EACvB,OAAO,GAAE,oBAAyB,GACjC,OAAO,CAAC,MAAM,CAAC,CAUjB;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,eAAO,MAAM,iBAAiB,aACX,WAAW,KAAG,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,GAAG,IAAI,CAG3D,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,eAAO,MAAM,oBAAoB,QACrB,OAAO,CAAC,iBAAiB,CAGpC,CAAC;AAEF;;;;;;;;;;;;GAYG;AACH,wBAAsB,qBAAqB,CACzC,MAAM,EAAE,WAAW,EACnB,OAAO,GAAE,oBAAyB,GACjC,OAAO,CAAC,OAAO,GAAG,IAAI,CAAC,CAEzB;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAsB,wBAAwB,CAC5C,MAAM,EAAE,WAAW,EACnB,OAAO,GAAE,oBAAyB,GACjC,OAAO,CAAC,oBAAoB,CAAC,CAE/B;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAsB,uBAAuB,CAC3C,OAAO,EAAE,OAAO,EAChB,QAAQ,GAAE,oBAAyB,GAClC,OAAO,CAAC,MAAM,CAAC,CAEjB;AAED;;;;;;;;GAQG;AACH,wBAAsB,mBAAmB,CACvC,OAAO,GAAE,mBAAwB,GAChC,OAAO,CAAC,IAAI,CAAC,CASf"}
|