@workos/authkit-session 0.1.1 → 0.1.3
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/core/client/types.d.ts +75 -0
- package/dist/core/client/types.d.ts.map +1 -0
- package/dist/core/client/types.js +2 -0
- package/dist/core/client/types.js.map +1 -0
- package/dist/core/client/workos.d.ts +11 -0
- package/dist/core/client/workos.d.ts.map +1 -0
- package/dist/core/client/workos.js +33 -0
- package/dist/core/client/workos.js.map +1 -0
- package/dist/core/config/ConfigurationProvider.d.ts +43 -0
- package/dist/core/config/ConfigurationProvider.d.ts.map +1 -0
- package/dist/core/config/ConfigurationProvider.js +171 -0
- package/dist/core/config/ConfigurationProvider.js.map +1 -0
- package/dist/core/config/types.d.ts +62 -0
- package/dist/core/config/types.d.ts.map +1 -0
- package/dist/core/config/types.js +2 -0
- package/dist/core/config/types.js.map +1 -0
- package/dist/core/config.d.ts +69 -0
- package/dist/core/config.d.ts.map +1 -0
- package/dist/core/config.js +49 -0
- package/dist/core/config.js.map +1 -0
- package/dist/core/createAuthKitFactory.d.ts +64 -0
- package/dist/core/createAuthKitFactory.d.ts.map +1 -0
- package/dist/core/createAuthKitFactory.js +95 -0
- package/dist/core/createAuthKitFactory.js.map +1 -0
- package/dist/core/encryption/ironSessionEncryption.d.ts +16 -0
- package/dist/core/encryption/ironSessionEncryption.d.ts.map +1 -0
- package/dist/core/encryption/ironSessionEncryption.js +6 -0
- package/dist/core/encryption/ironSessionEncryption.js.map +1 -0
- package/dist/core/encryption/ironWebcryptoEncryption.d.ts +19 -0
- package/dist/core/encryption/ironWebcryptoEncryption.d.ts.map +1 -0
- package/dist/core/encryption/ironWebcryptoEncryption.js +84 -0
- package/dist/core/encryption/ironWebcryptoEncryption.js.map +1 -0
- package/dist/core/encryption/pureWebcryptoEncryption.d.ts +29 -0
- package/dist/core/encryption/pureWebcryptoEncryption.d.ts.map +1 -0
- package/dist/core/encryption/pureWebcryptoEncryption.js +182 -0
- package/dist/core/encryption/pureWebcryptoEncryption.js.map +1 -0
- package/dist/core/errors.d.ts +14 -0
- package/dist/core/errors.d.ts.map +1 -0
- package/dist/core/errors.js +28 -0
- package/dist/core/errors.js.map +1 -0
- package/dist/core/session/CookieSessionStorage.d.ts +33 -0
- package/dist/core/session/CookieSessionStorage.d.ts.map +1 -0
- package/dist/core/session/CookieSessionStorage.js +52 -0
- package/dist/core/session/CookieSessionStorage.js.map +1 -0
- package/dist/core/session/SessionManager.d.ts +51 -0
- package/dist/core/session/SessionManager.d.ts.map +1 -0
- package/dist/core/session/SessionManager.js +238 -0
- package/dist/core/session/SessionManager.js.map +1 -0
- package/dist/core/session/TokenManager.d.ts +14 -0
- package/dist/core/session/TokenManager.d.ts.map +1 -0
- package/dist/core/session/TokenManager.js +43 -0
- package/dist/core/session/TokenManager.js.map +1 -0
- package/dist/core/session/types.d.ts +101 -0
- package/dist/core/session/types.d.ts.map +1 -0
- package/dist/core/session/types.js +2 -0
- package/dist/core/session/types.js.map +1 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +8 -796
- package/dist/index.js.map +1 -1
- package/dist/utils.d.ts +9 -0
- package/dist/utils.d.ts.map +1 -0
- package/dist/utils.js +19 -0
- package/dist/utils.js.map +1 -0
- package/package.json +3 -2
- package/dist/index.cjs +0 -797
- package/dist/index.cjs.map +0 -1
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import type { User, Impersonator, WorkOS } from '@workos-inc/node';
|
|
2
|
+
export interface UserManagementInterface {
|
|
3
|
+
getAuthorizationUrl: (options: AuthorizationURLOptions) => string;
|
|
4
|
+
authenticateWithCode: (options: AuthenticateWithCodeOptions) => Promise<AuthenticationResponse>;
|
|
5
|
+
authenticateWithRefreshToken: (options: AuthenticateWithRefreshTokenOptions) => Promise<AuthenticationResponse>;
|
|
6
|
+
getLogoutUrl: (options: {
|
|
7
|
+
sessionId: string;
|
|
8
|
+
returnTo?: string;
|
|
9
|
+
}) => string;
|
|
10
|
+
revokeSession: (options: {
|
|
11
|
+
sessionId: string;
|
|
12
|
+
}) => Promise<void>;
|
|
13
|
+
}
|
|
14
|
+
export interface WorkOSClientConstructor {
|
|
15
|
+
new (apiKey: string, options?: WorkOSOptions): WorkOS;
|
|
16
|
+
}
|
|
17
|
+
export interface AppInfo {
|
|
18
|
+
name: string;
|
|
19
|
+
version: string;
|
|
20
|
+
}
|
|
21
|
+
export interface WorkOSOptions {
|
|
22
|
+
apiHostname?: string;
|
|
23
|
+
https?: boolean;
|
|
24
|
+
port?: number;
|
|
25
|
+
config?: RequestInit;
|
|
26
|
+
appInfo?: AppInfo;
|
|
27
|
+
fetchFn?: typeof fetch;
|
|
28
|
+
clientId?: string;
|
|
29
|
+
}
|
|
30
|
+
export interface AuthenticationResponse {
|
|
31
|
+
user: User;
|
|
32
|
+
organizationId?: string;
|
|
33
|
+
accessToken: string;
|
|
34
|
+
refreshToken: string;
|
|
35
|
+
impersonator?: Impersonator;
|
|
36
|
+
authenticationMethod?: string;
|
|
37
|
+
sealedSession?: string;
|
|
38
|
+
}
|
|
39
|
+
export interface AuthenticateWithOptionsBase {
|
|
40
|
+
clientId: string;
|
|
41
|
+
ipAddress?: string;
|
|
42
|
+
userAgent?: string;
|
|
43
|
+
session?: {
|
|
44
|
+
cookiePassword?: string;
|
|
45
|
+
sealSession: boolean;
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
export interface AuthenticateWithRefreshTokenOptions extends AuthenticateWithOptionsBase {
|
|
49
|
+
refreshToken: string;
|
|
50
|
+
organizationId?: string;
|
|
51
|
+
}
|
|
52
|
+
export interface AuthenticateWithCodeOptions extends AuthenticateWithOptionsBase {
|
|
53
|
+
codeVerifier?: string;
|
|
54
|
+
code: string;
|
|
55
|
+
invitationToken?: string;
|
|
56
|
+
}
|
|
57
|
+
export interface AuthenticateWithEmailVerificationOptions extends AuthenticateWithOptionsBase {
|
|
58
|
+
code: string;
|
|
59
|
+
pendingAuthenticationToken: string;
|
|
60
|
+
}
|
|
61
|
+
export interface AuthorizationURLOptions {
|
|
62
|
+
clientId: string;
|
|
63
|
+
codeChallenge?: string;
|
|
64
|
+
codeChallengeMethod?: 'S256';
|
|
65
|
+
connectionId?: string;
|
|
66
|
+
context?: string;
|
|
67
|
+
organizationId?: string;
|
|
68
|
+
domainHint?: string;
|
|
69
|
+
loginHint?: string;
|
|
70
|
+
provider?: string;
|
|
71
|
+
redirectUri: string;
|
|
72
|
+
state?: string;
|
|
73
|
+
screenHint?: 'sign-up' | 'sign-in';
|
|
74
|
+
}
|
|
75
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/core/client/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,YAAY,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AACnE,MAAM,WAAW,uBAAuB;IACtC,mBAAmB,EAAE,CAAC,OAAO,EAAE,uBAAuB,KAAK,MAAM,CAAC;IAClE,oBAAoB,EAAE,CACpB,OAAO,EAAE,2BAA2B,KACjC,OAAO,CAAC,sBAAsB,CAAC,CAAC;IACrC,4BAA4B,EAAE,CAC5B,OAAO,EAAE,mCAAmC,KACzC,OAAO,CAAC,sBAAsB,CAAC,CAAC;IACrC,YAAY,EAAE,CAAC,OAAO,EAAE;QAAE,SAAS,EAAE,MAAM,CAAC;QAAC,QAAQ,CAAC,EAAE,MAAM,CAAA;KAAE,KAAK,MAAM,CAAC;IAC5E,aAAa,EAAE,CAAC,OAAO,EAAE;QAAE,SAAS,EAAE,MAAM,CAAA;KAAE,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;CAClE;AAED,MAAM,WAAW,uBAAuB;IACtC,KAAK,MAAM,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,aAAa,GAAG,MAAM,CAAC;CACvD;AAED,MAAM,WAAW,OAAO;IACtB,IAA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AAuB;IACtC,QAAQ,EAAE,MAAM,CAAC;IACjB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,mBAAmB,CAAC,EAAE,MAAM,CAAC;IAC7B,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,WAAW,EAAE,MAAM,CAAC;IACpB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,UAAU,CAAC,EAAE,SAAS,GAAG,SAAS,CAAC;CACpC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/core/client/types.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { WorkOS } from '@workos-inc/node';
|
|
2
|
+
/**
|
|
3
|
+
* Create a WorkOS instance with the provided API key and optional settings.
|
|
4
|
+
*/
|
|
5
|
+
export declare function createWorkOSInstance(): WorkOS;
|
|
6
|
+
/**
|
|
7
|
+
* Create a WorkOS instance with the provided API key and optional settings.
|
|
8
|
+
* This function is lazy loaded to avoid loading the WorkOS SDK when it's not needed.
|
|
9
|
+
*/
|
|
10
|
+
export declare const getWorkOS: () => WorkOS;
|
|
11
|
+
//# sourceMappingURL=workos.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"workos.d.ts","sourceRoot":"","sources":["../../../src/core/client/workos.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAK1C;;GAEG;AACH,wBAAgB,oBAAoB,WAuBnC;AAED;;;GAGG;AACH,eAAO,MAAM,SAAS,cAA6B,CAAC"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { WorkOS } from '@workos-inc/node';
|
|
2
|
+
import { getConfig } from '../config.js';
|
|
3
|
+
import { once } from '../../utils.js';
|
|
4
|
+
import pkg from '../../../package.json' with { type: 'json' };
|
|
5
|
+
/**
|
|
6
|
+
* Create a WorkOS instance with the provided API key and optional settings.
|
|
7
|
+
*/
|
|
8
|
+
export function createWorkOSInstance() {
|
|
9
|
+
// Get required API key from config
|
|
10
|
+
const apiKey = getConfig('apiKey');
|
|
11
|
+
// Get optional settings
|
|
12
|
+
const apiHostname = getConfig('apiHostname');
|
|
13
|
+
const apiHttps = getConfig('apiHttps');
|
|
14
|
+
const apiPort = getConfig('apiPort');
|
|
15
|
+
const options = {
|
|
16
|
+
apiHostname,
|
|
17
|
+
https: apiHttps,
|
|
18
|
+
port: apiPort,
|
|
19
|
+
appInfo: {
|
|
20
|
+
name: 'authkit-session',
|
|
21
|
+
version: pkg.version,
|
|
22
|
+
},
|
|
23
|
+
};
|
|
24
|
+
// Initialize the WorkOS client with config values
|
|
25
|
+
const workos = new WorkOS(apiKey, options);
|
|
26
|
+
return workos;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Create a WorkOS instance with the provided API key and optional settings.
|
|
30
|
+
* This function is lazy loaded to avoid loading the WorkOS SDK when it's not needed.
|
|
31
|
+
*/
|
|
32
|
+
export const getWorkOS = once(createWorkOSInstance);
|
|
33
|
+
//# sourceMappingURL=workos.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"workos.js","sourceRoot":"","sources":["../../../src/core/client/workos.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAC1C,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzC,OAAO,EAAE,IAAI,EAAE,MAAM,gBAAgB,CAAC;AACtC,OAAO,GAAG,MAAM,uBAAuB,CAAC,OAAO,IAAI,EAAE,MAAM,EAAE,CAAC;AAE9D;;GAEG;AACH,MAAM,UAAU,oBAAoB;IAClC,mCAAmC;IACnC,MAAM,MAAM,GAAG,SAAS,CAAC,QAAQ,CAAC,CAAC;IAEnC,wBAAwB;IACxB,MAAM,WAAW,GAAG,SAAS,CAAC,aAAa,CAAC,CAAC;IAC7C,MAAM,QAAQ,GAAG,SAAS,CAAC,UAAU,CAAC,CAAC;IACvC,MAAM,OAAO,GAAG,SAAS,CAAC,SAAS,CAAC,CAAC;IAErC,MAAM,OAAO,GAAG;QACd,WAAW;QACX,KAAK,EAAE,QAAQ;QACf,IAAI,EAAE,OAAO;QACb,OAAO,EAAE;YACP,IAAI,EAAE,iBAAiB;YACvB,OAAO,EAAE,GAAG,CAAC,OAAO;SACrB;KACF,CAAC;IAEF,kDAAkD;IAClD,MAAM,MAAM,GAAG,IAAI,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAE3C,OAAO,MAAM,CAAC;AAChB,CAAC;AAED;;;GAGG;AACH,MAAM,CAAC,MAAM,SAAS,GAAG,IAAI,CAAC,oBAAoB,CAAC,CAAC"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import type { AuthKitConfig, ValueSource } from './types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Configuration class for AuthKit.
|
|
4
|
+
* This class is used to manage configuration values and provide defaults.
|
|
5
|
+
* It also provides a way to get configuration values from environment variables.
|
|
6
|
+
* @internal
|
|
7
|
+
*/
|
|
8
|
+
export declare class ConfigurationProvider {
|
|
9
|
+
private config;
|
|
10
|
+
private valueSource;
|
|
11
|
+
private readonly requiredKeys;
|
|
12
|
+
/**
|
|
13
|
+
* Convert a camelCase string to an uppercase, underscore-separated environment variable name.
|
|
14
|
+
* @param str The string to convert
|
|
15
|
+
* @returns The environment variable name
|
|
16
|
+
*/
|
|
17
|
+
protected getEnvironmentVariableName(str: string): string;
|
|
18
|
+
private updateConfig;
|
|
19
|
+
setValueSource(source: ValueSource): void;
|
|
20
|
+
configure(configOrSource: Partial<AuthKitConfig> | ValueSource, source?: ValueSource): void;
|
|
21
|
+
getValue<K extends keyof AuthKitConfig>(key: K): AuthKitConfig[K];
|
|
22
|
+
private getEnvironmentValue;
|
|
23
|
+
private convertValueType;
|
|
24
|
+
/**
|
|
25
|
+
* Validates that all required configuration values are present and meet requirements.
|
|
26
|
+
* Collects all validation errors before throwing to provide comprehensive feedback.
|
|
27
|
+
*
|
|
28
|
+
* @throws {Error} If any required configuration is missing or invalid
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
31
|
+
* ```typescript
|
|
32
|
+
* const provider = new ConfigurationProvider();
|
|
33
|
+
* try {
|
|
34
|
+
* provider.validate();
|
|
35
|
+
* } catch (error) {
|
|
36
|
+
* console.error(error.message); // Shows all missing/invalid config at once
|
|
37
|
+
* }
|
|
38
|
+
* ```
|
|
39
|
+
*/
|
|
40
|
+
validate(): void;
|
|
41
|
+
getConfig(): AuthKitConfig;
|
|
42
|
+
}
|
|
43
|
+
//# sourceMappingURL=ConfigurationProvider.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ConfigurationProvider.d.ts","sourceRoot":"","sources":["../../../src/core/config/ConfigurationProvider.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAgB7D;;;;;GAKG;AACH,qBAAa,qBAAqB;IAChC,OAAO,CAAC,MAAM,CAQZ;IAEF,OAAO,CAAC,WAAW,CAA8B;IAEjD,OAAO,CAAC,QAAQ,CAAC,YAAY,CAK3B;IAEF;;;;OAIG;IACH,SAAS,CAAC,0BAA0B,CAAC,GAAG,EAAE,MAAM;IAIhD,OAAO,CAAC,YAAY;IAIpB,cAAc,CAAC,MAAM,EAAE,WAAW,GAAG,IAAI;IAIzC,SAAS,CACP,cAAc,EAAE,OAAO,CAAC,aAAa,CAAC,GAAG,WAAW,EACpD,MAAM,CAAC,EAAE,WAAW,GACnB,IAAI;IAWP,QAAQ,CAAC,CAAC,SAAS,MAAM,aAAa,EAAE,GAAG,EAAE,CAAC,GAAG,aAAa,CAAC,CAAC,CAAC;IAoBjE,OAAO,CAAC,mBAAmB;IAc3B,OAAO,CAAC,gBAAgB;IAsBxB;;;;;;;;;;;;;;;OAeG;IACH,QAAQ,IAAI,IAAI;IAiChB,SAAS,IAAI,aAAa;CA4B3B"}
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Default environment variable source that uses process.env
|
|
3
|
+
*/
|
|
4
|
+
const defaultSource = (key) => {
|
|
5
|
+
try {
|
|
6
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
7
|
+
const processEnv = globalThis
|
|
8
|
+
?.process?.env;
|
|
9
|
+
return processEnv?.[key];
|
|
10
|
+
}
|
|
11
|
+
catch {
|
|
12
|
+
return undefined;
|
|
13
|
+
}
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* Configuration class for AuthKit.
|
|
17
|
+
* This class is used to manage configuration values and provide defaults.
|
|
18
|
+
* It also provides a way to get configuration values from environment variables.
|
|
19
|
+
* @internal
|
|
20
|
+
*/
|
|
21
|
+
export class ConfigurationProvider {
|
|
22
|
+
config = {
|
|
23
|
+
cookieName: 'wos-session',
|
|
24
|
+
apiHttps: true,
|
|
25
|
+
// Defaults to 400 days, the maximum allowed by Chrome
|
|
26
|
+
// It's fine to have a long cookie expiry date as the access/refresh tokens
|
|
27
|
+
// act as the actual time-limited aspects of the session.
|
|
28
|
+
cookieMaxAge: 60 * 60 * 24 * 400,
|
|
29
|
+
apiHostname: 'api.workos.com',
|
|
30
|
+
};
|
|
31
|
+
valueSource = defaultSource;
|
|
32
|
+
requiredKeys = [
|
|
33
|
+
'clientId',
|
|
34
|
+
'apiKey',
|
|
35
|
+
'redirectUri',
|
|
36
|
+
'cookiePassword',
|
|
37
|
+
];
|
|
38
|
+
/**
|
|
39
|
+
* Convert a camelCase string to an uppercase, underscore-separated environment variable name.
|
|
40
|
+
* @param str The string to convert
|
|
41
|
+
* @returns The environment variable name
|
|
42
|
+
*/
|
|
43
|
+
getEnvironmentVariableName(str) {
|
|
44
|
+
return `WORKOS_${str.replace(/([a-z])([A-Z])/g, '$1_$2').toUpperCase()}`;
|
|
45
|
+
}
|
|
46
|
+
updateConfig(config) {
|
|
47
|
+
this.config = { ...this.config, ...config };
|
|
48
|
+
}
|
|
49
|
+
setValueSource(source) {
|
|
50
|
+
this.valueSource = source;
|
|
51
|
+
}
|
|
52
|
+
configure(configOrSource, source) {
|
|
53
|
+
if (typeof configOrSource === 'function') {
|
|
54
|
+
this.setValueSource(configOrSource);
|
|
55
|
+
}
|
|
56
|
+
else if (typeof configOrSource === 'object' && !source) {
|
|
57
|
+
this.updateConfig(configOrSource);
|
|
58
|
+
}
|
|
59
|
+
else if (typeof configOrSource === 'object' && source) {
|
|
60
|
+
this.updateConfig(configOrSource);
|
|
61
|
+
this.setValueSource(source);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
getValue(key) {
|
|
65
|
+
const envKey = this.getEnvironmentVariableName(key);
|
|
66
|
+
const envValue = this.getEnvironmentValue(envKey);
|
|
67
|
+
// Use environment value if available, otherwise fall back to config
|
|
68
|
+
const rawValue = envValue ?? this.config[key];
|
|
69
|
+
if (rawValue != null) {
|
|
70
|
+
return this.convertValueType(key, rawValue);
|
|
71
|
+
}
|
|
72
|
+
if (this.requiredKeys.includes(key)) {
|
|
73
|
+
throw new Error(`Missing required configuration value for ${key} (${envKey}).`);
|
|
74
|
+
}
|
|
75
|
+
return undefined;
|
|
76
|
+
}
|
|
77
|
+
getEnvironmentValue(envKey) {
|
|
78
|
+
const { valueSource } = this;
|
|
79
|
+
if (typeof valueSource === 'function') {
|
|
80
|
+
return valueSource(envKey);
|
|
81
|
+
}
|
|
82
|
+
if (valueSource && envKey in valueSource) {
|
|
83
|
+
return valueSource[envKey];
|
|
84
|
+
}
|
|
85
|
+
return undefined;
|
|
86
|
+
}
|
|
87
|
+
convertValueType(key, value) {
|
|
88
|
+
if (typeof value !== 'string') {
|
|
89
|
+
return value;
|
|
90
|
+
}
|
|
91
|
+
// Handle boolean conversion
|
|
92
|
+
if (key === 'apiHttps') {
|
|
93
|
+
return (value === 'true');
|
|
94
|
+
}
|
|
95
|
+
// Handle number conversion
|
|
96
|
+
if (key === 'apiPort' || key === 'cookieMaxAge') {
|
|
97
|
+
const num = parseInt(value, 10);
|
|
98
|
+
return (isNaN(num) ? undefined : num);
|
|
99
|
+
}
|
|
100
|
+
return value;
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Validates that all required configuration values are present and meet requirements.
|
|
104
|
+
* Collects all validation errors before throwing to provide comprehensive feedback.
|
|
105
|
+
*
|
|
106
|
+
* @throws {Error} If any required configuration is missing or invalid
|
|
107
|
+
*
|
|
108
|
+
* @example
|
|
109
|
+
* ```typescript
|
|
110
|
+
* const provider = new ConfigurationProvider();
|
|
111
|
+
* try {
|
|
112
|
+
* provider.validate();
|
|
113
|
+
* } catch (error) {
|
|
114
|
+
* console.error(error.message); // Shows all missing/invalid config at once
|
|
115
|
+
* }
|
|
116
|
+
* ```
|
|
117
|
+
*/
|
|
118
|
+
validate() {
|
|
119
|
+
const errors = [];
|
|
120
|
+
// Validate each required key
|
|
121
|
+
for (const key of this.requiredKeys) {
|
|
122
|
+
const envKey = this.getEnvironmentVariableName(key);
|
|
123
|
+
const envValue = this.getEnvironmentValue(envKey);
|
|
124
|
+
const configValue = this.config[key];
|
|
125
|
+
const value = envValue ?? configValue;
|
|
126
|
+
if (!value) {
|
|
127
|
+
errors.push(`${envKey} is required`);
|
|
128
|
+
}
|
|
129
|
+
else if (key === 'cookiePassword') {
|
|
130
|
+
// Special validation for cookiePassword length
|
|
131
|
+
const password = String(value);
|
|
132
|
+
if (password.length < 32) {
|
|
133
|
+
errors.push(`${envKey} must be at least 32 characters (currently ${password.length})`);
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
if (errors.length > 0) {
|
|
138
|
+
throw new Error('AuthKit configuration error. Missing or invalid environment variables:\n\n' +
|
|
139
|
+
errors.map(e => ` • ${e}`).join('\n') +
|
|
140
|
+
'\n\nSet these environment variables or call configure() with the required values.' +
|
|
141
|
+
'\nGet your values from the WorkOS Dashboard: https://dashboard.workos.com');
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
getConfig() {
|
|
145
|
+
// Build a complete config by merging stored config with environment variables
|
|
146
|
+
const fullConfig = {};
|
|
147
|
+
// Get all keys from the stored config and required keys
|
|
148
|
+
const allKeys = new Set([
|
|
149
|
+
...Object.keys(this.config),
|
|
150
|
+
...this.requiredKeys,
|
|
151
|
+
]);
|
|
152
|
+
// Merge each key, with environment variables taking precedence
|
|
153
|
+
for (const key of allKeys) {
|
|
154
|
+
try {
|
|
155
|
+
const value = this.getValue(key);
|
|
156
|
+
if (value !== undefined) {
|
|
157
|
+
fullConfig[key] = value;
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
catch (error) {
|
|
161
|
+
// If a required key is missing, let the error bubble up
|
|
162
|
+
if (this.requiredKeys.includes(key)) {
|
|
163
|
+
throw error;
|
|
164
|
+
}
|
|
165
|
+
// For optional keys, continue without the value
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
return fullConfig;
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
//# sourceMappingURL=ConfigurationProvider.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ConfigurationProvider.js","sourceRoot":"","sources":["../../../src/core/config/ConfigurationProvider.ts"],"names":[],"mappings":"AAEA;;GAEG;AACH,MAAM,aAAa,GAAgB,CAAC,GAAW,EAAsB,EAAE;IACrE,IAAI,CAAC;QACH,8DAA8D;QAC9D,MAAM,UAAU,GAAwC,UAAkB;YACxE,EAAE,OAAO,EAAE,GAAG,CAAC;QACjB,OAAO,UAAU,EAAE,CAAC,GAAG,CAAC,CAAC;IAC3B,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,SAAS,CAAC;IACnB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EAA2E,CAC9E,CAAC;QACJ,CAAC;IACH,CAAC;IAED,SAAS;QACP,8EAA8E;QAC9E,MAAM,UAAU,GAAG,EAAmB,CAAC;QAEvC,wDAAwD;QACxD,MAAM,OAAO,GAAG,IAAI,GAAG,CAAsB;YAC3C,GAAI,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,CAA6B;YACxD,GAAG,IAAI,CAAC,YAAY;SACrB,CAAC,CAAC;QAEH,+DAA+D;QAC/D,KAAK,MAAM,GAAG,IAAI,OAAO,EAAE,CAAC;YAC1B,IAAI,CAAC;gBACH,MAAM,KAAK,GAAG,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC;gBACjC,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;oBACvB,UAAkB,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;gBACnC,CAAC;YACH,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBACf,wDAAwD;gBACxD,IAAI,IAAI,CAAC,YAAY,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC;oBACpC,MAAM,KAAK,CAAC;gBACd,CAAC;gBACD,gDAAgD;YAClD,CAAC;QACH,CAAC;QAED,OAAO,UAAU,CAAC;IACpB,CAAC;CACF"}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* AuthKit Configuration Options
|
|
3
|
+
*/
|
|
4
|
+
export interface AuthKitConfig {
|
|
5
|
+
/**
|
|
6
|
+
* The WorkOS Client ID
|
|
7
|
+
* Equivalent to the WORKOS_CLIENT_ID environment variable
|
|
8
|
+
*/
|
|
9
|
+
clientId: string;
|
|
10
|
+
/**
|
|
11
|
+
* The WorkOS API Key
|
|
12
|
+
* Equivalent to the WORKOS_API_KEY environment variable
|
|
13
|
+
*/
|
|
14
|
+
apiKey: string;
|
|
15
|
+
/**
|
|
16
|
+
* The redirect URI for the authentication callback
|
|
17
|
+
* Equivalent to the WORKOS_REDIRECT_URI environment variable
|
|
18
|
+
*/
|
|
19
|
+
redirectUri: string;
|
|
20
|
+
/**
|
|
21
|
+
* The password used to encrypt the session cookie
|
|
22
|
+
* Equivalent to the WORKOS_COOKIE_PASSWORD environment variable
|
|
23
|
+
* Must be at least 32 characters long
|
|
24
|
+
*/
|
|
25
|
+
cookiePassword: string;
|
|
26
|
+
/**
|
|
27
|
+
* The hostname of the API to use
|
|
28
|
+
* Equivalent to the WORKOS_API_HOSTNAME environment variable
|
|
29
|
+
*/
|
|
30
|
+
apiHostname?: string;
|
|
31
|
+
/**
|
|
32
|
+
* Whether to use HTTPS for API requests
|
|
33
|
+
* Equivalent to the WORKOS_API_HTTPS environment variable
|
|
34
|
+
*/
|
|
35
|
+
apiHttps: boolean;
|
|
36
|
+
/**
|
|
37
|
+
* The port to use for the API
|
|
38
|
+
* Equivalent to the WORKOS_API_PORT environment variable
|
|
39
|
+
*/
|
|
40
|
+
apiPort?: number;
|
|
41
|
+
/**
|
|
42
|
+
* The maximum age of the session cookie in seconds
|
|
43
|
+
* Equivalent to the WORKOS_COOKIE_MAX_AGE environment variable
|
|
44
|
+
*/
|
|
45
|
+
cookieMaxAge: number;
|
|
46
|
+
/**
|
|
47
|
+
* The sameSite attribute for the session cookie
|
|
48
|
+
*/
|
|
49
|
+
cookieSameSite?: 'strict' | 'lax' | 'none';
|
|
50
|
+
/**
|
|
51
|
+
* The name of the session cookie
|
|
52
|
+
* Equivalent to the WORKOS_COOKIE_NAME environment variable
|
|
53
|
+
* Defaults to "wos-session"
|
|
54
|
+
*/
|
|
55
|
+
cookieName: string;
|
|
56
|
+
/**
|
|
57
|
+
* The domain for the session cookie
|
|
58
|
+
*/
|
|
59
|
+
cookieDomain?: string;
|
|
60
|
+
}
|
|
61
|
+
export type ValueSource = Record<string, any> | ((key: string) => any);
|
|
62
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/core/config/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,WAAW,aAAa;IAC5B;;;OAGG;IACH,QAAQ,EAAE,MAAM,CAAC;IAEjB;;;OAGG;IACH,MAAM,EAAE,MAAM,CAAC;IAEf;;;OAGG;IACH,WAAW,EAAE,MAAM,CAAC;IAEpB;;;;OAIG;IACH,cAAc,EAAE,MAAM,CAAC;IAEvB;;;OAGG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;IAErB;;;OAGG;IACH,QAAQ,EAAE,OAAO,CAAC;IAElB;;;OAGG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;IAEjB;;;OAGG;IACH,YAAY,EAAE,MAAM,CAAC;IAErB;;OAEG;IACH,cAAc,CAAC,EAAE,QAAQ,GAAG,KAAK,GAAG,MAAM,CAAC;IAE3C;;;;OAIG;IACH,UAAU,EAAE,MAAM,CAAC;IAEnB;;OAEG;IACH,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB;AAGD,MAAM,MAAM,WAAW,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,MAAM,KAAK,GAAG,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/core/config/types.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { ConfigurationProvider } from './config/ConfigurationProvider.js';
|
|
2
|
+
import type { AuthKitConfig, ValueSource } from './config/types.js';
|
|
3
|
+
/**
|
|
4
|
+
* Configure AuthKit with a custom value source.
|
|
5
|
+
* @param source The source of configuration values
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* configure(key => Deno.env.get(key));
|
|
9
|
+
*/
|
|
10
|
+
export declare function configure(source: ValueSource): void;
|
|
11
|
+
/**
|
|
12
|
+
* Configure AuthKit with custom values.
|
|
13
|
+
* @param config The configuration values
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* configure({
|
|
17
|
+
* clientId: 'your-client-id',
|
|
18
|
+
* redirectUri: 'https://your-app.com/auth/callback',
|
|
19
|
+
* apiKey: 'your-api-key',
|
|
20
|
+
* cookiePassword: 'your-cookie-password',
|
|
21
|
+
* });
|
|
22
|
+
*/
|
|
23
|
+
export declare function configure(config: Partial<AuthKitConfig>): void;
|
|
24
|
+
/**
|
|
25
|
+
* Configure AuthKit with custom values and a custom value source.
|
|
26
|
+
* @param config The configuration values
|
|
27
|
+
* @param source The source of configuration values
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* configure({
|
|
31
|
+
* clientId: 'your-client-id',
|
|
32
|
+
* }, env);
|
|
33
|
+
*/
|
|
34
|
+
export declare function configure(config: Partial<AuthKitConfig>, source: ValueSource): void;
|
|
35
|
+
/**
|
|
36
|
+
* Get a configuration value by key.
|
|
37
|
+
* This function will first check environment variables, then programmatically provided config,
|
|
38
|
+
* and finally fall back to defaults for optional settings.
|
|
39
|
+
* If a required setting is missing, an error will be thrown.
|
|
40
|
+
* @param key The configuration key
|
|
41
|
+
* @returns The configuration value
|
|
42
|
+
*/
|
|
43
|
+
export declare function getConfig<K extends keyof AuthKitConfig>(key: K): AuthKitConfig[K];
|
|
44
|
+
export declare function getConfigurationProvider(): ConfigurationProvider;
|
|
45
|
+
export declare function getFullConfig(): AuthKitConfig;
|
|
46
|
+
/**
|
|
47
|
+
* Validates that all required configuration values are present and meet requirements.
|
|
48
|
+
* Collects all validation errors before throwing to provide comprehensive feedback.
|
|
49
|
+
*
|
|
50
|
+
* This is useful to call early in your application lifecycle to fail fast with
|
|
51
|
+
* helpful error messages showing all missing/invalid configuration at once.
|
|
52
|
+
*
|
|
53
|
+
* @throws {Error} If any required configuration is missing or invalid
|
|
54
|
+
*
|
|
55
|
+
* @example
|
|
56
|
+
* ```typescript
|
|
57
|
+
* import { validateConfig } from '@workos/authkit-session';
|
|
58
|
+
*
|
|
59
|
+
* // Validate configuration on startup
|
|
60
|
+
* try {
|
|
61
|
+
* validateConfig();
|
|
62
|
+
* } catch (error) {
|
|
63
|
+
* console.error(error.message); // Shows all missing config at once
|
|
64
|
+
* process.exit(1);
|
|
65
|
+
* }
|
|
66
|
+
* ```
|
|
67
|
+
*/
|
|
68
|
+
export declare function validateConfig(): void;
|
|
69
|
+
//# sourceMappingURL=config.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/core/config.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,qBAAqB,EAAE,MAAM,mCAAmC,CAAC;AAC1E,OAAO,KAAK,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAIpE;;;;;;GAMG;AACH,wBAAgB,SAAS,CAAC,MAAM,EAAE,WAAW,GAAG,IAAI,CAAC;AACrD;;;;;;;;;;;GAWG;AACH,wBAAgB,SAAS,CAAC,MAAM,EAAE,OAAO,CAAC,aAAa,CAAC,GAAG,IAAI,CAAC;AAChE;;;;;;;;;GASG;AACH,wBAAgB,SAAS,CACvB,MAAM,EAAE,OAAO,CAAC,aAAa,CAAC,EAC9B,MAAM,EAAE,WAAW,GAClB,IAAI,CAAC;AAQR;;;;;;;GAOG;AACH,wBAAgB,SAAS,CAAC,CAAC,SAAS,MAAM,aAAa,EACrD,GAAG,EAAE,CAAC,GACL,aAAa,CAAC,CAAC,CAAC,CAElB;AAED,wBAAgB,wBAAwB,IAAI,qBAAqB,CAEhE;AAED,wBAAgB,aAAa,IAAI,aAAa,CAE7C;AAED;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAgB,cAAc,IAAI,IAAI,CAErC"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { once } from '../utils.js';
|
|
2
|
+
import { ConfigurationProvider } from './config/ConfigurationProvider.js';
|
|
3
|
+
const getConfigurationInstance = once(() => new ConfigurationProvider());
|
|
4
|
+
export function configure(configOrSource, source) {
|
|
5
|
+
getConfigurationInstance().configure(configOrSource, source);
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Get a configuration value by key.
|
|
9
|
+
* This function will first check environment variables, then programmatically provided config,
|
|
10
|
+
* and finally fall back to defaults for optional settings.
|
|
11
|
+
* If a required setting is missing, an error will be thrown.
|
|
12
|
+
* @param key The configuration key
|
|
13
|
+
* @returns The configuration value
|
|
14
|
+
*/
|
|
15
|
+
export function getConfig(key) {
|
|
16
|
+
return getConfigurationInstance().getValue(key);
|
|
17
|
+
}
|
|
18
|
+
export function getConfigurationProvider() {
|
|
19
|
+
return getConfigurationInstance();
|
|
20
|
+
}
|
|
21
|
+
export function getFullConfig() {
|
|
22
|
+
return getConfigurationInstance().getConfig();
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Validates that all required configuration values are present and meet requirements.
|
|
26
|
+
* Collects all validation errors before throwing to provide comprehensive feedback.
|
|
27
|
+
*
|
|
28
|
+
* This is useful to call early in your application lifecycle to fail fast with
|
|
29
|
+
* helpful error messages showing all missing/invalid configuration at once.
|
|
30
|
+
*
|
|
31
|
+
* @throws {Error} If any required configuration is missing or invalid
|
|
32
|
+
*
|
|
33
|
+
* @example
|
|
34
|
+
* ```typescript
|
|
35
|
+
* import { validateConfig } from '@workos/authkit-session';
|
|
36
|
+
*
|
|
37
|
+
* // Validate configuration on startup
|
|
38
|
+
* try {
|
|
39
|
+
* validateConfig();
|
|
40
|
+
* } catch (error) {
|
|
41
|
+
* console.error(error.message); // Shows all missing config at once
|
|
42
|
+
* process.exit(1);
|
|
43
|
+
* }
|
|
44
|
+
* ```
|
|
45
|
+
*/
|
|
46
|
+
export function validateConfig() {
|
|
47
|
+
return getConfigurationInstance().validate();
|
|
48
|
+
}
|
|
49
|
+
//# sourceMappingURL=config.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.js","sourceRoot":"","sources":["../../src/core/config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,aAAa,CAAC;AACnC,OAAO,EAAE,qBAAqB,EAAE,MAAM,mCAAmC,CAAC;AAG1E,MAAM,wBAAwB,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC,IAAI,qBAAqB,EAAE,CAAC,CAAC;AAqCzE,MAAM,UAAU,SAAS,CACvB,cAAoD,EACpD,MAAoB;IAEpB,wBAAwB,EAAE,CAAC,SAAS,CAAC,cAAc,EAAE,MAAM,CAAC,CAAC;AAC/D,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,SAAS,CACvB,GAAM;IAEN,OAAO,wBAAwB,EAAE,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC;AAClD,CAAC;AAED,MAAM,UAAU,wBAAwB;IACtC,OAAO,wBAAwB,EAAE,CAAC;AACpC,CAAC;AAED,MAAM,UAAU,aAAa;IAC3B,OAAO,wBAAwB,EAAE,CAAC,SAAS,EAAE,CAAC;AAChD,CAAC;AAED;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,MAAM,UAAU,cAAc;IAC5B,OAAO,wBAAwB,EAAE,CAAC,QAAQ,EAAE,CAAC;AAC/C,CAAC"}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import type { WorkOS } from '@workos-inc/node';
|
|
2
|
+
import type { AuthKitConfig } from './config/types.js';
|
|
3
|
+
import type { AuthUrlOptions, BaseTokenClaims, CustomClaims, SessionEncryption, SessionStorage } from './session/types.js';
|
|
4
|
+
export declare const createAuthKitFactory: <TRequest, TResponse>(options: {
|
|
5
|
+
sessionStorageFactory: (config: AuthKitConfig) => SessionStorage<TRequest, TResponse>;
|
|
6
|
+
sessionEncryptionFactory?: (confg: AuthKitConfig) => SessionEncryption;
|
|
7
|
+
clientFactory?: (config: AuthKitConfig) => WorkOS;
|
|
8
|
+
}) => {
|
|
9
|
+
withAuth: (request: any) => Promise<import("./session/types.js").AuthResult<CustomClaims>>;
|
|
10
|
+
getAuthorizationUrl: (args_0?: import("./session/types.js").GetAuthorizationUrlOptions | undefined) => Promise<string>;
|
|
11
|
+
refreshSession: (session: import("./session/types.js").Session, organizationId?: string | undefined) => Promise<{
|
|
12
|
+
user: import("@workos-inc/node").User;
|
|
13
|
+
sessionId: string;
|
|
14
|
+
organizationId: string | undefined;
|
|
15
|
+
role: string | undefined;
|
|
16
|
+
roles: string[] | undefined;
|
|
17
|
+
permissions: string[] | undefined;
|
|
18
|
+
entitlements: string[] | undefined;
|
|
19
|
+
impersonator: import("@workos-inc/node").Impersonator | undefined;
|
|
20
|
+
accessToken: string;
|
|
21
|
+
claims: BaseTokenClaims & CustomClaims;
|
|
22
|
+
sessionData: string;
|
|
23
|
+
session: import("./session/types.js").Session;
|
|
24
|
+
}>;
|
|
25
|
+
saveSession: (response: TResponse | undefined, sessionData: string, options?: unknown) => Promise<{
|
|
26
|
+
response?: TResponse | undefined;
|
|
27
|
+
headers?: import("./session/types.js").HeadersBag;
|
|
28
|
+
}>;
|
|
29
|
+
getSignInUrl: (options?: AuthUrlOptions) => Promise<string>;
|
|
30
|
+
getSignUpUrl: (options?: AuthUrlOptions) => Promise<string>;
|
|
31
|
+
getWorkOS: () => WorkOS;
|
|
32
|
+
getSession: (request: TRequest) => Promise<import("./session/types.js").Session | null>;
|
|
33
|
+
terminateSession: (session: import("./session/types.js").Session, response: any, options?: {
|
|
34
|
+
returnTo?: string;
|
|
35
|
+
} | undefined) => Promise<{
|
|
36
|
+
response?: TResponse | undefined;
|
|
37
|
+
headers?: import("./session/types.js").HeadersBag;
|
|
38
|
+
logoutUrl: string;
|
|
39
|
+
}>;
|
|
40
|
+
signOut: (request: TRequest, response: TResponse, options?: {
|
|
41
|
+
returnTo?: string;
|
|
42
|
+
}) => Promise<TResponse | {
|
|
43
|
+
response?: TResponse | undefined;
|
|
44
|
+
headers?: import("./session/types.js").HeadersBag;
|
|
45
|
+
} | undefined>;
|
|
46
|
+
switchToOrganization: (request: any, response: any, organizationId: string) => Promise<{
|
|
47
|
+
response?: TResponse | undefined;
|
|
48
|
+
headers?: import("./session/types.js").HeadersBag;
|
|
49
|
+
authResult: import("./session/types.js").AuthResult<CustomClaims>;
|
|
50
|
+
}>;
|
|
51
|
+
handleCallback: (_request: TRequest, response: TResponse, options: {
|
|
52
|
+
code: string;
|
|
53
|
+
state?: string;
|
|
54
|
+
}) => Promise<{
|
|
55
|
+
response: {
|
|
56
|
+
response?: TResponse | undefined;
|
|
57
|
+
headers?: import("./session/types.js").HeadersBag;
|
|
58
|
+
};
|
|
59
|
+
returnPathname: string;
|
|
60
|
+
authResponse: import("@workos-inc/node").AuthenticationResponse;
|
|
61
|
+
}>;
|
|
62
|
+
getTokenClaims: <TCustomClaims = CustomClaims>(request: TRequest, accessToken?: string) => Promise<Partial<BaseTokenClaims & TCustomClaims>>;
|
|
63
|
+
};
|
|
64
|
+
//# sourceMappingURL=createAuthKitFactory.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createAuthKitFactory.d.ts","sourceRoot":"","sources":["../../src/core/createAuthKitFactory.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAQ/C,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAIvD,OAAO,KAAK,EACV,cAAc,EACd,eAAe,EACf,YAAY,EACZ,iBAAiB,EACjB,cAAc,EACf,MAAM,oBAAoB,CAAC;AAE5B,eAAO,MAAM,oBAAoB,GAC/B,QAAQ,EACR,SAAS;2BAEc,CACrB,MAAM,EAAE,aAAa,KAClB,cAAc,CAAC,QAAQ,EAAE,SAAS,CAAC;+BACb,CAAC,KAAK,EAAE,aAAa,KAAK,iBAAiB;oBACtD,CAAC,MAAM,EAAE,aAAa,KAAK,MAAM;;;;;;;;;;;;;;;;;;;;;;6BA2CtB,cAAc;6BAMd,cAAc;;0BAUjB,QAAQ;;;;;;;;uBAQnB,QAAQ,YACP,SAAS,YACT;QAAE,QAAQ,CAAC,EAAE,MAAM,CAAA;KAAE;;;;;;;;;+BAuCrB,QAAQ,YACR,SAAS,WACV;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,KAAK,CAAC,EAAE,MAAM,CAAA;KAAE;;;;;;;;qBAoCpB,aAAa,0BACzB,QAAQ,gBACH,MAAM,KACnB,OAAO,CAAC,OAAO,CAAC,eAAe,GAAG,aAAa,CAAC,CAAC;CAiBtD,CAAC"}
|