@farm.js/auth0 0.1.0-beta.98 → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -2,10 +2,10 @@
2
2
 
3
3
  Auth0 integration for Farm.js
4
4
 
5
- Farm.js is currently in beta.
5
+ See [Stability and Support](https://farmjs.dev/docs/stability) for what this package guarantees.
6
6
 
7
7
  ```bash
8
- npm install @farm.js/auth0@beta
8
+ npm install @farm.js/auth0
9
9
  ```
10
10
 
11
11
  See the [Farm.js repository](https://github.com/farming-labs/farm.js) for documentation, examples, and support.
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";
@@ -46,7 +52,7 @@ export declare function auth0(input?: Auth0IntegrationInput): import("@farm.js/c
46
52
  clientId: string;
47
53
  protectedRoutes: string[];
48
54
  };
49
- config: import("@farm.js/core").FarmIntegrationConfigDefinition<ResolvedAuth0Env, import("@farm.js/core").FarmIntegrationSchema | undefined>;
55
+ config: import("@farm.js/core").FarmIntegrationConfigDefinition<ResolvedAuth0Env, import("@farm.js/core").FarmSchema | undefined>;
50
56
  api: {
51
57
  [x: string]: {
52
58
  get: {
@@ -79,7 +85,7 @@ export declare function auth0(input?: Auth0IntegrationInput): import("@farm.js/c
79
85
  documentNavigations: {
80
86
  matcher: string[];
81
87
  }[];
82
- routes: import("@farm.js/core").FarmTypedIntegrationRoute<string, never, any, unknown, false, "GET", import("@farm.js/core").FarmIntegrationSchema | undefined>[];
88
+ routes: import("@farm.js/core").FarmTypedIntegrationRoute<string, never, any, unknown, false, "GET", import("@farm.js/core").FarmSchema | undefined>[];
83
89
  middleware: {
84
90
  matcher: string[];
85
91
  handler(request: Request): Response | undefined;
@@ -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;AA2BhG,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,EAAE,MAAM,CAAC;IACrB,eAAe,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;IACpC,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;IAC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,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,5 +1,6 @@
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";
@@ -195,6 +196,7 @@ export function auth0(input = {}) {
195
196
  const logoutPath = input.logoutPath ?? "/auth/logout";
196
197
  const profilePath = input.profilePath ?? "/auth/profile";
197
198
  const scopes = input.scopes?.length ? input.scopes : ["openid", "profile", "email"];
199
+ const allowedOrigins = resolveIntegrationAllowedOrigins(input.allowedOrigins, "auth0.allowedOrigins");
198
200
  const stateCookieName = "farm_auth0_state";
199
201
  const sessionCookieName = "farm_auth0_session";
200
202
  const callbackSettings = resolveCallbackSettings({
@@ -343,6 +345,23 @@ export function auth0(input = {}) {
343
345
  integrationRoute.get(logoutPath, {
344
346
  responseFormat: "json",
345
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
+ }
346
365
  const origin = getOrigin(request, appBaseUrl);
347
366
  const redirectTo = new URL("/v2/logout", `https://${domain}`);
348
367
  redirectTo.searchParams.set("client_id", clientId);
@@ -392,7 +411,7 @@ export function auth0(input = {}) {
392
411
  const requestUrl = new URL(request.url);
393
412
  const redirectUrl = new URL(loginPath, getOrigin(request, appBaseUrl));
394
413
  redirectUrl.searchParams.set("returnTo", `${requestUrl.pathname}${requestUrl.search}`);
395
- 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)
396
415
  },
397
416
  },
398
417
  ]
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@farm.js/auth0",
3
- "version": "0.1.0-beta.98",
3
+ "version": "0.1.0",
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.98",
33
- "@farm.js/integration-utils": "0.1.0-beta.98"
32
+ "@farm.js/core": "0.1.0",
33
+ "@farm.js/integration-utils": "0.1.0"
34
34
  },
35
35
  "scripts": {
36
36
  "build": "node -e \"require('node:fs').rmSync('dist', { recursive: true, force: true })\" && tsc",