@workos/authkit-session 0.0.1-alpha.3 → 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 +80 -5
- 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 +18 -11
- 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 +75 -7
- 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 +28 -23
- 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 +71 -72
- 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
|
@@ -1,31 +1,34 @@
|
|
|
1
|
-
import type { ConfigurationProvider } from '../config/ConfigurationProvider';
|
|
1
|
+
import type { ConfigurationProvider } from '../config/ConfigurationProvider.js';
|
|
2
2
|
import {
|
|
3
3
|
AuthKitError,
|
|
4
4
|
SessionEncryptionError,
|
|
5
5
|
TokenRefreshError,
|
|
6
|
-
} from '../errors';
|
|
7
|
-
import type { AuthenticationResponse
|
|
8
|
-
import type { TokenManager } from './TokenManager';
|
|
6
|
+
} from '../errors.js';
|
|
7
|
+
import type { AuthenticationResponse } from '../client/types.js';
|
|
8
|
+
import type { TokenManager } from './TokenManager.js';
|
|
9
9
|
import type {
|
|
10
10
|
AuthResult,
|
|
11
11
|
CustomClaims,
|
|
12
|
+
GetAuthorizationUrlOptions,
|
|
13
|
+
HeadersBag,
|
|
12
14
|
Session,
|
|
13
15
|
SessionStorage,
|
|
14
|
-
|
|
15
|
-
|
|
16
|
+
SessionEncryption,
|
|
17
|
+
} from './types.js';
|
|
18
|
+
import type { WorkOS } from '@workos-inc/node';
|
|
16
19
|
|
|
17
20
|
export class SessionManager<TRequest, TResponse> {
|
|
18
21
|
private readonly config: ConfigurationProvider;
|
|
19
22
|
private readonly storage: SessionStorage<TRequest, TResponse>;
|
|
20
23
|
private readonly tokenManager: TokenManager;
|
|
21
|
-
private readonly client:
|
|
24
|
+
private readonly client: WorkOS;
|
|
22
25
|
private readonly encryption: SessionEncryption;
|
|
23
26
|
|
|
24
27
|
constructor(
|
|
25
28
|
config: ConfigurationProvider,
|
|
26
29
|
storage: SessionStorage<TRequest, TResponse>,
|
|
27
30
|
tokenManager: TokenManager,
|
|
28
|
-
client:
|
|
31
|
+
client: WorkOS,
|
|
29
32
|
encryption: SessionEncryption,
|
|
30
33
|
) {
|
|
31
34
|
this.config = config;
|
|
@@ -58,12 +61,11 @@ export class SessionManager<TRequest, TResponse> {
|
|
|
58
61
|
);
|
|
59
62
|
return session;
|
|
60
63
|
} catch (error) {
|
|
61
|
-
console.error('Detailed error:', error);
|
|
62
64
|
throw new SessionEncryptionError('Failed to decrypt session', error);
|
|
63
65
|
}
|
|
64
66
|
}
|
|
65
67
|
|
|
66
|
-
|
|
68
|
+
async getSession(request: TRequest): Promise<Session | null> {
|
|
67
69
|
const encryptedSession = await this.storage.getSession(request);
|
|
68
70
|
if (!encryptedSession) {
|
|
69
71
|
return null;
|
|
@@ -76,58 +78,48 @@ export class SessionManager<TRequest, TResponse> {
|
|
|
76
78
|
) {
|
|
77
79
|
try {
|
|
78
80
|
const session = await this.decryptSession(encryptedSession);
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
session: Session,
|
|
116
|
-
) {
|
|
117
|
-
try {
|
|
118
|
-
const refreshResult = await this.refreshSession<TCustomClaims>(session);
|
|
119
|
-
return {
|
|
120
|
-
valid: true,
|
|
121
|
-
session: refreshResult.session,
|
|
122
|
-
claims: refreshResult.claims,
|
|
123
|
-
};
|
|
124
|
-
} catch (error) {
|
|
81
|
+
const isValid = await this.tokenManager.verifyToken(session.accessToken);
|
|
82
|
+
const isExpiring = this.tokenManager.isTokenExpiring(session.accessToken);
|
|
83
|
+
|
|
84
|
+
// Token is valid and not expiring - return immediately
|
|
85
|
+
if (isValid && !isExpiring) {
|
|
86
|
+
const claims = this.tokenManager.parseTokenClaims<TCustomClaims>(
|
|
87
|
+
session.accessToken,
|
|
88
|
+
);
|
|
89
|
+
return {
|
|
90
|
+
valid: true,
|
|
91
|
+
session,
|
|
92
|
+
claims,
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
// Token needs refresh
|
|
97
|
+
try {
|
|
98
|
+
const refreshResult = await this.refreshSession<TCustomClaims>(session);
|
|
99
|
+
return {
|
|
100
|
+
valid: true,
|
|
101
|
+
session: refreshResult.session,
|
|
102
|
+
claims: refreshResult.claims,
|
|
103
|
+
};
|
|
104
|
+
} catch (refreshError) {
|
|
105
|
+
return {
|
|
106
|
+
valid: false,
|
|
107
|
+
error:
|
|
108
|
+
refreshError instanceof Error
|
|
109
|
+
? refreshError
|
|
110
|
+
: new TokenRefreshError(
|
|
111
|
+
'Failed to refresh session',
|
|
112
|
+
refreshError,
|
|
113
|
+
),
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
} catch (decryptError) {
|
|
125
117
|
return {
|
|
126
118
|
valid: false,
|
|
127
119
|
error:
|
|
128
|
-
|
|
129
|
-
?
|
|
130
|
-
: new
|
|
120
|
+
decryptError instanceof Error
|
|
121
|
+
? decryptError
|
|
122
|
+
: new AuthKitError('Failed to decrypt session', decryptError),
|
|
131
123
|
};
|
|
132
124
|
}
|
|
133
125
|
}
|
|
@@ -191,6 +183,7 @@ export class SessionManager<TRequest, TResponse> {
|
|
|
191
183
|
sessionId: claims.sid,
|
|
192
184
|
organizationId: claims.org_id,
|
|
193
185
|
role: claims.role,
|
|
186
|
+
roles: claims.roles,
|
|
194
187
|
permissions: claims.permissions,
|
|
195
188
|
entitlements: claims.entitlements,
|
|
196
189
|
impersonator: newSession.impersonator,
|
|
@@ -205,18 +198,20 @@ export class SessionManager<TRequest, TResponse> {
|
|
|
205
198
|
}
|
|
206
199
|
|
|
207
200
|
async getAuthorizationUrl({
|
|
208
|
-
returnPathname
|
|
201
|
+
returnPathname,
|
|
209
202
|
redirectUri,
|
|
210
203
|
screenHint,
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
}): Promise<string> {
|
|
204
|
+
organizationId,
|
|
205
|
+
loginHint,
|
|
206
|
+
prompt,
|
|
207
|
+
}: GetAuthorizationUrlOptions = {}): Promise<string> {
|
|
216
208
|
return this.client.userManagement.getAuthorizationUrl({
|
|
217
209
|
provider: 'authkit',
|
|
218
210
|
redirectUri: redirectUri ?? this.config.getValue('redirectUri'),
|
|
219
211
|
screenHint,
|
|
212
|
+
organizationId,
|
|
213
|
+
loginHint,
|
|
214
|
+
prompt,
|
|
220
215
|
clientId: this.config.getValue('clientId'),
|
|
221
216
|
state: returnPathname
|
|
222
217
|
? btoa(JSON.stringify({ returnPathname }))
|
|
@@ -226,8 +221,8 @@ export class SessionManager<TRequest, TResponse> {
|
|
|
226
221
|
|
|
227
222
|
async createSession(
|
|
228
223
|
authResponse: AuthenticationResponse,
|
|
229
|
-
response: TResponse,
|
|
230
|
-
): Promise<TResponse> {
|
|
224
|
+
response: TResponse | undefined,
|
|
225
|
+
): Promise<{ response?: TResponse; headers?: HeadersBag }> {
|
|
231
226
|
const { accessToken, refreshToken, user, impersonator } = authResponse;
|
|
232
227
|
if (!accessToken || !refreshToken) {
|
|
233
228
|
throw new AuthKitError('Missing access or refresh token');
|
|
@@ -251,7 +246,8 @@ export class SessionManager<TRequest, TResponse> {
|
|
|
251
246
|
response: TResponse,
|
|
252
247
|
organizationId: string,
|
|
253
248
|
): Promise<{
|
|
254
|
-
response
|
|
249
|
+
response?: TResponse;
|
|
250
|
+
headers?: HeadersBag;
|
|
255
251
|
authResult: AuthResult<TCustomClaims>;
|
|
256
252
|
}> {
|
|
257
253
|
const session = await this.getSession(request);
|
|
@@ -273,7 +269,8 @@ export class SessionManager<TRequest, TResponse> {
|
|
|
273
269
|
);
|
|
274
270
|
|
|
275
271
|
return {
|
|
276
|
-
response: updatedResponse,
|
|
272
|
+
response: updatedResponse.response,
|
|
273
|
+
headers: updatedResponse.headers,
|
|
277
274
|
authResult: {
|
|
278
275
|
user: refreshResult.user,
|
|
279
276
|
sessionId: refreshResult.sessionId,
|
|
@@ -326,7 +323,8 @@ export class SessionManager<TRequest, TResponse> {
|
|
|
326
323
|
response: TResponse,
|
|
327
324
|
options?: { returnTo?: string },
|
|
328
325
|
): Promise<{
|
|
329
|
-
response
|
|
326
|
+
response?: TResponse;
|
|
327
|
+
headers?: HeadersBag;
|
|
330
328
|
logoutUrl: string;
|
|
331
329
|
}> {
|
|
332
330
|
const claims = this.tokenManager.parseTokenClaims(session.accessToken);
|
|
@@ -342,7 +340,7 @@ export class SessionManager<TRequest, TResponse> {
|
|
|
342
340
|
}
|
|
343
341
|
|
|
344
342
|
// Clear the session cookie locally
|
|
345
|
-
const
|
|
343
|
+
const cleared = await this.storage.clearSession(response);
|
|
346
344
|
|
|
347
345
|
// Generate logout URL (for completeness, though session is already revoked)
|
|
348
346
|
const logoutUrl = this.client.userManagement.getLogoutUrl({
|
|
@@ -351,7 +349,8 @@ export class SessionManager<TRequest, TResponse> {
|
|
|
351
349
|
});
|
|
352
350
|
|
|
353
351
|
return {
|
|
354
|
-
response:
|
|
352
|
+
response: cleared.response,
|
|
353
|
+
headers: cleared.headers,
|
|
355
354
|
logoutUrl,
|
|
356
355
|
};
|
|
357
356
|
}
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
import { TokenManager } from './TokenManager.js';
|
|
2
|
+
|
|
3
|
+
// Mock WorkOS client
|
|
4
|
+
const mockClient = {
|
|
5
|
+
userManagement: {
|
|
6
|
+
getJwksUrl: () => 'https://api.workos.com/sso/jwks/test-client-id',
|
|
7
|
+
},
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
describe('TokenManager', () => {
|
|
11
|
+
let tokenManager: TokenManager;
|
|
12
|
+
|
|
13
|
+
beforeEach(() => {
|
|
14
|
+
tokenManager = new TokenManager('test-client-id', mockClient as any);
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
describe('constructor', () => {
|
|
18
|
+
it('creates instance with client ID and WorkOS client', () => {
|
|
19
|
+
expect(tokenManager).toBeInstanceOf(TokenManager);
|
|
20
|
+
});
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
describe('parseTokenClaims()', () => {
|
|
24
|
+
it('parses valid JWT payload', () => {
|
|
25
|
+
// Simple JWT with valid claims (header.payload.signature)
|
|
26
|
+
const validJwt =
|
|
27
|
+
'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJ1c2VyXzEyMyIsInNpZCI6InNlc3Npb25fMTIzIiwiZXhwIjoxNzM2Mzc2MDAwfQ.fake-signature';
|
|
28
|
+
|
|
29
|
+
const result = tokenManager.parseTokenClaims(validJwt);
|
|
30
|
+
|
|
31
|
+
expect(result.sub).toBe('user_123');
|
|
32
|
+
expect(result.sid).toBe('session_123');
|
|
33
|
+
expect(result.exp).toBe(1736376000);
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
it('throws error for invalid JWT', () => {
|
|
37
|
+
expect(() => tokenManager.parseTokenClaims('invalid-jwt')).toThrow(
|
|
38
|
+
'Invalid token',
|
|
39
|
+
);
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
it('throws error for malformed JWT', () => {
|
|
43
|
+
expect(() => tokenManager.parseTokenClaims('not.a.jwt')).toThrow(
|
|
44
|
+
'Invalid token',
|
|
45
|
+
);
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
it('supports custom claims', () => {
|
|
49
|
+
// JWT with custom claims
|
|
50
|
+
const customJwt =
|
|
51
|
+
'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJ1c2VyXzEyMyIsImN1c3RvbUZpZWxkIjoiY3VzdG9tLXZhbHVlIn0.fake-signature';
|
|
52
|
+
|
|
53
|
+
const result = tokenManager.parseTokenClaims<{ customField: string }>(
|
|
54
|
+
customJwt,
|
|
55
|
+
);
|
|
56
|
+
|
|
57
|
+
expect(result.customField).toBe('custom-value');
|
|
58
|
+
});
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
describe('getTokenExpiryTime()', () => {
|
|
62
|
+
it('returns expiry time from token', () => {
|
|
63
|
+
const jwtWithExp =
|
|
64
|
+
'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJ1c2VyXzEyMyIsImV4cCI6MTczNjM3NjAwMH0.fake-signature';
|
|
65
|
+
|
|
66
|
+
const result = tokenManager.getTokenExpiryTime(jwtWithExp);
|
|
67
|
+
|
|
68
|
+
expect(result).toBe(1736376000);
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
it('returns null when token has no exp claim', () => {
|
|
72
|
+
const jwtWithoutExp =
|
|
73
|
+
'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJ1c2VyXzEyMyJ9.fake-signature';
|
|
74
|
+
|
|
75
|
+
const result = tokenManager.getTokenExpiryTime(jwtWithoutExp);
|
|
76
|
+
|
|
77
|
+
expect(result).toBeNull();
|
|
78
|
+
});
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
describe('isTokenExpiring()', () => {
|
|
82
|
+
it('returns true when token expires soon', () => {
|
|
83
|
+
const soonExpiry = Math.floor(Date.now() / 1000) + 30; // 30 seconds from now
|
|
84
|
+
const expiringJwt = `eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.${btoa(JSON.stringify({ exp: soonExpiry }))}.fake-signature`;
|
|
85
|
+
|
|
86
|
+
const result = tokenManager.isTokenExpiring(expiringJwt);
|
|
87
|
+
|
|
88
|
+
expect(result).toBe(true);
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
it('returns false when token expires later', () => {
|
|
92
|
+
const laterExpiry = Math.floor(Date.now() / 1000) + 3600; // 1 hour from now
|
|
93
|
+
const validJwt = `eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.${btoa(JSON.stringify({ exp: laterExpiry }))}.fake-signature`;
|
|
94
|
+
|
|
95
|
+
const result = tokenManager.isTokenExpiring(validJwt);
|
|
96
|
+
|
|
97
|
+
expect(result).toBe(false);
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
it('uses custom buffer time', () => {
|
|
101
|
+
const expiry = Math.floor(Date.now() / 1000) + 150; // 2.5 minutes from now
|
|
102
|
+
const jwt = `eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.${btoa(JSON.stringify({ exp: expiry }))}.fake-signature`;
|
|
103
|
+
|
|
104
|
+
const result = tokenManager.isTokenExpiring(jwt, 180); // 3 minute buffer
|
|
105
|
+
|
|
106
|
+
expect(result).toBe(true);
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
it('returns false when token has no expiry', () => {
|
|
110
|
+
const noExpiryJwt =
|
|
111
|
+
'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJ1c2VyXzEyMyJ9.fake-signature';
|
|
112
|
+
|
|
113
|
+
const result = tokenManager.isTokenExpiring(noExpiryJwt);
|
|
114
|
+
|
|
115
|
+
expect(result).toBe(false);
|
|
116
|
+
});
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
describe('verifyToken()', () => {
|
|
120
|
+
it('returns false for invalid tokens', async () => {
|
|
121
|
+
const result = await tokenManager.verifyToken('invalid-token');
|
|
122
|
+
|
|
123
|
+
expect(result).toBe(false);
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
it('returns false for malformed tokens', async () => {
|
|
127
|
+
const result = await tokenManager.verifyToken('not.a.jwt');
|
|
128
|
+
|
|
129
|
+
expect(result).toBe(false);
|
|
130
|
+
});
|
|
131
|
+
});
|
|
132
|
+
});
|
|
@@ -1,19 +1,21 @@
|
|
|
1
1
|
import { createRemoteJWKSet, decodeJwt, jwtVerify } from 'jose';
|
|
2
|
-
import { once } from '../../utils';
|
|
3
|
-
import type {
|
|
4
|
-
import type {
|
|
2
|
+
import { once } from '../../utils.js';
|
|
3
|
+
import type { BaseTokenClaims, CustomClaims } from './types.js';
|
|
4
|
+
import type { WorkOS } from '@workos-inc/node';
|
|
5
5
|
|
|
6
6
|
export class TokenManager {
|
|
7
7
|
private clientId: string;
|
|
8
|
-
private client:
|
|
8
|
+
private client: WorkOS;
|
|
9
9
|
|
|
10
|
-
constructor(clientId: string, client:
|
|
10
|
+
constructor(clientId: string, client: WorkOS) {
|
|
11
11
|
this.clientId = clientId;
|
|
12
12
|
this.client = client;
|
|
13
13
|
}
|
|
14
14
|
|
|
15
15
|
private readonly getPublicKey = once(() =>
|
|
16
|
-
createRemoteJWKSet(
|
|
16
|
+
createRemoteJWKSet(
|
|
17
|
+
new URL(this.client.userManagement.getJwksUrl(this.clientId)),
|
|
18
|
+
),
|
|
17
19
|
);
|
|
18
20
|
|
|
19
21
|
async verifyToken(token: string): Promise<boolean> {
|
|
@@ -5,6 +5,7 @@ export interface BaseTokenClaims extends JWTPayload {
|
|
|
5
5
|
sid: string;
|
|
6
6
|
org_id?: string;
|
|
7
7
|
role?: string;
|
|
8
|
+
roles?: string[];
|
|
8
9
|
permissions?: string[];
|
|
9
10
|
entitlements?: string[];
|
|
10
11
|
feature_flags?: string[];
|
|
@@ -43,6 +44,8 @@ export interface Session {
|
|
|
43
44
|
impersonator?: Impersonator;
|
|
44
45
|
}
|
|
45
46
|
|
|
47
|
+
export type HeadersBag = Record<string, string | string[]>;
|
|
48
|
+
|
|
46
49
|
export interface SessionStorage<TRequest, TResponse, TOptions = unknown> {
|
|
47
50
|
/*
|
|
48
51
|
* Extract session data from a request object
|
|
@@ -59,16 +62,19 @@ export interface SessionStorage<TRequest, TResponse, TOptions = unknown> {
|
|
|
59
62
|
* @returns The framework-specific response object with the session cookie set.
|
|
60
63
|
*/
|
|
61
64
|
saveSession(
|
|
62
|
-
response: TResponse,
|
|
65
|
+
response: TResponse | undefined,
|
|
63
66
|
sessionData: string,
|
|
64
67
|
options?: TOptions,
|
|
65
|
-
): Promise<TResponse>;
|
|
68
|
+
): Promise<{ response?: TResponse; headers?: HeadersBag }>;
|
|
66
69
|
|
|
67
70
|
/**
|
|
68
71
|
* @param response The frmework-specific response object.
|
|
69
72
|
* @returns The framework-specific response object with the session cookie removed.
|
|
70
73
|
*/
|
|
71
|
-
clearSession(
|
|
74
|
+
clearSession(
|
|
75
|
+
response: TResponse | undefined,
|
|
76
|
+
options?: TOptions,
|
|
77
|
+
): Promise<{ response?: TResponse; headers?: HeadersBag }>;
|
|
72
78
|
}
|
|
73
79
|
|
|
74
80
|
export interface SessionEncryption {
|
|
@@ -86,3 +92,33 @@ export interface SessionEncryption {
|
|
|
86
92
|
},
|
|
87
93
|
) => Promise<T>;
|
|
88
94
|
}
|
|
95
|
+
|
|
96
|
+
export interface CookieOptions {
|
|
97
|
+
path?: string;
|
|
98
|
+
domain?: string;
|
|
99
|
+
maxAge?: number;
|
|
100
|
+
expires?: Date;
|
|
101
|
+
httpOnly?: boolean;
|
|
102
|
+
secure?: boolean;
|
|
103
|
+
sameSite?: 'lax' | 'strict' | 'none';
|
|
104
|
+
priority?: 'low' | 'medium' | 'high';
|
|
105
|
+
partitioned?: boolean;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* Options for generating authorization URLs
|
|
110
|
+
*/
|
|
111
|
+
export interface AuthUrlOptions {
|
|
112
|
+
returnPathname?: string;
|
|
113
|
+
redirectUri?: string;
|
|
114
|
+
organizationId?: string;
|
|
115
|
+
loginHint?: string;
|
|
116
|
+
prompt?: 'login' | 'none' | 'consent' | 'select_account';
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* Options for getAuthorizationUrl, including screenHint
|
|
121
|
+
*/
|
|
122
|
+
export interface GetAuthorizationUrlOptions extends AuthUrlOptions {
|
|
123
|
+
screenHint?: 'sign-up' | 'sign-in';
|
|
124
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -1,8 +1,20 @@
|
|
|
1
|
-
export { getWorkOS } from './core/client/
|
|
2
|
-
export {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
export
|
|
1
|
+
export { getWorkOS } from './core/client/workos.js';
|
|
2
|
+
export {
|
|
3
|
+
configure,
|
|
4
|
+
getConfig,
|
|
5
|
+
getConfigurationProvider,
|
|
6
|
+
validateConfig,
|
|
7
|
+
} from './core/config.js';
|
|
8
|
+
export { ConfigurationProvider } from './core/config/ConfigurationProvider.js';
|
|
9
|
+
export { SessionManager } from './core/session/SessionManager.js';
|
|
10
|
+
export { CookieSessionStorage } from './core/session/CookieSessionStorage.js';
|
|
11
|
+
export { createAuthKitFactory } from './core/createAuthKitFactory.js';
|
|
12
|
+
export * from './core/session/types.js';
|
|
13
|
+
export * from './core/config/types.js';
|
|
14
|
+
export type {
|
|
15
|
+
User,
|
|
16
|
+
Impersonator,
|
|
17
|
+
Organization,
|
|
18
|
+
WorkOS,
|
|
19
|
+
AuthenticationResponse,
|
|
20
|
+
} from '@workos-inc/node';
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { once } from './utils.js';
|
|
2
|
+
|
|
3
|
+
describe('utils', () => {
|
|
4
|
+
describe('once', () => {
|
|
5
|
+
it('only allows the provided function to be called once, caching its result', () => {
|
|
6
|
+
let num = 0;
|
|
7
|
+
const fn = once(() => ++num);
|
|
8
|
+
expect(fn()).toEqual(1);
|
|
9
|
+
expect(fn()).toEqual(1); // test it's the same on every call
|
|
10
|
+
});
|
|
11
|
+
});
|
|
12
|
+
});
|