@cedarjs/auth-dbauth-api 7.0.0 → 8.0.0-canary.3263
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/DbAuthHandler.d.ts +6 -33
- package/dist/DbAuthHandler.d.ts.map +1 -1
- package/dist/DbAuthHandler.js +43 -57
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/session.d.ts +114 -0
- package/dist/session.d.ts.map +1 -0
- package/dist/session.js +103 -0
- package/package.json +13 -6
package/dist/DbAuthHandler.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import type { AuthenticationResponseJSON, RegistrationResponseJSON } from '@simplewebauthn/
|
|
1
|
+
import type { AuthenticationResponseJSON, RegistrationResponseJSON } from '@simplewebauthn/server';
|
|
2
2
|
import type { APIGatewayProxyEvent, Context as LambdaContext } from 'aws-lambda';
|
|
3
3
|
import type { CorsConfig, CorsContext, PartialRequest } from '@cedarjs/api';
|
|
4
|
+
import type { DbAuthCookieConfig } from './session.js';
|
|
4
5
|
interface SignupFlowOptions<TUserAttributes = Record<string, unknown>> {
|
|
5
6
|
/**
|
|
6
7
|
* Allow users to sign up. Defaults to true.
|
|
@@ -170,33 +171,7 @@ export interface DbAuthHandlerOptions<TUser = UserType, TUserAttributes = Record
|
|
|
170
171
|
/**
|
|
171
172
|
* Object containing cookie config options
|
|
172
173
|
*/
|
|
173
|
-
cookie?:
|
|
174
|
-
/** @deprecated set this option in `cookie.attributes` */
|
|
175
|
-
Path?: string;
|
|
176
|
-
/** @deprecated set this option in `cookie.attributes` */
|
|
177
|
-
HttpOnly?: boolean;
|
|
178
|
-
/** @deprecated set this option in `cookie.attributes` */
|
|
179
|
-
Secure?: boolean;
|
|
180
|
-
/** @deprecated set this option in `cookie.attributes` */
|
|
181
|
-
SameSite?: string;
|
|
182
|
-
/** @deprecated set this option in `cookie.attributes` */
|
|
183
|
-
Domain?: string;
|
|
184
|
-
attributes?: {
|
|
185
|
-
Path?: string;
|
|
186
|
-
HttpOnly?: boolean;
|
|
187
|
-
Secure?: boolean;
|
|
188
|
-
SameSite?: string;
|
|
189
|
-
Domain?: string;
|
|
190
|
-
};
|
|
191
|
-
/**
|
|
192
|
-
* The name of the cookie that dbAuth sets
|
|
193
|
-
*
|
|
194
|
-
* %port% will be replaced with the port the api server is running on.
|
|
195
|
-
* If you have multiple RW apps running on the same host, you'll need to
|
|
196
|
-
* make sure they all use unique cookie names
|
|
197
|
-
*/
|
|
198
|
-
name?: string;
|
|
199
|
-
};
|
|
174
|
+
cookie?: DbAuthCookieConfig;
|
|
200
175
|
/**
|
|
201
176
|
* Object containing forgot password options
|
|
202
177
|
*/
|
|
@@ -339,12 +314,12 @@ export declare class DbAuthHandler<TUser extends UserType, TUserAttributes = Rec
|
|
|
339
314
|
_validateOptions(): void;
|
|
340
315
|
_saveChallenge(userId: string | number, value: string | null): Promise<void>;
|
|
341
316
|
_webAuthnCookie(id: string, expires: string): string;
|
|
342
|
-
_sanitizeUser(user: Record<string, unknown>):
|
|
317
|
+
_sanitizeUser(user: Record<string, unknown>): Record<string, unknown>;
|
|
343
318
|
_decodeEvent(): void;
|
|
344
319
|
_cookieAttributes({ expires, options, }: {
|
|
345
320
|
expires?: 'now' | string;
|
|
346
321
|
options?: DbAuthHandlerOptions['cookie'];
|
|
347
|
-
}):
|
|
322
|
+
}): string[];
|
|
348
323
|
_createAuthProviderCookieString(): string;
|
|
349
324
|
_createSessionCookieString<TIdType = any>(data: DbAuthSession<TIdType>, csrfToken: string): string;
|
|
350
325
|
_findUserByToken(token: string): Promise<any>;
|
|
@@ -355,9 +330,7 @@ export declare class DbAuthHandler<TUser extends UserType, TUserAttributes = Rec
|
|
|
355
330
|
_createUser(): Promise<any>;
|
|
356
331
|
_getAuthMethod(): Promise<AuthMethodNames>;
|
|
357
332
|
_validateField(name: string, value: string | undefined): value is string;
|
|
358
|
-
_loginResponse(user: Record<string, any>, statusCode?: number): [{
|
|
359
|
-
id: string;
|
|
360
|
-
}, Headers, {
|
|
333
|
+
_loginResponse(user: Record<string, any>, statusCode?: number): [Record<string, any>, Headers, {
|
|
361
334
|
statusCode: number;
|
|
362
335
|
}];
|
|
363
336
|
_logoutResponse(response?: Record<string, unknown>): AuthMethodOutput;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DbAuthHandler.d.ts","sourceRoot":"","sources":["../src/DbAuthHandler.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"DbAuthHandler.d.ts","sourceRoot":"","sources":["../src/DbAuthHandler.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,0BAA0B,EAG1B,wBAAwB,EAKzB,MAAM,wBAAwB,CAAA;AAC/B,OAAO,KAAK,EAAE,oBAAoB,EAAE,OAAO,IAAI,aAAa,EAAE,MAAM,YAAY,CAAA;AAIhF,OAAO,KAAK,EAAE,UAAU,EAAE,WAAW,EAAE,cAAc,EAAE,MAAM,cAAc,CAAA;AAyB3E,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAA;AAetD,UAAU,iBAAiB,CAAC,eAAe,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;IACnE;;;OAGG;IACH,OAAO,CAAC,EAAE,OAAO,CAAA;IACjB;;;;;;;OAOG;IACH,OAAO,EAAE,CAAC,oBAAoB,EAAE,oBAAoB,CAAC,eAAe,CAAC,KAAK,GAAG,CAAA;IAE7E;;;OAGG;IACH,kBAAkB,CAAC,EAAE,CAAC,QAAQ,EAAE,MAAM,KAAK,OAAO,CAAA;IAElD;;OAEG;IACH,MAAM,CAAC,EAAE;QACP,YAAY,CAAC,EAAE,MAAM,CAAA;QACrB,aAAa,CAAC,EAAE,MAAM,CAAA;QACtB,cAAc,CAAC,EAAE,MAAM,CAAA;KACxB,CAAA;IAED;;OAEG;IACH,aAAa,CAAC,EAAE,MAAM,CAAA;CACvB;AAED,UAAU,yB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AAS;IA6CxB,eAAe,CAAC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,QAAQ,EAAE,MAAM;IA6C/D,eAAe;IAqCf,WAAW;IAqCX,cAAc;IAqBpB,cAAc,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,SAAS,GAAG,KAAK,IAAI,MAAM;IAYxE,cAAc,CACZ,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EACzB,UAAU,SAAM,GACf,CAAC,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAAE,OAAO,EAAE;QAAE,UAAU,EAAE,MAAM,CAAA;KAAE,CAAC;IASzD,eAAe,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,gBAAgB;IAIrE,GAAG,CACD,IAAI,EAAE,MAAM,GAAG,OAAO,GAAG,SAAS,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC5D,OAAO,UAAgB,EACvB,OAAO;;KAAsB;;;;;IAW/B,SAAS;;;IAMT,WAAW,CAAC,OAAO,EAAE,MAAM;;;;;IAQ3B,UAAU,CAAC,OAAO,EAAE,MAAM;;;;;IAQ1B,4BAA4B,CAC1B,QAAQ,EAAE,MAAM,EAChB,uBAAuB,EAAE,MAAM,GAAG,SAAS;;;;;;;;CAgB9C"}
|
package/dist/DbAuthHandler.js
CHANGED
|
@@ -13,9 +13,18 @@ import {
|
|
|
13
13
|
resolveRequestHost,
|
|
14
14
|
resolveRequestProtocol
|
|
15
15
|
} from "./originValidation.js";
|
|
16
|
+
import {
|
|
17
|
+
buildCookieAttributes,
|
|
18
|
+
createAuthProviderCookieString,
|
|
19
|
+
createCsrfToken,
|
|
20
|
+
createExpiresAtDate,
|
|
21
|
+
createLoginResponse,
|
|
22
|
+
createSessionCookieString,
|
|
23
|
+
DEFAULT_ALLOWED_USER_FIELDS,
|
|
24
|
+
sanitizeUser
|
|
25
|
+
} from "./session.js";
|
|
16
26
|
import {
|
|
17
27
|
decryptSession,
|
|
18
|
-
encryptSession,
|
|
19
28
|
extractCookie,
|
|
20
29
|
extractHashingOptions,
|
|
21
30
|
generateCookieName,
|
|
@@ -27,7 +36,6 @@ import {
|
|
|
27
36
|
legacyHashPassword,
|
|
28
37
|
webAuthnSession
|
|
29
38
|
} from "./shared.js";
|
|
30
|
-
const DEFAULT_ALLOWED_USER_FIELDS = ["id", "email"];
|
|
31
39
|
class DbAuthHandler {
|
|
32
40
|
event;
|
|
33
41
|
_normalizedRequest;
|
|
@@ -92,7 +100,7 @@ class DbAuthHandler {
|
|
|
92
100
|
}
|
|
93
101
|
// generate a new token (standard UUID)
|
|
94
102
|
static get CSRF_TOKEN() {
|
|
95
|
-
return
|
|
103
|
+
return createCsrfToken();
|
|
96
104
|
}
|
|
97
105
|
static get AVAILABLE_WEBAUTHN_TRANSPORTS() {
|
|
98
106
|
return ["usb", "ble", "nfc", "internal"];
|
|
@@ -135,11 +143,9 @@ class DbAuthHandler {
|
|
|
135
143
|
this.dbCredentialAccessor = this.options.credentialModelAccessor ? this.db[this.options.credentialModelAccessor] : null;
|
|
136
144
|
this.hasInvalidSession = false;
|
|
137
145
|
this.allowedUserFields = this.options.allowedUserFields || DEFAULT_ALLOWED_USER_FIELDS;
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
sessionExpiresAt.getSeconds() + this.options.login.expires
|
|
146
|
+
this.sessionExpiresDate = createExpiresAtDate(
|
|
147
|
+
this.options.login.expires
|
|
141
148
|
);
|
|
142
|
-
this.sessionExpiresDate = sessionExpiresAt.toUTCString();
|
|
143
149
|
const webAuthnExpiresAt = /* @__PURE__ */ new Date();
|
|
144
150
|
webAuthnExpiresAt.setSeconds(
|
|
145
151
|
webAuthnExpiresAt.getSeconds() + (this.options?.webAuthn?.expires || 0)
|
|
@@ -442,9 +448,9 @@ class DbAuthHandler {
|
|
|
442
448
|
expectedChallenge: user[this.options.authFields.challenge],
|
|
443
449
|
expectedOrigin: webAuthnOptions.origin,
|
|
444
450
|
expectedRPID: webAuthnOptions.domain,
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
451
|
+
credential: {
|
|
452
|
+
id: credential[webAuthnOptions.credentialFields.id],
|
|
453
|
+
publicKey: credential[webAuthnOptions.credentialFields.publicKey],
|
|
448
454
|
counter: credential[webAuthnOptions.credentialFields.counter],
|
|
449
455
|
transports: credential[webAuthnOptions.credentialFields.transports] ? JSON.parse(
|
|
450
456
|
credential[webAuthnOptions.credentialFields.transports]
|
|
@@ -586,7 +592,11 @@ class DbAuthHandler {
|
|
|
586
592
|
if (!verified || !registrationInfo) {
|
|
587
593
|
throw new DbAuthError.WebAuthnError("Registration failed");
|
|
588
594
|
}
|
|
589
|
-
const {
|
|
595
|
+
const {
|
|
596
|
+
id: credentialID,
|
|
597
|
+
publicKey: credentialPublicKey,
|
|
598
|
+
counter
|
|
599
|
+
} = registrationInfo.credential;
|
|
590
600
|
const existingDevice = await this.dbCredentialAccessor.findFirst({
|
|
591
601
|
where: {
|
|
592
602
|
[this.options.webAuthn.credentialFields.id]: credentialID,
|
|
@@ -665,13 +675,7 @@ class DbAuthHandler {
|
|
|
665
675
|
// removes any fields not explicitly allowed to be sent to the client before
|
|
666
676
|
// sending a response over the wire
|
|
667
677
|
_sanitizeUser(user) {
|
|
668
|
-
|
|
669
|
-
Object.keys(sanitized).forEach((key) => {
|
|
670
|
-
if (!this.allowedUserFields.includes(key)) {
|
|
671
|
-
delete sanitized[key];
|
|
672
|
-
}
|
|
673
|
-
});
|
|
674
|
-
return sanitized;
|
|
678
|
+
return sanitizeUser(user, this.allowedUserFields);
|
|
675
679
|
}
|
|
676
680
|
// Converts LambdaEvent or FetchRequest to
|
|
677
681
|
_decodeEvent() {
|
|
@@ -684,41 +688,27 @@ class DbAuthHandler {
|
|
|
684
688
|
expires = "now",
|
|
685
689
|
options = {}
|
|
686
690
|
}) {
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
const meta = Object.keys(cookieOptions).map((key) => {
|
|
693
|
-
const optionValue = cookieOptions[key];
|
|
694
|
-
if (optionValue === true) {
|
|
695
|
-
return key;
|
|
696
|
-
} else if (optionValue === false) {
|
|
697
|
-
return null;
|
|
698
|
-
} else {
|
|
699
|
-
return `${key}=${optionValue}`;
|
|
700
|
-
}
|
|
701
|
-
}).filter((v) => v);
|
|
702
|
-
const expiresAt = expires === "now" ? DbAuthHandler.PAST_EXPIRES_DATE : expires;
|
|
703
|
-
meta.push(`Expires=${expiresAt}`);
|
|
704
|
-
return meta;
|
|
691
|
+
return buildCookieAttributes({
|
|
692
|
+
cookieConfig: this.options.cookie,
|
|
693
|
+
expires,
|
|
694
|
+
overrideAttributes: options
|
|
695
|
+
});
|
|
705
696
|
}
|
|
706
697
|
_createAuthProviderCookieString() {
|
|
707
|
-
return
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
698
|
+
return createAuthProviderCookieString({
|
|
699
|
+
cookieConfig: this.options.cookie,
|
|
700
|
+
expiresAt: this.sessionExpiresDate
|
|
701
|
+
});
|
|
711
702
|
}
|
|
712
703
|
// returns the set-cookie header to be returned in the request (effectively
|
|
713
704
|
// creates the session)
|
|
714
705
|
_createSessionCookieString(data, csrfToken) {
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
return sessionCookieString;
|
|
706
|
+
return createSessionCookieString({
|
|
707
|
+
data,
|
|
708
|
+
csrfToken,
|
|
709
|
+
cookieConfig: this.options.cookie,
|
|
710
|
+
expiresAt: this.sessionExpiresDate
|
|
711
|
+
});
|
|
722
712
|
}
|
|
723
713
|
async _findUserByToken(token) {
|
|
724
714
|
const tokenExpires = /* @__PURE__ */ new Date();
|
|
@@ -901,16 +891,12 @@ class DbAuthHandler {
|
|
|
901
891
|
}
|
|
902
892
|
}
|
|
903
893
|
_loginResponse(user, statusCode = 200) {
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
"set-cookie",
|
|
911
|
-
this._createSessionCookieString(sessionData, csrfToken)
|
|
912
|
-
);
|
|
913
|
-
return [sessionData, headers, { statusCode }];
|
|
894
|
+
return createLoginResponse(user, {
|
|
895
|
+
cookie: this.options.cookie,
|
|
896
|
+
allowedUserFields: this.allowedUserFields,
|
|
897
|
+
expiresAt: this.sessionExpiresDate,
|
|
898
|
+
statusCode
|
|
899
|
+
});
|
|
914
900
|
}
|
|
915
901
|
_logoutResponse(response) {
|
|
916
902
|
return [response ? JSON.stringify(response) : "", this._deleteSessionHeader];
|
package/dist/index.d.ts
CHANGED
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAA;AAClC,OAAO,EAAE,uBAAuB,EAAE,MAAM,aAAa,CAAA;AACrD,cAAc,aAAa,CAAA;AAC3B,OAAO,EAAE,WAAW,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAA;AAC7D,cAAc,uBAAuB,CAAA"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAA;AAClC,OAAO,EAAE,uBAAuB,EAAE,MAAM,aAAa,CAAA;AACrD,cAAc,cAAc,CAAA;AAC5B,cAAc,aAAa,CAAA;AAC3B,OAAO,EAAE,WAAW,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAA;AAC7D,cAAc,uBAAuB,CAAA"}
|
package/dist/index.js
CHANGED
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Cookie attributes that can be set on a dbAuth cookie, either as
|
|
3
|
+
* `cookie.attributes` or (deprecated) directly on `cookie`.
|
|
4
|
+
*/
|
|
5
|
+
export interface DbAuthCookieAttributes {
|
|
6
|
+
Path?: string;
|
|
7
|
+
HttpOnly?: boolean;
|
|
8
|
+
Secure?: boolean;
|
|
9
|
+
SameSite?: string;
|
|
10
|
+
Domain?: string;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Configuration for the cookies dbAuth sets: the session cookie's name, and
|
|
14
|
+
* the attributes applied to every cookie dbAuth writes (the session cookie
|
|
15
|
+
* and the `auth-provider` cookie).
|
|
16
|
+
*/
|
|
17
|
+
export interface DbAuthCookieConfig extends DbAuthCookieAttributes {
|
|
18
|
+
attributes?: DbAuthCookieAttributes;
|
|
19
|
+
/**
|
|
20
|
+
* The name of the cookie that dbAuth sets
|
|
21
|
+
*
|
|
22
|
+
* %port% will be replaced with the port the api server is running on.
|
|
23
|
+
* If you have multiple RW apps running on the same host, you'll need to
|
|
24
|
+
* make sure they all use unique cookie names
|
|
25
|
+
*/
|
|
26
|
+
name?: string;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Returns a UTC date string `expiresInSeconds` seconds in the future. Used as
|
|
30
|
+
* the `Expires` cookie attribute for a session that should stay valid for
|
|
31
|
+
* that long from now.
|
|
32
|
+
*/
|
|
33
|
+
export declare function createExpiresAtDate(expiresInSeconds: number): string;
|
|
34
|
+
/**
|
|
35
|
+
* Generates a new CSRF token (a standard UUID) to pair with a session.
|
|
36
|
+
*/
|
|
37
|
+
export declare function createCsrfToken(): string;
|
|
38
|
+
/**
|
|
39
|
+
* Removes any fields not explicitly allowed to be sent to the client before
|
|
40
|
+
* sending a user record over the wire.
|
|
41
|
+
*/
|
|
42
|
+
export declare function sanitizeUser(user: Record<string, unknown>, allowedUserFields: string[]): Record<string, unknown>;
|
|
43
|
+
/**
|
|
44
|
+
* Builds the Set-Cookie attribute strings (`Path`, `HttpOnly`, `SameSite`,
|
|
45
|
+
* `Secure`, `Domain`, `Expires`) for a dbAuth cookie.
|
|
46
|
+
*
|
|
47
|
+
* Pass `expires: 'now'` (the default) to get the attributes needed to expire
|
|
48
|
+
* the cookie, or a UTC date string (e.g. from `createExpiresAtDate`) to set a
|
|
49
|
+
* future expiration.
|
|
50
|
+
*/
|
|
51
|
+
export declare function buildCookieAttributes({ cookieConfig, expires, overrideAttributes, }: {
|
|
52
|
+
cookieConfig?: DbAuthCookieConfig;
|
|
53
|
+
expires?: 'now' | string;
|
|
54
|
+
overrideAttributes?: DbAuthCookieAttributes;
|
|
55
|
+
}): string[];
|
|
56
|
+
/**
|
|
57
|
+
* Builds the Set-Cookie header string for the `auth-provider` cookie dbAuth
|
|
58
|
+
* sets alongside the session cookie.
|
|
59
|
+
*/
|
|
60
|
+
export declare function createAuthProviderCookieString({ cookieConfig, expiresAt, }: {
|
|
61
|
+
cookieConfig?: DbAuthCookieConfig;
|
|
62
|
+
expiresAt: string;
|
|
63
|
+
}): string;
|
|
64
|
+
/**
|
|
65
|
+
* Builds the Set-Cookie header string for the dbAuth session cookie: the
|
|
66
|
+
* `data;csrfToken` payload, encrypted, under the configured cookie name and
|
|
67
|
+
* attributes.
|
|
68
|
+
*/
|
|
69
|
+
export declare function createSessionCookieString<TIdType = unknown>({ data, csrfToken, cookieConfig, expiresAt, }: {
|
|
70
|
+
data: Record<string, TIdType>;
|
|
71
|
+
csrfToken: string;
|
|
72
|
+
cookieConfig?: DbAuthCookieConfig;
|
|
73
|
+
expiresAt: string;
|
|
74
|
+
}): string;
|
|
75
|
+
/** Fields returned from the user record when none are explicitly allowed */
|
|
76
|
+
export declare const DEFAULT_ALLOWED_USER_FIELDS: string[];
|
|
77
|
+
export interface CreateLoginResponseOptions {
|
|
78
|
+
/**
|
|
79
|
+
* Object containing cookie config options: the cookie name (with %port%
|
|
80
|
+
* support) and the attributes applied to it (`Path`, `HttpOnly`,
|
|
81
|
+
* `SameSite`, `Secure`, `Domain`).
|
|
82
|
+
*/
|
|
83
|
+
cookie?: DbAuthCookieConfig;
|
|
84
|
+
/**
|
|
85
|
+
* The fields that are allowed to be returned from the user record.
|
|
86
|
+
* Defaults to `id` and `email`.
|
|
87
|
+
*/
|
|
88
|
+
allowedUserFields?: string[];
|
|
89
|
+
/**
|
|
90
|
+
* The `Expires` cookie attribute value for the session and `auth-provider`
|
|
91
|
+
* cookies: a UTC date string in the future. Build one with
|
|
92
|
+
* `createExpiresAtDate(expiresInSeconds)`.
|
|
93
|
+
*/
|
|
94
|
+
expiresAt: string;
|
|
95
|
+
/**
|
|
96
|
+
* The HTTP status code to return in the response tuple. Defaults to 200.
|
|
97
|
+
*/
|
|
98
|
+
statusCode?: number;
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Mints a dbAuth session for the given user: a CSRF token, a session cookie
|
|
102
|
+
* (the sanitized user data paired with the CSRF token, encrypted), and the
|
|
103
|
+
* `auth-provider` cookie, in the same `[body, headers, { statusCode }]` shape
|
|
104
|
+
* every dbAuth auth method returns.
|
|
105
|
+
*
|
|
106
|
+
* Callable without a `DbAuthHandler` instance, so any code that has already
|
|
107
|
+
* verified a user's identity — a WebAuthn assertion, an OAuth callback, a
|
|
108
|
+
* magic link — can issue a session the same way the built-in login flow
|
|
109
|
+
* does.
|
|
110
|
+
*/
|
|
111
|
+
export declare function createLoginResponse(user: Record<string, unknown>, options: CreateLoginResponseOptions): [Record<string, unknown>, Headers, {
|
|
112
|
+
statusCode: number;
|
|
113
|
+
}];
|
|
114
|
+
//# sourceMappingURL=session.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"session.d.ts","sourceRoot":"","sources":["../src/session.ts"],"names":[],"mappings":"AAIA;;;GAGG;AACH,MAAM,WAAW,sBAAsB;IACrC,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB,MAAM,CAAC,EAAE,OAAO,CAAA;IAChB,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,MAAM,CAAC,EAAE,MAAM,CAAA;CAChB;AAED;;;;GAIG;AACH,MAAM,W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,0BAA0B;IACzC;;;;OAIG;IACH,MAAM,CAAC,EAAE,kBAAkB,CAAA;IAC3B;;;OAGG;IACH,iBAAiB,CAAC,EAAE,MAAM,EAAE,CAAA;IAC5B;;;;OAIG;IACH,SAAS,EAAE,MAAM,CAAA;IACjB;;OAEG;IACH,UAAU,CAAC,EAAE,MAAM,CAAA;CACpB;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,mBAAmB,CACjC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC7B,OAAO,EAAE,0BAA0B,GAClC,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,OAAO,EAAE;IAAE,UAAU,EAAE,MAAM,CAAA;CAAE,CAAC,CA+B5D"}
|
package/dist/session.js
ADDED
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import { v4 as uuidv4 } from "uuid";
|
|
2
|
+
import { encryptSession, generateCookieName } from "./shared.js";
|
|
3
|
+
const PAST_EXPIRES_DATE = (/* @__PURE__ */ new Date(
|
|
4
|
+
"1970-01-01T00:00:00.000+00:00"
|
|
5
|
+
)).toUTCString();
|
|
6
|
+
function createExpiresAtDate(expiresInSeconds) {
|
|
7
|
+
const expiresAt = /* @__PURE__ */ new Date();
|
|
8
|
+
expiresAt.setSeconds(expiresAt.getSeconds() + expiresInSeconds);
|
|
9
|
+
return expiresAt.toUTCString();
|
|
10
|
+
}
|
|
11
|
+
function createCsrfToken() {
|
|
12
|
+
return uuidv4();
|
|
13
|
+
}
|
|
14
|
+
function sanitizeUser(user, allowedUserFields) {
|
|
15
|
+
const sanitized = JSON.parse(JSON.stringify(user));
|
|
16
|
+
Object.keys(sanitized).forEach((key) => {
|
|
17
|
+
if (!allowedUserFields.includes(key)) {
|
|
18
|
+
delete sanitized[key];
|
|
19
|
+
}
|
|
20
|
+
});
|
|
21
|
+
return sanitized;
|
|
22
|
+
}
|
|
23
|
+
function buildCookieAttributes({
|
|
24
|
+
cookieConfig,
|
|
25
|
+
expires = "now",
|
|
26
|
+
overrideAttributes = {}
|
|
27
|
+
}) {
|
|
28
|
+
const userCookieAttributes = cookieConfig?.attributes ? { ...cookieConfig.attributes } : { ...cookieConfig };
|
|
29
|
+
if (!cookieConfig?.attributes) {
|
|
30
|
+
delete userCookieAttributes.name;
|
|
31
|
+
}
|
|
32
|
+
const cookieOptions = { ...userCookieAttributes, ...overrideAttributes };
|
|
33
|
+
const meta = Object.keys(cookieOptions).map((key) => {
|
|
34
|
+
const optionValue = cookieOptions[key];
|
|
35
|
+
if (optionValue === true) {
|
|
36
|
+
return key;
|
|
37
|
+
} else if (optionValue === false) {
|
|
38
|
+
return null;
|
|
39
|
+
} else {
|
|
40
|
+
return `${key}=${optionValue}`;
|
|
41
|
+
}
|
|
42
|
+
}).filter((v) => v !== null);
|
|
43
|
+
const expiresAt = expires === "now" ? PAST_EXPIRES_DATE : expires;
|
|
44
|
+
meta.push(`Expires=${expiresAt}`);
|
|
45
|
+
return meta;
|
|
46
|
+
}
|
|
47
|
+
function createAuthProviderCookieString({
|
|
48
|
+
cookieConfig,
|
|
49
|
+
expiresAt
|
|
50
|
+
}) {
|
|
51
|
+
return [
|
|
52
|
+
`auth-provider=dbAuth`,
|
|
53
|
+
...buildCookieAttributes({ cookieConfig, expires: expiresAt })
|
|
54
|
+
].join(";");
|
|
55
|
+
}
|
|
56
|
+
function createSessionCookieString({
|
|
57
|
+
data,
|
|
58
|
+
csrfToken,
|
|
59
|
+
cookieConfig,
|
|
60
|
+
expiresAt
|
|
61
|
+
}) {
|
|
62
|
+
const session = JSON.stringify(data) + ";" + csrfToken;
|
|
63
|
+
const encrypted = encryptSession(session);
|
|
64
|
+
return [
|
|
65
|
+
`${generateCookieName(cookieConfig?.name)}=${encrypted}`,
|
|
66
|
+
...buildCookieAttributes({ cookieConfig, expires: expiresAt })
|
|
67
|
+
].join(";");
|
|
68
|
+
}
|
|
69
|
+
const DEFAULT_ALLOWED_USER_FIELDS = ["id", "email"];
|
|
70
|
+
function createLoginResponse(user, options) {
|
|
71
|
+
const allowedUserFields = options.allowedUserFields ?? DEFAULT_ALLOWED_USER_FIELDS;
|
|
72
|
+
const sessionData = sanitizeUser(user, allowedUserFields);
|
|
73
|
+
const csrfToken = createCsrfToken();
|
|
74
|
+
const headers = new Headers();
|
|
75
|
+
headers.append("csrf-token", csrfToken);
|
|
76
|
+
headers.append(
|
|
77
|
+
"set-cookie",
|
|
78
|
+
createAuthProviderCookieString({
|
|
79
|
+
cookieConfig: options.cookie,
|
|
80
|
+
expiresAt: options.expiresAt
|
|
81
|
+
})
|
|
82
|
+
);
|
|
83
|
+
headers.append(
|
|
84
|
+
"set-cookie",
|
|
85
|
+
createSessionCookieString({
|
|
86
|
+
data: sessionData,
|
|
87
|
+
csrfToken,
|
|
88
|
+
cookieConfig: options.cookie,
|
|
89
|
+
expiresAt: options.expiresAt
|
|
90
|
+
})
|
|
91
|
+
);
|
|
92
|
+
return [sessionData, headers, { statusCode: options.statusCode ?? 200 }];
|
|
93
|
+
}
|
|
94
|
+
export {
|
|
95
|
+
DEFAULT_ALLOWED_USER_FIELDS,
|
|
96
|
+
buildCookieAttributes,
|
|
97
|
+
createAuthProviderCookieString,
|
|
98
|
+
createCsrfToken,
|
|
99
|
+
createExpiresAtDate,
|
|
100
|
+
createLoginResponse,
|
|
101
|
+
createSessionCookieString,
|
|
102
|
+
sanitizeUser
|
|
103
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cedarjs/auth-dbauth-api",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "8.0.0-canary.3263",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "git+https://github.com/cedarjs/cedar.git",
|
|
@@ -57,15 +57,14 @@
|
|
|
57
57
|
"test:watch": "vitest watch"
|
|
58
58
|
},
|
|
59
59
|
"dependencies": {
|
|
60
|
-
"@cedarjs/project-config": "
|
|
60
|
+
"@cedarjs/project-config": "8.0.0-canary.3263",
|
|
61
61
|
"md5": "2.3.0",
|
|
62
62
|
"uuid": "11.1.1"
|
|
63
63
|
},
|
|
64
64
|
"devDependencies": {
|
|
65
|
-
"@cedarjs/api": "
|
|
66
|
-
"@cedarjs/framework-tools": "
|
|
67
|
-
"@simplewebauthn/server": "
|
|
68
|
-
"@simplewebauthn/types": "10.0.0",
|
|
65
|
+
"@cedarjs/api": "8.0.0-canary.3263",
|
|
66
|
+
"@cedarjs/framework-tools": "8.0.0-canary.3263",
|
|
67
|
+
"@simplewebauthn/server": "13.3.3",
|
|
69
68
|
"@types/aws-lambda": "8.10.163",
|
|
70
69
|
"@types/md5": "2.3.6",
|
|
71
70
|
"concurrently": "9.2.4",
|
|
@@ -73,6 +72,14 @@
|
|
|
73
72
|
"typescript": "5.9.3",
|
|
74
73
|
"vitest": "4.1.11"
|
|
75
74
|
},
|
|
75
|
+
"peerDependencies": {
|
|
76
|
+
"@simplewebauthn/server": "^13.0.0"
|
|
77
|
+
},
|
|
78
|
+
"peerDependenciesMeta": {
|
|
79
|
+
"@simplewebauthn/server": {
|
|
80
|
+
"optional": true
|
|
81
|
+
}
|
|
82
|
+
},
|
|
76
83
|
"engines": {
|
|
77
84
|
"node": ">=24"
|
|
78
85
|
},
|