@farm.js/auth0 0.1.0-beta.10 → 0.1.0-beta.101

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -17,6 +17,12 @@ export interface Auth0IntegrationInput {
17
17
  logoutPath?: string;
18
18
  profilePath?: string;
19
19
  protectedRoutes?: string | string[];
20
+ /**
21
+ * Additional origins allowed to drive the sign-out route, using the same
22
+ * pattern syntax as `serverActions.allowedOrigins`. The app's own origin is
23
+ * always trusted.
24
+ */
25
+ allowedOrigins?: string[];
20
26
  audience?: string;
21
27
  scopes?: string[];
22
28
  tokenEndpointAuthMethod?: "auto" | "client_secret_basic" | "client_secret_post" | "none";
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAuC,KAAK,qBAAqB,EAAE,MAAM,eAAe,CAAC;AAkBhG,MAAM,WAAW,aAAa;IAC5B,UAAU,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,QAAQ,GAAG,IAAI,CAAC,GAAG,QAAQ,GAAG,IAAI,CAAC;IACzE,OAAO,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;CAC7B;AAED,MAAM,WAAW,qBAAqB;IACpC,QAAQ,CAAC,EAAE,aAAa,CAAC;IACzB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,WAAW,CAAC,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EAAE,MAAM,CAAC;IACnB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,eAAe,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;IACpC;;;;OAIG;IACH,cAAc,CAAC,EAAE,MAAM,EAAE,CAAC;IAC1B,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC;IAClB,uBAAuB,CAAC,EAAE,MAAM,GAAG,qBAAqB,GAAG,oBAAoB,GAAG,MAAM,CAAC;IACzF,GAAG,CAAC,EAAE,qBAAqB,CAAC;CAC7B;AAED,UAAU,gBAAgB;IACxB,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,MAAM,CAAC;IACjB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AA6PD,wBAAgB,KAAK,CAAC,KAAK,GAAE,qBAA0B;;;;;;;yBAU5B,OAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;yBAsSH,OAAO;;GAmBrC"}
package/dist/index.js CHANGED
@@ -1,8 +1,17 @@
1
1
  import { createHash, createHmac, randomBytes, timingSafeEqual } from "node:crypto";
2
2
  import { defineIntegration, integrationRoute } from "@farm.js/core";
3
+ import { describeIntegrationOriginRejection, resolveIntegrationAllowedOrigins, validateIntegrationRequestOrigin, } from "@farm.js/core/integrations";
3
4
  import { clearRequestCookie, createPathInferredClientApi, createDocumentNavigationMatchers, createRequestCookie, getOrigin, getReturnTo, integrationConfig, normalizeMatchers, parseCookieHeaderMap, resolveCallbackSettings, } from "@farm.js/integration-utils";
4
5
  import { auth0Client } from "./client.js";
5
6
  const DEV_SECRET = "farmjs-auth0-development-secret-2026";
7
+ // The built server re-evaluates farm.config.ts at runtime to instantiate
8
+ // integrations, and Farm does not force NODE_ENV=production into that process.
9
+ // Treating an absent NODE_ENV as "development" would silently sign production
10
+ // sessions with the public DEV_SECRET, so only an explicit dev/test value may
11
+ // use it. `farm dev` runs through Vite, which sets NODE_ENV="development".
12
+ function isExplicitDevelopmentEnv() {
13
+ return process.env.NODE_ENV === "development" || process.env.NODE_ENV === "test";
14
+ }
6
15
  function createAuth0Api(input) {
7
16
  return createPathInferredClientApi({
8
17
  path: input.loginPath,
@@ -25,15 +34,15 @@ function resolveEnv(input) {
25
34
  const domain = normalizeDomain(input.domain ?? process.env.AUTH0_DOMAIN ?? "");
26
35
  const clientId = input.clientId ?? process.env.AUTH0_CLIENT_ID ?? "";
27
36
  const clientSecret = input.clientSecret ?? process.env.AUTH0_CLIENT_SECRET ?? "";
28
- const secret = input.secret ??
29
- process.env.AUTH0_SECRET ??
30
- (process.env.NODE_ENV === "production" ? "" : DEV_SECRET);
37
+ const secret = input.secret ?? process.env.AUTH0_SECRET ?? (isExplicitDevelopmentEnv() ? DEV_SECRET : "");
31
38
  const appBaseUrl = input.appBaseUrl ?? process.env.APP_BASE_URL ?? undefined;
32
39
  if (!domain || !clientId) {
33
40
  throw new Error("Auth0 integration requires AUTH0_DOMAIN and AUTH0_CLIENT_ID.");
34
41
  }
35
42
  if (!secret) {
36
- throw new Error("Auth0 integration requires AUTH0_SECRET in production.");
43
+ throw new Error("Auth0 integration requires AUTH0_SECRET. A development-only fallback secret is used " +
44
+ 'only when NODE_ENV is "development" or "test"; set AUTH0_SECRET to a random 32-byte ' +
45
+ "value in every other environment.");
37
46
  }
38
47
  return {
39
48
  domain,
@@ -187,6 +196,7 @@ export function auth0(input = {}) {
187
196
  const logoutPath = input.logoutPath ?? "/auth/logout";
188
197
  const profilePath = input.profilePath ?? "/auth/profile";
189
198
  const scopes = input.scopes?.length ? input.scopes : ["openid", "profile", "email"];
199
+ const allowedOrigins = resolveIntegrationAllowedOrigins(input.allowedOrigins, "auth0.allowedOrigins");
190
200
  const stateCookieName = "farm_auth0_state";
191
201
  const sessionCookieName = "farm_auth0_session";
192
202
  const callbackSettings = resolveCallbackSettings({
@@ -335,6 +345,23 @@ export function auth0(input = {}) {
335
345
  integrationRoute.get(logoutPath, {
336
346
  responseFormat: "json",
337
347
  handler(request) {
348
+ // Sign-out is a GET, so it is also reachable as a plain link or a
349
+ // bookmark with no origin metadata at all. Only a request the browser
350
+ // labelled cross-site is refused.
351
+ const originResult = validateIntegrationRequestOrigin(request, {
352
+ allowedOrigins,
353
+ requireOriginMetadata: false,
354
+ });
355
+ if (!originResult.ok) {
356
+ const message = describeIntegrationOriginRejection(originResult.reason);
357
+ if (request.headers.get("x-farm-integration-client") === "1") {
358
+ return Response.json({ error: message }, { status: 403 });
359
+ }
360
+ return new Response(message, {
361
+ status: 403,
362
+ headers: { "content-type": "text/plain; charset=utf-8" },
363
+ });
364
+ }
338
365
  const origin = getOrigin(request, appBaseUrl);
339
366
  const redirectTo = new URL("/v2/logout", `https://${domain}`);
340
367
  redirectTo.searchParams.set("client_id", clientId);
@@ -384,7 +411,7 @@ export function auth0(input = {}) {
384
411
  const requestUrl = new URL(request.url);
385
412
  const redirectUrl = new URL(loginPath, getOrigin(request, appBaseUrl));
386
413
  redirectUrl.searchParams.set("returnTo", `${requestUrl.pathname}${requestUrl.search}`);
387
- return Response.redirect(redirectUrl, 307);
414
+ return Response.redirect(redirectUrl, 303); // 303 (See Other) mandates a GET on the GET-only login route regardless of the original method (RFC 7231 §6.4.4)
388
415
  },
389
416
  },
390
417
  ]
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@farm.js/auth0",
3
- "version": "0.1.0-beta.10",
3
+ "version": "0.1.0-beta.101",
4
4
  "description": "Auth0 integration for Farm.js",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -29,8 +29,8 @@
29
29
  "access": "public"
30
30
  },
31
31
  "dependencies": {
32
- "@farm.js/core": "0.1.0-beta.10",
33
- "@farm.js/integration-utils": "0.1.0-beta.10"
32
+ "@farm.js/core": "0.1.0-beta.101",
33
+ "@farm.js/integration-utils": "0.1.0-beta.101"
34
34
  },
35
35
  "scripts": {
36
36
  "build": "node -e \"require('node:fs').rmSync('dist', { recursive: true, force: true })\" && tsc",