@farm.js/workos 0.1.34 → 0.1.36
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 +10 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +22 -10
- package/package.json +3 -3
package/dist/index.d.ts
CHANGED
|
@@ -7,7 +7,17 @@ export interface WorkOSIntegrationInput {
|
|
|
7
7
|
clientId?: string;
|
|
8
8
|
apiKey?: string;
|
|
9
9
|
cookiePassword?: string;
|
|
10
|
+
/**
|
|
11
|
+
* Session cookie name. A `__Host-` name (`__Host-wos-session`) cannot be set or shadowed by a
|
|
12
|
+
* sibling subdomain; Farm adds the `Secure` and `Path=/` it requires.
|
|
13
|
+
* @default "wos-session"
|
|
14
|
+
*/
|
|
10
15
|
cookieName?: string;
|
|
16
|
+
/**
|
|
17
|
+
* Login state cookie name, held between the redirect to AuthKit and the callback.
|
|
18
|
+
* @default "farm_workos_state"
|
|
19
|
+
*/
|
|
20
|
+
stateCookieName?: string;
|
|
11
21
|
loginPath?: string;
|
|
12
22
|
signUpPath?: string;
|
|
13
23
|
callbackPath?: string;
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAC1C,OAAO,EAAuC,KAAK,qBAAqB,EAAE,MAAM,eAAe,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAC1C,OAAO,EAAuC,KAAK,qBAAqB,EAAE,MAAM,eAAe,CAAC;AAiBhG,OAAO,KAAK,EAAuB,oBAAoB,EAAuB,MAAM,aAAa,CAAC;AAQlG,MAAM,WAAW,sBAAsB;IACrC,2FAA2F;IAC3F,QAAQ,CAAC,EAAE,yBAAyB,CAAC;IACrC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB;;;;OAIG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB;;;OAGG;IACH,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,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;;;;OAIG;IACH,cAAc,CAAC,EAAE,MAAM,EAAE,CAAC;IAC1B,GAAG,CAAC,EAAE,qBAAqB,CAAC;CAC7B;AAED,MAAM,MAAM,yBAAyB,GAAG,MAAM,CAAC;AAY/C,UAAU,oBAAoB;IAC5B,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,cAAc,EAAE,MAAM,CAAC;CACxB;AAgGD,wBAAgB,MAAM,CAAC,KAAK,GAAE,sBAA2B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;mBAgPG,MAAM;;;;yBAyE7B,OAAO;;mDAe3C"}
|
package/dist/index.js
CHANGED
|
@@ -3,13 +3,13 @@ import { WorkOS } from "@workos-inc/node";
|
|
|
3
3
|
import { defineIntegration, integrationRoute } from "@farm.js/core";
|
|
4
4
|
import { describeIntegrationOriginRejection, resolveIntegrationAllowedOrigins, validateIntegrationRequestOrigin, } from "@farm.js/core/integrations";
|
|
5
5
|
import { clearRequestCookie, createPathInferredClientApi, createDocumentNavigationMatchers, createRequestCookie, getCookieValue, getReturnTo, integrationConfig, normalizeMatchers, } from "@farm.js/integration-utils";
|
|
6
|
+
import { resolveDevelopmentSecret } from "@farm.js/integration-utils/dev-secret";
|
|
6
7
|
import { workosClient } from "./client.js";
|
|
7
|
-
const DEV_COOKIE_PASSWORD = "farmjs-workos-cookie-password-development-2026";
|
|
8
8
|
// The built server re-evaluates farm.config.ts at runtime to instantiate
|
|
9
9
|
// integrations, and Farm does not force NODE_ENV=production into that process.
|
|
10
10
|
// Treating an absent NODE_ENV as "development" would silently seal production
|
|
11
|
-
// sessions with
|
|
12
|
-
//
|
|
11
|
+
// sessions with a development password, so only an explicit dev/test value
|
|
12
|
+
// may use one. `farm dev` runs through Vite, which sets
|
|
13
13
|
// NODE_ENV="development".
|
|
14
14
|
function isExplicitDevelopmentEnv() {
|
|
15
15
|
return process.env.NODE_ENV === "development" || process.env.NODE_ENV === "test";
|
|
@@ -35,7 +35,7 @@ function resolveEnv(input) {
|
|
|
35
35
|
const cookiePassword = input.cookiePassword ??
|
|
36
36
|
process.env.WORKOS_COOKIE_PASSWORD ??
|
|
37
37
|
process.env.FARM_WORKOS_COOKIE_PASSWORD ??
|
|
38
|
-
(isExplicitDevelopmentEnv() ?
|
|
38
|
+
(isExplicitDevelopmentEnv() ? resolveDevelopmentSecret("workos") : "");
|
|
39
39
|
if (!clientId || (!input.instance && !apiKey)) {
|
|
40
40
|
throw new Error("WorkOS integration requires a client ID and either a WorkOS instance or WORKOS_API_KEY.");
|
|
41
41
|
}
|
|
@@ -68,10 +68,27 @@ async function getSession(workos, request, cookieName, cookiePassword) {
|
|
|
68
68
|
authentication,
|
|
69
69
|
};
|
|
70
70
|
}
|
|
71
|
+
function resolveCookieName(value, fallback, option) {
|
|
72
|
+
if (value === undefined)
|
|
73
|
+
return fallback;
|
|
74
|
+
// RFC 6265 token: no separators, whitespace, or control characters.
|
|
75
|
+
if (!/^[!#$%&'*+\-.^_`|~0-9A-Za-z]+$/.test(value)) {
|
|
76
|
+
throw new Error(`WorkOS integration ${option} must be a valid cookie name, got ${JSON.stringify(value)}.`);
|
|
77
|
+
}
|
|
78
|
+
return value;
|
|
79
|
+
}
|
|
71
80
|
export function workos(input = {}) {
|
|
72
81
|
const { clientId, apiKey, cookiePassword } = resolveEnv(input);
|
|
73
82
|
const protectedMatchers = normalizeMatchers(input.protectedRoutes);
|
|
74
|
-
const cookieName = input.cookieName
|
|
83
|
+
const cookieName = resolveCookieName(input.cookieName, "wos-session", "cookieName");
|
|
84
|
+
// The OAuth `state` must be unguessable and bound to the browser that started
|
|
85
|
+
// the flow. We keep a random nonce in an HMAC-signed, http-only cookie and
|
|
86
|
+
// require the callback's state to match it, so an attacker cannot feed a
|
|
87
|
+
// victim a code/state pair from their own login (login CSRF / code injection).
|
|
88
|
+
const stateCookieName = resolveCookieName(input.stateCookieName, "farm_workos_state", "stateCookieName");
|
|
89
|
+
if (stateCookieName === cookieName) {
|
|
90
|
+
throw new Error("WorkOS integration cookieName and stateCookieName must differ.");
|
|
91
|
+
}
|
|
75
92
|
const loginPath = input.loginPath ?? "/login";
|
|
76
93
|
const signUpPath = input.signUpPath ?? "/signup";
|
|
77
94
|
const callbackPath = input.callbackPath ?? "/callback";
|
|
@@ -83,11 +100,6 @@ export function workos(input = {}) {
|
|
|
83
100
|
apiKey,
|
|
84
101
|
clientId,
|
|
85
102
|
});
|
|
86
|
-
// The OAuth `state` must be unguessable and bound to the browser that started
|
|
87
|
-
// the flow. We keep a random nonce in an HMAC-signed, http-only cookie and
|
|
88
|
-
// require the callback's state to match it, so an attacker cannot feed a
|
|
89
|
-
// victim a code/state pair from their own login (login CSRF / code injection).
|
|
90
|
-
const stateCookieName = "farm_workos_state";
|
|
91
103
|
function signState(payload) {
|
|
92
104
|
const encoded = Buffer.from(JSON.stringify(payload), "utf8").toString("base64url");
|
|
93
105
|
const signature = createHmac("sha256", cookiePassword).update(encoded).digest("hex");
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@farm.js/workos",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.36",
|
|
4
4
|
"description": "WorkOS integration for Farm.js",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -30,8 +30,8 @@
|
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
32
|
"@workos-inc/node": "^8.9.0",
|
|
33
|
-
"@farm.js/
|
|
34
|
-
"@farm.js/
|
|
33
|
+
"@farm.js/core": "0.1.36",
|
|
34
|
+
"@farm.js/integration-utils": "0.1.36"
|
|
35
35
|
},
|
|
36
36
|
"scripts": {
|
|
37
37
|
"build": "node -e \"require('node:fs').rmSync('dist', { recursive: true, force: true })\" && tsc",
|