@workos/authkit-session 0.0.1-alpha.2 → 0.1.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 +184 -11
- package/dist/index.cjs +229 -356
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +225 -352
- package/dist/index.js.map +1 -1
- package/package.json +20 -12
- package/src/core/client/types.ts +2 -7
- package/src/core/client/workos.ts +5 -5
- package/src/core/config/ConfigurationProvider.spec.ts +201 -0
- package/src/core/config/ConfigurationProvider.ts +80 -12
- package/src/core/config.spec.ts +160 -0
- package/src/core/config.ts +29 -3
- package/src/core/createAuthKitFactory.spec.ts +161 -0
- package/src/core/createAuthKitFactory.ts +33 -25
- package/src/core/encryption/ironWebcryptoEncryption.spec.ts +129 -0
- package/src/core/encryption/ironWebcryptoEncryption.ts +28 -23
- package/src/core/encryption/pureWebcryptoEncryption.spec.ts +177 -0
- package/src/core/encryption/pureWebcryptoEncryption.ts +339 -0
- package/src/core/errors.spec.ts +130 -0
- package/src/core/session/CookieSessionStorage.spec.ts +136 -0
- package/src/core/session/CookieSessionStorage.ts +40 -7
- package/src/core/session/SessionManager.spec.ts +357 -0
- package/src/core/session/SessionManager.ts +78 -75
- package/src/core/session/TokenManager.spec.ts +132 -0
- package/src/core/session/TokenManager.ts +8 -6
- package/src/core/session/types.ts +39 -3
- package/src/index.ts +20 -8
- package/src/utils.spec.ts +12 -0
- package/dist/index.d.cts +0 -406
- package/dist/index.d.ts +0 -406
- package/src/HttpClient.ts +0 -160
- package/src/adapters/chrome/ChromeExtensionStorage.ts +0 -34
- package/src/core/UserManagement.ts +0 -8
- package/src/core/client/WorkOSLite.ts +0 -284
- package/src/core/iron.ts +0 -103
package/dist/index.js
CHANGED
|
@@ -1,92 +1,5 @@
|
|
|
1
|
-
//
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
// src/HttpClient.ts
|
|
5
|
-
var HttpClient = class {
|
|
6
|
-
baseUrl;
|
|
7
|
-
defaultHeaders;
|
|
8
|
-
timeout;
|
|
9
|
-
credentials;
|
|
10
|
-
constructor(config) {
|
|
11
|
-
this.baseUrl = config.baseUrl.replace(/\/$/, "");
|
|
12
|
-
this.defaultHeaders = {
|
|
13
|
-
"Content-Type": "application/json",
|
|
14
|
-
Accept: "application/json",
|
|
15
|
-
...config.defaultHeaders
|
|
16
|
-
};
|
|
17
|
-
this.timeout = config.timeout || 3e4;
|
|
18
|
-
this.credentials = config.credentials || "same-origin";
|
|
19
|
-
}
|
|
20
|
-
createError(message, status, details) {
|
|
21
|
-
return { message, status, details };
|
|
22
|
-
}
|
|
23
|
-
async request(endpoint, options) {
|
|
24
|
-
let url = `${this.baseUrl}${endpoint}`;
|
|
25
|
-
const headers = { ...this.defaultHeaders, ...options.headers };
|
|
26
|
-
const fetchOptions = {
|
|
27
|
-
method: options.method,
|
|
28
|
-
headers,
|
|
29
|
-
credentials: options.credentials ?? this.credentials,
|
|
30
|
-
mode: options.mode ?? "cors"
|
|
31
|
-
};
|
|
32
|
-
if (options.params) {
|
|
33
|
-
url += new URLSearchParams(options.params).toString();
|
|
34
|
-
}
|
|
35
|
-
if (options.body) {
|
|
36
|
-
if (options.body instanceof FormData) {
|
|
37
|
-
fetchOptions.body = options.body;
|
|
38
|
-
const headerRecord = fetchOptions.headers;
|
|
39
|
-
delete headerRecord["Content-Type"];
|
|
40
|
-
} else {
|
|
41
|
-
fetchOptions.body = typeof options.body === "string" ? options.body : JSON.stringify(options.body);
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
try {
|
|
45
|
-
const controller = new AbortController();
|
|
46
|
-
const timeoutId = setTimeout(() => controller.abort(), this.timeout);
|
|
47
|
-
const response = await fetch(url, {
|
|
48
|
-
...fetchOptions,
|
|
49
|
-
signal: controller.signal
|
|
50
|
-
});
|
|
51
|
-
clearTimeout(timeoutId);
|
|
52
|
-
const responseData = await response.json();
|
|
53
|
-
const responseHeaders = {};
|
|
54
|
-
response.headers.forEach((value, key) => {
|
|
55
|
-
responseHeaders[key] = value;
|
|
56
|
-
});
|
|
57
|
-
return {
|
|
58
|
-
data: responseData,
|
|
59
|
-
status: response.status,
|
|
60
|
-
headers: responseHeaders,
|
|
61
|
-
ok: response.ok
|
|
62
|
-
};
|
|
63
|
-
} catch (error) {
|
|
64
|
-
if (error instanceof Error) {
|
|
65
|
-
if (error.name === "AbortController") {
|
|
66
|
-
throw this.createError("Request timeout", 408);
|
|
67
|
-
}
|
|
68
|
-
throw this.createError(error.message);
|
|
69
|
-
}
|
|
70
|
-
throw this.createError("Unknown error occurred");
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
async get(endpoint, options = {}) {
|
|
74
|
-
return this.request(endpoint, { ...options, method: "GET" });
|
|
75
|
-
}
|
|
76
|
-
async post(endpoint, body, options = {}) {
|
|
77
|
-
return this.request(endpoint, { ...options, method: "POST", body });
|
|
78
|
-
}
|
|
79
|
-
async put(endpoint, body, options = {}) {
|
|
80
|
-
return this.request(endpoint, { ...options, method: "PUT", body });
|
|
81
|
-
}
|
|
82
|
-
async delete(endpoint, options = {}) {
|
|
83
|
-
return this.request(endpoint, { ...options, method: "DELETE" });
|
|
84
|
-
}
|
|
85
|
-
async patch(endpoint, body, options = {}) {
|
|
86
|
-
return this.request(endpoint, { ...options, method: "PATCH", body });
|
|
87
|
-
}
|
|
88
|
-
};
|
|
89
|
-
var HttpClient_default = HttpClient;
|
|
1
|
+
// src/core/client/workos.ts
|
|
2
|
+
import { WorkOS } from "@workos-inc/node";
|
|
90
3
|
|
|
91
4
|
// src/utils.ts
|
|
92
5
|
function once(fn) {
|
|
@@ -150,9 +63,6 @@ var ConfigurationProvider = class {
|
|
|
150
63
|
this.updateConfig(configOrSource);
|
|
151
64
|
this.setValueSource(source);
|
|
152
65
|
}
|
|
153
|
-
if (this.config.cookiePassword && this.config.cookiePassword.length < 32) {
|
|
154
|
-
throw new Error("cookiePassword must be at least 32 characters long");
|
|
155
|
-
}
|
|
156
66
|
}
|
|
157
67
|
getValue(key) {
|
|
158
68
|
const envKey = this.getEnvironmentVariableName(key);
|
|
@@ -191,8 +101,65 @@ var ConfigurationProvider = class {
|
|
|
191
101
|
}
|
|
192
102
|
return value;
|
|
193
103
|
}
|
|
104
|
+
/**
|
|
105
|
+
* Validates that all required configuration values are present and meet requirements.
|
|
106
|
+
* Collects all validation errors before throwing to provide comprehensive feedback.
|
|
107
|
+
*
|
|
108
|
+
* @throws {Error} If any required configuration is missing or invalid
|
|
109
|
+
*
|
|
110
|
+
* @example
|
|
111
|
+
* ```typescript
|
|
112
|
+
* const provider = new ConfigurationProvider();
|
|
113
|
+
* try {
|
|
114
|
+
* provider.validate();
|
|
115
|
+
* } catch (error) {
|
|
116
|
+
* console.error(error.message); // Shows all missing/invalid config at once
|
|
117
|
+
* }
|
|
118
|
+
* ```
|
|
119
|
+
*/
|
|
120
|
+
validate() {
|
|
121
|
+
const errors = [];
|
|
122
|
+
for (const key of this.requiredKeys) {
|
|
123
|
+
const envKey = this.getEnvironmentVariableName(key);
|
|
124
|
+
const envValue = this.getEnvironmentValue(envKey);
|
|
125
|
+
const configValue = this.config[key];
|
|
126
|
+
const value = envValue ?? configValue;
|
|
127
|
+
if (!value) {
|
|
128
|
+
errors.push(`${envKey} is required`);
|
|
129
|
+
} else if (key === "cookiePassword") {
|
|
130
|
+
const password = String(value);
|
|
131
|
+
if (password.length < 32) {
|
|
132
|
+
errors.push(
|
|
133
|
+
`${envKey} must be at least 32 characters (currently ${password.length})`
|
|
134
|
+
);
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
if (errors.length > 0) {
|
|
139
|
+
throw new Error(
|
|
140
|
+
"AuthKit configuration error. Missing or invalid environment variables:\n\n" + errors.map((e) => ` \u2022 ${e}`).join("\n") + "\n\nSet these environment variables or call configure() with the required values.\nGet your values from the WorkOS Dashboard: https://dashboard.workos.com"
|
|
141
|
+
);
|
|
142
|
+
}
|
|
143
|
+
}
|
|
194
144
|
getConfig() {
|
|
195
|
-
|
|
145
|
+
const fullConfig = {};
|
|
146
|
+
const allKeys = /* @__PURE__ */ new Set([
|
|
147
|
+
...Object.keys(this.config),
|
|
148
|
+
...this.requiredKeys
|
|
149
|
+
]);
|
|
150
|
+
for (const key of allKeys) {
|
|
151
|
+
try {
|
|
152
|
+
const value = this.getValue(key);
|
|
153
|
+
if (value !== void 0) {
|
|
154
|
+
fullConfig[key] = value;
|
|
155
|
+
}
|
|
156
|
+
} catch (error) {
|
|
157
|
+
if (this.requiredKeys.includes(key)) {
|
|
158
|
+
throw error;
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
return fullConfig;
|
|
196
163
|
}
|
|
197
164
|
};
|
|
198
165
|
|
|
@@ -210,211 +177,78 @@ function getConfigurationProvider() {
|
|
|
210
177
|
function getFullConfig() {
|
|
211
178
|
return getConfigurationInstance().getConfig();
|
|
212
179
|
}
|
|
180
|
+
function validateConfig() {
|
|
181
|
+
return getConfigurationInstance().validate();
|
|
182
|
+
}
|
|
213
183
|
|
|
214
|
-
//
|
|
215
|
-
var
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
throw new TypeError("sessionId is required");
|
|
265
|
-
}
|
|
266
|
-
await this.client.post("/user_management/sessions/revoke", {
|
|
267
|
-
session_id: sessionId
|
|
268
|
-
});
|
|
269
|
-
}
|
|
270
|
-
getAuthorizationUrl({
|
|
271
|
-
connectionId,
|
|
272
|
-
codeChallenge,
|
|
273
|
-
codeChallengeMethod,
|
|
274
|
-
context,
|
|
275
|
-
clientId,
|
|
276
|
-
domainHint,
|
|
277
|
-
loginHint,
|
|
278
|
-
organizationId,
|
|
279
|
-
provider,
|
|
280
|
-
redirectUri,
|
|
281
|
-
state,
|
|
282
|
-
screenHint
|
|
283
|
-
}) {
|
|
284
|
-
if (!provider && !connectionId && !organizationId) {
|
|
285
|
-
throw new TypeError(
|
|
286
|
-
`Incomplete arguments. Need to specify either a 'connectionId', 'organizationId', or 'provider'.`
|
|
287
|
-
);
|
|
288
|
-
}
|
|
289
|
-
if (provider !== "authkit" && screenHint) {
|
|
290
|
-
throw new TypeError(
|
|
291
|
-
`'screenHint' is only supported for 'authkit' provider`
|
|
292
|
-
);
|
|
293
|
-
}
|
|
294
|
-
const query = this.toQueryString({
|
|
295
|
-
connection_id: connectionId,
|
|
296
|
-
code_challenge: codeChallenge,
|
|
297
|
-
code_challenge_method: codeChallengeMethod,
|
|
298
|
-
context,
|
|
299
|
-
organization_id: organizationId,
|
|
300
|
-
domain_hint: domainHint,
|
|
301
|
-
login_hint: loginHint,
|
|
302
|
-
provider,
|
|
303
|
-
client_id: clientId,
|
|
304
|
-
redirect_uri: redirectUri,
|
|
305
|
-
response_type: "code",
|
|
306
|
-
state,
|
|
307
|
-
screen_hint: screenHint
|
|
308
|
-
});
|
|
309
|
-
return `${this.baseURL}/user_management/authorize?${query}`;
|
|
310
|
-
}
|
|
311
|
-
async authenticateWithRefreshToken(options) {
|
|
312
|
-
const { data } = await this.client.post(
|
|
313
|
-
"/user_management/authenticate",
|
|
314
|
-
{
|
|
315
|
-
grant_type: "refresh_token",
|
|
316
|
-
client_id: options.clientId,
|
|
317
|
-
client_secret: this.key,
|
|
318
|
-
refresh_token: options.refreshToken,
|
|
319
|
-
organization_id: options.organizationId,
|
|
320
|
-
ip_address: options.ipAddress,
|
|
321
|
-
user_agent: options.userAgent
|
|
322
|
-
}
|
|
323
|
-
);
|
|
324
|
-
return this.deserializeAuthResponse(data);
|
|
325
|
-
}
|
|
326
|
-
async authenticateWithCode(options) {
|
|
327
|
-
const { data } = await this.client.post(
|
|
328
|
-
"/user_management/authenticate",
|
|
329
|
-
{
|
|
330
|
-
grant_type: "authorization_code",
|
|
331
|
-
client_id: options.clientId,
|
|
332
|
-
client_secret: this.key,
|
|
333
|
-
code: options.code,
|
|
334
|
-
code_verifier: options.codeVerifier,
|
|
335
|
-
invitation_token: options.invitationToken,
|
|
336
|
-
ip_address: options.ipAddress,
|
|
337
|
-
user_agent: options.userAgent
|
|
338
|
-
}
|
|
339
|
-
);
|
|
340
|
-
return this.deserializeAuthResponse(data);
|
|
341
|
-
}
|
|
342
|
-
async authenticateWithEmailVerification(options) {
|
|
343
|
-
const { data } = await this.client.post(
|
|
344
|
-
"/user_management/authenticate",
|
|
345
|
-
{
|
|
346
|
-
grant_type: "urn:workos:oauth:grant-type:email-verification:code",
|
|
347
|
-
client_id: options.clientId,
|
|
348
|
-
client_secret: this.key,
|
|
349
|
-
pending_authentication_token: options.pendingAuthenticationToken,
|
|
350
|
-
code: options.code,
|
|
351
|
-
ip_address: options.ipAddress,
|
|
352
|
-
user_agent: options.userAgent
|
|
353
|
-
}
|
|
354
|
-
);
|
|
355
|
-
return this.deserializeAuthResponse(data);
|
|
356
|
-
}
|
|
357
|
-
// Helper to deserialize auth response
|
|
358
|
-
deserializeAuthResponse(data) {
|
|
359
|
-
return {
|
|
360
|
-
user: {
|
|
361
|
-
object: data.user.object,
|
|
362
|
-
id: data.user.id,
|
|
363
|
-
email: data.user.email,
|
|
364
|
-
emailVerified: data.user.email_verified,
|
|
365
|
-
firstName: data.user.first_name,
|
|
366
|
-
profilePictureUrl: data.user.profile_picture_url,
|
|
367
|
-
lastName: data.user.last_name,
|
|
368
|
-
lastSignInAt: data.user.last_sign_in_at,
|
|
369
|
-
createdAt: data.user.created_at,
|
|
370
|
-
updatedAt: data.user.updated_at,
|
|
371
|
-
externalId: data.user.external_id ?? null,
|
|
372
|
-
metadata: data.user.metadata ?? {}
|
|
373
|
-
},
|
|
374
|
-
organizationId: data.organization_id,
|
|
375
|
-
accessToken: data.access_token,
|
|
376
|
-
refreshToken: data.refresh_token,
|
|
377
|
-
impersonator: data.impersonator,
|
|
378
|
-
authenticationMethod: data.authentication_method
|
|
379
|
-
};
|
|
380
|
-
}
|
|
381
|
-
};
|
|
382
|
-
var WorkOSLite = class {
|
|
383
|
-
apiKey;
|
|
384
|
-
baseURL;
|
|
385
|
-
userManagement;
|
|
386
|
-
constructor(apiKey, options) {
|
|
387
|
-
this.apiKey = apiKey;
|
|
388
|
-
const hostname = options.apiHostname || "api.workos.com";
|
|
389
|
-
const protocol = options.https !== false ? "https" : "http";
|
|
390
|
-
const port = options.port ? `:${options.port}` : "";
|
|
391
|
-
this.baseURL = `${protocol}://${hostname}${port}`;
|
|
392
|
-
this.userManagement = new UserManagement(this.apiKey, this.baseURL);
|
|
393
|
-
}
|
|
394
|
-
getJwksUrl(clientId) {
|
|
395
|
-
if (!clientId) {
|
|
396
|
-
throw TypeError("clientId must be a valid clientId");
|
|
397
|
-
}
|
|
398
|
-
return `${this.baseURL}/sso/jwks/${clientId}`;
|
|
399
|
-
}
|
|
184
|
+
// package.json
|
|
185
|
+
var package_default = {
|
|
186
|
+
name: "@workos/authkit-session",
|
|
187
|
+
version: "0.1.1",
|
|
188
|
+
description: "",
|
|
189
|
+
type: "module",
|
|
190
|
+
main: "./dist/index.js",
|
|
191
|
+
types: "./dist/index.d.ts",
|
|
192
|
+
exports: {
|
|
193
|
+
".": {
|
|
194
|
+
types: "./dist/index.d.ts",
|
|
195
|
+
default: "./dist/index.js"
|
|
196
|
+
}
|
|
197
|
+
},
|
|
198
|
+
scripts: {
|
|
199
|
+
clean: "rm -rf dist",
|
|
200
|
+
build: "tsc -p tsconfig.build.json",
|
|
201
|
+
rebuild: "pnpm run clean && pnpm run build",
|
|
202
|
+
dev: "tsc -p tsconfig.build.json --watch",
|
|
203
|
+
prettier: "prettier --check .",
|
|
204
|
+
format: "prettier --write .",
|
|
205
|
+
typecheck: "tsc --noEmit",
|
|
206
|
+
test: "vitest --run",
|
|
207
|
+
"test:coverage": "vitest --run --coverage",
|
|
208
|
+
"test:watch": "vitest --watch"
|
|
209
|
+
},
|
|
210
|
+
keywords: [],
|
|
211
|
+
author: "WorkOS",
|
|
212
|
+
license: "MIT",
|
|
213
|
+
devDependencies: {
|
|
214
|
+
"@types/node": "^20.17.0",
|
|
215
|
+
"@vitest/coverage-v8": "^3.2.4",
|
|
216
|
+
prettier: "^3.6.2",
|
|
217
|
+
typescript: "^5.9.2",
|
|
218
|
+
vitest: "^3.2.4"
|
|
219
|
+
},
|
|
220
|
+
dependencies: {
|
|
221
|
+
"@workos-inc/node": "^8.0.0-beta.4",
|
|
222
|
+
"iron-session": "^8.0.4",
|
|
223
|
+
"iron-webcrypto": "^1.2.1",
|
|
224
|
+
jose: "^6.0.12"
|
|
225
|
+
},
|
|
226
|
+
engines: {
|
|
227
|
+
node: ">=20.0.0"
|
|
228
|
+
},
|
|
229
|
+
files: [
|
|
230
|
+
"dist",
|
|
231
|
+
"src",
|
|
232
|
+
"README.md"
|
|
233
|
+
]
|
|
400
234
|
};
|
|
235
|
+
|
|
236
|
+
// src/core/client/workos.ts
|
|
401
237
|
function createWorkOSInstance() {
|
|
402
238
|
const apiKey = getConfig("apiKey");
|
|
403
239
|
const apiHostname = getConfig("apiHostname");
|
|
404
240
|
const apiHttps = getConfig("apiHttps");
|
|
405
241
|
const apiPort = getConfig("apiPort");
|
|
406
|
-
const clientId = getConfig("clientId");
|
|
407
242
|
const options = {
|
|
408
243
|
apiHostname,
|
|
409
244
|
https: apiHttps,
|
|
410
245
|
port: apiPort,
|
|
411
|
-
clientId,
|
|
412
246
|
appInfo: {
|
|
413
247
|
name: "authkit-session",
|
|
414
|
-
version
|
|
248
|
+
version: package_default.version
|
|
415
249
|
}
|
|
416
250
|
};
|
|
417
|
-
const workos = new
|
|
251
|
+
const workos = new WorkOS(apiKey, options);
|
|
418
252
|
return workos;
|
|
419
253
|
}
|
|
420
254
|
var getWorkOS = once(createWorkOSInstance);
|
|
@@ -477,7 +311,6 @@ var SessionManager = class {
|
|
|
477
311
|
);
|
|
478
312
|
return session;
|
|
479
313
|
} catch (error) {
|
|
480
|
-
console.error("Detailed error:", error);
|
|
481
314
|
throw new SessionEncryptionError("Failed to decrypt session", error);
|
|
482
315
|
}
|
|
483
316
|
}
|
|
@@ -491,41 +324,38 @@ var SessionManager = class {
|
|
|
491
324
|
async validateSession(encryptedSession) {
|
|
492
325
|
try {
|
|
493
326
|
const session = await this.decryptSession(encryptedSession);
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
claims: refreshResult.claims
|
|
524
|
-
};
|
|
525
|
-
} catch (error) {
|
|
327
|
+
const isValid = await this.tokenManager.verifyToken(session.accessToken);
|
|
328
|
+
const isExpiring = this.tokenManager.isTokenExpiring(session.accessToken);
|
|
329
|
+
if (isValid && !isExpiring) {
|
|
330
|
+
const claims = this.tokenManager.parseTokenClaims(
|
|
331
|
+
session.accessToken
|
|
332
|
+
);
|
|
333
|
+
return {
|
|
334
|
+
valid: true,
|
|
335
|
+
session,
|
|
336
|
+
claims
|
|
337
|
+
};
|
|
338
|
+
}
|
|
339
|
+
try {
|
|
340
|
+
const refreshResult = await this.refreshSession(session);
|
|
341
|
+
return {
|
|
342
|
+
valid: true,
|
|
343
|
+
session: refreshResult.session,
|
|
344
|
+
claims: refreshResult.claims
|
|
345
|
+
};
|
|
346
|
+
} catch (refreshError) {
|
|
347
|
+
return {
|
|
348
|
+
valid: false,
|
|
349
|
+
error: refreshError instanceof Error ? refreshError : new TokenRefreshError(
|
|
350
|
+
"Failed to refresh session",
|
|
351
|
+
refreshError
|
|
352
|
+
)
|
|
353
|
+
};
|
|
354
|
+
}
|
|
355
|
+
} catch (decryptError) {
|
|
526
356
|
return {
|
|
527
357
|
valid: false,
|
|
528
|
-
error:
|
|
358
|
+
error: decryptError instanceof Error ? decryptError : new AuthKitError("Failed to decrypt session", decryptError)
|
|
529
359
|
};
|
|
530
360
|
}
|
|
531
361
|
}
|
|
@@ -573,6 +403,7 @@ var SessionManager = class {
|
|
|
573
403
|
sessionId: claims.sid,
|
|
574
404
|
organizationId: claims.org_id,
|
|
575
405
|
role: claims.role,
|
|
406
|
+
roles: claims.roles,
|
|
576
407
|
permissions: claims.permissions,
|
|
577
408
|
entitlements: claims.entitlements,
|
|
578
409
|
impersonator: newSession.impersonator,
|
|
@@ -586,14 +417,20 @@ var SessionManager = class {
|
|
|
586
417
|
}
|
|
587
418
|
}
|
|
588
419
|
async getAuthorizationUrl({
|
|
589
|
-
returnPathname
|
|
420
|
+
returnPathname,
|
|
590
421
|
redirectUri,
|
|
591
|
-
screenHint
|
|
592
|
-
|
|
422
|
+
screenHint,
|
|
423
|
+
organizationId,
|
|
424
|
+
loginHint,
|
|
425
|
+
prompt
|
|
426
|
+
} = {}) {
|
|
593
427
|
return this.client.userManagement.getAuthorizationUrl({
|
|
594
428
|
provider: "authkit",
|
|
595
429
|
redirectUri: redirectUri ?? this.config.getValue("redirectUri"),
|
|
596
430
|
screenHint,
|
|
431
|
+
organizationId,
|
|
432
|
+
loginHint,
|
|
433
|
+
prompt,
|
|
597
434
|
clientId: this.config.getValue("clientId"),
|
|
598
435
|
state: returnPathname ? btoa(JSON.stringify({ returnPathname })) : void 0
|
|
599
436
|
});
|
|
@@ -627,7 +464,8 @@ var SessionManager = class {
|
|
|
627
464
|
refreshResult.sessionData
|
|
628
465
|
);
|
|
629
466
|
return {
|
|
630
|
-
response: updatedResponse,
|
|
467
|
+
response: updatedResponse.response,
|
|
468
|
+
headers: updatedResponse.headers,
|
|
631
469
|
authResult: {
|
|
632
470
|
user: refreshResult.user,
|
|
633
471
|
sessionId: refreshResult.sessionId,
|
|
@@ -674,13 +512,14 @@ var SessionManager = class {
|
|
|
674
512
|
} catch (error) {
|
|
675
513
|
console.error("Failed to revoke session on WorkOS:", error);
|
|
676
514
|
}
|
|
677
|
-
const
|
|
515
|
+
const cleared = await this.storage.clearSession(response);
|
|
678
516
|
const logoutUrl = this.client.userManagement.getLogoutUrl({
|
|
679
517
|
sessionId: claims.sid,
|
|
680
518
|
returnTo: options?.returnTo
|
|
681
519
|
});
|
|
682
520
|
return {
|
|
683
|
-
response:
|
|
521
|
+
response: cleared.response,
|
|
522
|
+
headers: cleared.headers,
|
|
684
523
|
logoutUrl
|
|
685
524
|
};
|
|
686
525
|
}
|
|
@@ -690,8 +529,10 @@ var SessionManager = class {
|
|
|
690
529
|
var CookieSessionStorage = class {
|
|
691
530
|
cookieName;
|
|
692
531
|
cookieOptions;
|
|
532
|
+
config;
|
|
693
533
|
constructor(config) {
|
|
694
|
-
this.
|
|
534
|
+
this.config = config;
|
|
535
|
+
this.cookieName = config.getValue("cookieName") || "wos_session";
|
|
695
536
|
this.cookieOptions = {
|
|
696
537
|
path: "/",
|
|
697
538
|
httpOnly: true,
|
|
@@ -702,10 +543,36 @@ var CookieSessionStorage = class {
|
|
|
702
543
|
domain: config.getValue("cookieDomain")
|
|
703
544
|
};
|
|
704
545
|
}
|
|
546
|
+
async applyHeaders(_response, _headers) {
|
|
547
|
+
}
|
|
548
|
+
buildSetCookie(value, expired) {
|
|
549
|
+
const a = [`${this.cookieName}=${encodeURIComponent(value)}`];
|
|
550
|
+
const o = this.cookieOptions;
|
|
551
|
+
if (o.path) a.push(`Path=${o.path}`);
|
|
552
|
+
if (o.domain) a.push(`Domain=${o.domain}`);
|
|
553
|
+
if (o.maxAge || expired) a.push(`Max-Age=${expired ? 0 : o.maxAge}`);
|
|
554
|
+
if (o.httpOnly) a.push("HttpOnly");
|
|
555
|
+
if (o.secure) a.push("Secure");
|
|
556
|
+
if (o.sameSite) a.push(`SameSite=${o.sameSite}`);
|
|
557
|
+
if (o.priority) a.push(`Priority=${o.priority}`);
|
|
558
|
+
if (o.partitioned) a.push("Partitioned");
|
|
559
|
+
return a.join("; ");
|
|
560
|
+
}
|
|
561
|
+
async saveSession(response, sessionData) {
|
|
562
|
+
const header = this.buildSetCookie(sessionData);
|
|
563
|
+
const mutated = await this.applyHeaders(response, { "Set-Cookie": header });
|
|
564
|
+
return mutated ?? { headers: { "Set-Cookie": header } };
|
|
565
|
+
}
|
|
566
|
+
async clearSession(response) {
|
|
567
|
+
const header = this.buildSetCookie("", true);
|
|
568
|
+
const mutated = await this.applyHeaders(response, { "Set-Cookie": header });
|
|
569
|
+
return mutated ?? { headers: { "Set-Cookie": header } };
|
|
570
|
+
}
|
|
705
571
|
};
|
|
706
572
|
|
|
707
573
|
// src/core/encryption/ironWebcryptoEncryption.ts
|
|
708
574
|
import { seal as sealData, unseal as unsealData } from "iron-webcrypto";
|
|
575
|
+
var ironCrypto = globalThis.crypto;
|
|
709
576
|
var SessionEncryption = class {
|
|
710
577
|
versionDelimiter = "~";
|
|
711
578
|
currentMajorVersion = 2;
|
|
@@ -723,7 +590,7 @@ var SessionEncryption = class {
|
|
|
723
590
|
id: "1",
|
|
724
591
|
secret: password
|
|
725
592
|
};
|
|
726
|
-
const seal = await sealData(
|
|
593
|
+
const seal = await sealData(ironCrypto, data, passwordObj, {
|
|
727
594
|
encryption: {
|
|
728
595
|
saltBits: 256,
|
|
729
596
|
algorithm: "aes-256-cbc",
|
|
@@ -747,28 +614,23 @@ var SessionEncryption = class {
|
|
|
747
614
|
async unsealData(encryptedData, { password }) {
|
|
748
615
|
const { sealWithoutVersion, tokenVersion } = this.parseSeal(encryptedData);
|
|
749
616
|
const passwordMap = { 1: password };
|
|
750
|
-
const data = await unsealData(
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
ttl: 0,
|
|
768
|
-
timestampSkewSec: 60,
|
|
769
|
-
localtimeOffsetMsec: 0
|
|
770
|
-
}
|
|
771
|
-
);
|
|
617
|
+
const data = await unsealData(ironCrypto, sealWithoutVersion, passwordMap, {
|
|
618
|
+
encryption: {
|
|
619
|
+
saltBits: 256,
|
|
620
|
+
algorithm: "aes-256-cbc",
|
|
621
|
+
iterations: 1,
|
|
622
|
+
minPasswordlength: 32
|
|
623
|
+
},
|
|
624
|
+
integrity: {
|
|
625
|
+
saltBits: 256,
|
|
626
|
+
algorithm: "sha256",
|
|
627
|
+
iterations: 1,
|
|
628
|
+
minPasswordlength: 32
|
|
629
|
+
},
|
|
630
|
+
ttl: 0,
|
|
631
|
+
timestampSkewSec: 60,
|
|
632
|
+
localtimeOffsetMsec: 0
|
|
633
|
+
});
|
|
772
634
|
if (tokenVersion === 2) {
|
|
773
635
|
return data;
|
|
774
636
|
} else if (tokenVersion !== null) {
|
|
@@ -790,7 +652,9 @@ var TokenManager = class {
|
|
|
790
652
|
this.client = client;
|
|
791
653
|
}
|
|
792
654
|
getPublicKey = once(
|
|
793
|
-
() => createRemoteJWKSet(
|
|
655
|
+
() => createRemoteJWKSet(
|
|
656
|
+
new URL(this.client.userManagement.getJwksUrl(this.clientId))
|
|
657
|
+
)
|
|
794
658
|
);
|
|
795
659
|
async verifyToken(token) {
|
|
796
660
|
try {
|
|
@@ -855,6 +719,11 @@ var createAuthKitFactory = once(function createAuthKit(options) {
|
|
|
855
719
|
...options2,
|
|
856
720
|
screenHint: "sign-up"
|
|
857
721
|
}),
|
|
722
|
+
// Expose getWorkOS for direct client access
|
|
723
|
+
getWorkOS: () => clientFactory(getFullConfig()),
|
|
724
|
+
// Expose SessionManager's getSession directly
|
|
725
|
+
getSession: (request) => getSessionManager().getSession(request),
|
|
726
|
+
// terminateSession uses the standard SessionManager signature
|
|
858
727
|
terminateSession: (...args) => getSessionManager().terminateSession(...args),
|
|
859
728
|
signOut: async (request, response, options2) => {
|
|
860
729
|
const authResult = await getSessionManager().withAuth(request);
|
|
@@ -875,12 +744,13 @@ var createAuthKitFactory = once(function createAuthKit(options) {
|
|
|
875
744
|
return result.response;
|
|
876
745
|
},
|
|
877
746
|
switchToOrganization: (...args) => getSessionManager().switchToOrganization(...args),
|
|
878
|
-
handleCallback: async (
|
|
879
|
-
const client = clientFactory(getFullConfig());
|
|
747
|
+
handleCallback: async (_request, response, options2) => {
|
|
880
748
|
const config = getFullConfig();
|
|
749
|
+
const clientId = config.clientId;
|
|
750
|
+
const client = clientFactory(config);
|
|
881
751
|
const authResponse = await client.userManagement.authenticateWithCode({
|
|
882
752
|
code: options2.code,
|
|
883
|
-
clientId
|
|
753
|
+
clientId
|
|
884
754
|
});
|
|
885
755
|
const updatedResponse = await getSessionManager().createSession(
|
|
886
756
|
authResponse,
|
|
@@ -914,11 +784,14 @@ var createAuthKitFactory = once(function createAuthKit(options) {
|
|
|
914
784
|
};
|
|
915
785
|
});
|
|
916
786
|
export {
|
|
787
|
+
ConfigurationProvider,
|
|
917
788
|
CookieSessionStorage,
|
|
918
789
|
SessionManager,
|
|
919
790
|
configure,
|
|
920
791
|
createAuthKitFactory,
|
|
921
792
|
getConfig,
|
|
922
|
-
|
|
793
|
+
getConfigurationProvider,
|
|
794
|
+
getWorkOS,
|
|
795
|
+
validateConfig
|
|
923
796
|
};
|
|
924
797
|
//# sourceMappingURL=index.js.map
|