@cedarjs/auth-dbauth-api 7.0.0-canary.3260 → 7.0.0-rc.127
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 +33 -6
- package/dist/DbAuthHandler.d.ts.map +1 -1
- package/dist/DbAuthHandler.js +57 -43
- package/dist/index.d.ts +0 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +0 -1
- package/package.json +6 -13
- package/dist/session.d.ts +0 -114
- package/dist/session.d.ts.map +0 -1
- package/dist/session.js +0 -103
package/dist/DbAuthHandler.d.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import type { AuthenticationResponseJSON, RegistrationResponseJSON } from '@simplewebauthn/
|
|
1
|
+
import type { AuthenticationResponseJSON, RegistrationResponseJSON } from '@simplewebauthn/types';
|
|
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';
|
|
5
4
|
interface SignupFlowOptions<TUserAttributes = Record<string, unknown>> {
|
|
6
5
|
/**
|
|
7
6
|
* Allow users to sign up. Defaults to true.
|
|
@@ -171,7 +170,33 @@ export interface DbAuthHandlerOptions<TUser = UserType, TUserAttributes = Record
|
|
|
171
170
|
/**
|
|
172
171
|
* Object containing cookie config options
|
|
173
172
|
*/
|
|
174
|
-
cookie?:
|
|
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
|
+
};
|
|
175
200
|
/**
|
|
176
201
|
* Object containing forgot password options
|
|
177
202
|
*/
|
|
@@ -314,12 +339,12 @@ export declare class DbAuthHandler<TUser extends UserType, TUserAttributes = Rec
|
|
|
314
339
|
_validateOptions(): void;
|
|
315
340
|
_saveChallenge(userId: string | number, value: string | null): Promise<void>;
|
|
316
341
|
_webAuthnCookie(id: string, expires: string): string;
|
|
317
|
-
_sanitizeUser(user: Record<string, unknown>):
|
|
342
|
+
_sanitizeUser(user: Record<string, unknown>): any;
|
|
318
343
|
_decodeEvent(): void;
|
|
319
344
|
_cookieAttributes({ expires, options, }: {
|
|
320
345
|
expires?: 'now' | string;
|
|
321
346
|
options?: DbAuthHandlerOptions['cookie'];
|
|
322
|
-
}): string[];
|
|
347
|
+
}): (string | null)[];
|
|
323
348
|
_createAuthProviderCookieString(): string;
|
|
324
349
|
_createSessionCookieString<TIdType = any>(data: DbAuthSession<TIdType>, csrfToken: string): string;
|
|
325
350
|
_findUserByToken(token: string): Promise<any>;
|
|
@@ -330,7 +355,9 @@ export declare class DbAuthHandler<TUser extends UserType, TUserAttributes = Rec
|
|
|
330
355
|
_createUser(): Promise<any>;
|
|
331
356
|
_getAuthMethod(): Promise<AuthMethodNames>;
|
|
332
357
|
_validateField(name: string, value: string | undefined): value is string;
|
|
333
|
-
_loginResponse(user: Record<string, any>, statusCode?: number): [
|
|
358
|
+
_loginResponse(user: Record<string, any>, statusCode?: number): [{
|
|
359
|
+
id: string;
|
|
360
|
+
}, Headers, {
|
|
334
361
|
statusCode: number;
|
|
335
362
|
}];
|
|
336
363
|
_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":"AAQA,OAAO,KAAK,EACV,0BAA0B,EAC1B,wBAAwB,EACzB,MAAM,uBAAuB,CAAA;AAC9B,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;AA8B3E,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,yBAAyB,CAAC,KAAK,GAAG,QAAQ;IAClD;;;OAGG;IACH,OAAO,CAAC,EAAE,OAAO,CAAA;I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Q,EAAE,MAAM,EAChB,uBAAuB,EAAE,MAAM,GAAG,SAAS;;;;;;;;CAgB9C"}
|
package/dist/DbAuthHandler.js
CHANGED
|
@@ -13,18 +13,9 @@ 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";
|
|
26
16
|
import {
|
|
27
17
|
decryptSession,
|
|
18
|
+
encryptSession,
|
|
28
19
|
extractCookie,
|
|
29
20
|
extractHashingOptions,
|
|
30
21
|
generateCookieName,
|
|
@@ -36,6 +27,7 @@ import {
|
|
|
36
27
|
legacyHashPassword,
|
|
37
28
|
webAuthnSession
|
|
38
29
|
} from "./shared.js";
|
|
30
|
+
const DEFAULT_ALLOWED_USER_FIELDS = ["id", "email"];
|
|
39
31
|
class DbAuthHandler {
|
|
40
32
|
event;
|
|
41
33
|
_normalizedRequest;
|
|
@@ -100,7 +92,7 @@ class DbAuthHandler {
|
|
|
100
92
|
}
|
|
101
93
|
// generate a new token (standard UUID)
|
|
102
94
|
static get CSRF_TOKEN() {
|
|
103
|
-
return
|
|
95
|
+
return uuidv4();
|
|
104
96
|
}
|
|
105
97
|
static get AVAILABLE_WEBAUTHN_TRANSPORTS() {
|
|
106
98
|
return ["usb", "ble", "nfc", "internal"];
|
|
@@ -143,9 +135,11 @@ class DbAuthHandler {
|
|
|
143
135
|
this.dbCredentialAccessor = this.options.credentialModelAccessor ? this.db[this.options.credentialModelAccessor] : null;
|
|
144
136
|
this.hasInvalidSession = false;
|
|
145
137
|
this.allowedUserFields = this.options.allowedUserFields || DEFAULT_ALLOWED_USER_FIELDS;
|
|
146
|
-
|
|
147
|
-
|
|
138
|
+
const sessionExpiresAt = /* @__PURE__ */ new Date();
|
|
139
|
+
sessionExpiresAt.setSeconds(
|
|
140
|
+
sessionExpiresAt.getSeconds() + this.options.login.expires
|
|
148
141
|
);
|
|
142
|
+
this.sessionExpiresDate = sessionExpiresAt.toUTCString();
|
|
149
143
|
const webAuthnExpiresAt = /* @__PURE__ */ new Date();
|
|
150
144
|
webAuthnExpiresAt.setSeconds(
|
|
151
145
|
webAuthnExpiresAt.getSeconds() + (this.options?.webAuthn?.expires || 0)
|
|
@@ -448,9 +442,9 @@ class DbAuthHandler {
|
|
|
448
442
|
expectedChallenge: user[this.options.authFields.challenge],
|
|
449
443
|
expectedOrigin: webAuthnOptions.origin,
|
|
450
444
|
expectedRPID: webAuthnOptions.domain,
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
445
|
+
authenticator: {
|
|
446
|
+
credentialID: credential[webAuthnOptions.credentialFields.id],
|
|
447
|
+
credentialPublicKey: credential[webAuthnOptions.credentialFields.publicKey],
|
|
454
448
|
counter: credential[webAuthnOptions.credentialFields.counter],
|
|
455
449
|
transports: credential[webAuthnOptions.credentialFields.transports] ? JSON.parse(
|
|
456
450
|
credential[webAuthnOptions.credentialFields.transports]
|
|
@@ -592,11 +586,7 @@ class DbAuthHandler {
|
|
|
592
586
|
if (!verified || !registrationInfo) {
|
|
593
587
|
throw new DbAuthError.WebAuthnError("Registration failed");
|
|
594
588
|
}
|
|
595
|
-
const {
|
|
596
|
-
id: credentialID,
|
|
597
|
-
publicKey: credentialPublicKey,
|
|
598
|
-
counter
|
|
599
|
-
} = registrationInfo.credential;
|
|
589
|
+
const { credentialPublicKey, credentialID, counter } = registrationInfo;
|
|
600
590
|
const existingDevice = await this.dbCredentialAccessor.findFirst({
|
|
601
591
|
where: {
|
|
602
592
|
[this.options.webAuthn.credentialFields.id]: credentialID,
|
|
@@ -675,7 +665,13 @@ class DbAuthHandler {
|
|
|
675
665
|
// removes any fields not explicitly allowed to be sent to the client before
|
|
676
666
|
// sending a response over the wire
|
|
677
667
|
_sanitizeUser(user) {
|
|
678
|
-
|
|
668
|
+
const sanitized = JSON.parse(JSON.stringify(user));
|
|
669
|
+
Object.keys(sanitized).forEach((key) => {
|
|
670
|
+
if (!this.allowedUserFields.includes(key)) {
|
|
671
|
+
delete sanitized[key];
|
|
672
|
+
}
|
|
673
|
+
});
|
|
674
|
+
return sanitized;
|
|
679
675
|
}
|
|
680
676
|
// Converts LambdaEvent or FetchRequest to
|
|
681
677
|
_decodeEvent() {
|
|
@@ -688,27 +684,41 @@ class DbAuthHandler {
|
|
|
688
684
|
expires = "now",
|
|
689
685
|
options = {}
|
|
690
686
|
}) {
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
}
|
|
687
|
+
const userCookieAttributes = this.options.cookie?.attributes ? { ...this.options.cookie?.attributes } : { ...this.options.cookie };
|
|
688
|
+
if (!this.options.cookie?.attributes) {
|
|
689
|
+
delete userCookieAttributes.name;
|
|
690
|
+
}
|
|
691
|
+
const cookieOptions = { ...userCookieAttributes, ...options };
|
|
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;
|
|
696
705
|
}
|
|
697
706
|
_createAuthProviderCookieString() {
|
|
698
|
-
return
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
707
|
+
return [
|
|
708
|
+
`auth-provider=dbAuth`,
|
|
709
|
+
...this._cookieAttributes({ expires: this.sessionExpiresDate })
|
|
710
|
+
].join(";");
|
|
702
711
|
}
|
|
703
712
|
// returns the set-cookie header to be returned in the request (effectively
|
|
704
713
|
// creates the session)
|
|
705
714
|
_createSessionCookieString(data, csrfToken) {
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
715
|
+
const session = JSON.stringify(data) + ";" + csrfToken;
|
|
716
|
+
const encrypted = encryptSession(session);
|
|
717
|
+
const sessionCookieString = [
|
|
718
|
+
`${generateCookieName(this.options.cookie?.name)}=${encrypted}`,
|
|
719
|
+
...this._cookieAttributes({ expires: this.sessionExpiresDate })
|
|
720
|
+
].join(";");
|
|
721
|
+
return sessionCookieString;
|
|
712
722
|
}
|
|
713
723
|
async _findUserByToken(token) {
|
|
714
724
|
const tokenExpires = /* @__PURE__ */ new Date();
|
|
@@ -891,12 +901,16 @@ class DbAuthHandler {
|
|
|
891
901
|
}
|
|
892
902
|
}
|
|
893
903
|
_loginResponse(user, statusCode = 200) {
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
904
|
+
const sessionData = this._sanitizeUser(user);
|
|
905
|
+
const csrfToken = DbAuthHandler.CSRF_TOKEN;
|
|
906
|
+
const headers = new Headers();
|
|
907
|
+
headers.append("csrf-token", csrfToken);
|
|
908
|
+
headers.append("set-cookie", this._createAuthProviderCookieString());
|
|
909
|
+
headers.append(
|
|
910
|
+
"set-cookie",
|
|
911
|
+
this._createSessionCookieString(sessionData, csrfToken)
|
|
912
|
+
);
|
|
913
|
+
return [sessionData, headers, { statusCode }];
|
|
900
914
|
}
|
|
901
915
|
_logoutResponse(response) {
|
|
902
916
|
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,
|
|
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"}
|
package/dist/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cedarjs/auth-dbauth-api",
|
|
3
|
-
"version": "7.0.0-
|
|
3
|
+
"version": "7.0.0-rc.127",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "git+https://github.com/cedarjs/cedar.git",
|
|
@@ -57,14 +57,15 @@
|
|
|
57
57
|
"test:watch": "vitest watch"
|
|
58
58
|
},
|
|
59
59
|
"dependencies": {
|
|
60
|
-
"@cedarjs/project-config": "7.0.0-
|
|
60
|
+
"@cedarjs/project-config": "7.0.0-rc.127",
|
|
61
61
|
"md5": "2.3.0",
|
|
62
62
|
"uuid": "11.1.1"
|
|
63
63
|
},
|
|
64
64
|
"devDependencies": {
|
|
65
|
-
"@cedarjs/api": "7.0.0-
|
|
66
|
-
"@cedarjs/framework-tools": "7.0.0-
|
|
67
|
-
"@simplewebauthn/server": "
|
|
65
|
+
"@cedarjs/api": "7.0.0-rc.127",
|
|
66
|
+
"@cedarjs/framework-tools": "7.0.0-rc.127",
|
|
67
|
+
"@simplewebauthn/server": "10.0.1",
|
|
68
|
+
"@simplewebauthn/types": "10.0.0",
|
|
68
69
|
"@types/aws-lambda": "8.10.163",
|
|
69
70
|
"@types/md5": "2.3.6",
|
|
70
71
|
"concurrently": "9.2.4",
|
|
@@ -72,14 +73,6 @@
|
|
|
72
73
|
"typescript": "5.9.3",
|
|
73
74
|
"vitest": "4.1.11"
|
|
74
75
|
},
|
|
75
|
-
"peerDependencies": {
|
|
76
|
-
"@simplewebauthn/server": "^13.0.0"
|
|
77
|
-
},
|
|
78
|
-
"peerDependenciesMeta": {
|
|
79
|
-
"@simplewebauthn/server": {
|
|
80
|
-
"optional": true
|
|
81
|
-
}
|
|
82
|
-
},
|
|
83
76
|
"engines": {
|
|
84
77
|
"node": ">=24"
|
|
85
78
|
},
|
package/dist/session.d.ts
DELETED
|
@@ -1,114 +0,0 @@
|
|
|
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
|
package/dist/session.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
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,WAAW,kBAAmB,SAAQ,sBAAsB;IAChE,UAAU,CAAC,EAAE,sBAAsB,CAAA;IACnC;;;;;;OAMG;IACH,IAAI,CAAC,EAAE,MAAM,CAAA;CACd;AAOD;;;;GAIG;AACH,wBAAgB,mBAAmB,CAAC,gBAAgB,EAAE,MAAM,GAAG,MAAM,CAKpE;AAED;;GAEG;AACH,wBAAgB,eAAe,IAAI,MAAM,CAExC;AAED;;;GAGG;AACH,wBAAgB,YAAY,CAC1B,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC7B,iBAAiB,EAAE,MAAM,EAAE,GAC1B,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAUzB;AAED;;;;;;;GAOG;AACH,wBAAgB,qBAAqB,CAAC,EACpC,YAAY,EACZ,OAAe,EACf,kBAAuB,GACxB,EAAE;IACD,YAAY,CAAC,EAAE,kBAAkB,CAAA;IACjC,OAAO,CAAC,EAAE,KAAK,GAAG,MAAM,CAAA;IACxB,kBAAkB,CAAC,EAAE,sBAAsB,CAAA;CAC5C,GAAG,MAAM,EAAE,CAiCX;AAED;;;GAGG;AACH,wBAAgB,8BAA8B,CAAC,EAC7C,YAAY,EACZ,SAAS,GACV,EAAE;IACD,YAAY,CAAC,EAAE,kBAAkB,CAAA;IACjC,SAAS,EAAE,MAAM,CAAA;CAClB,GAAG,MAAM,CAKT;AAED;;;;GAIG;AACH,wBAAgB,yBAAyB,CAAC,OAAO,GAAG,OAAO,EAAE,EAC3D,IAAI,EACJ,SAAS,EACT,YAAY,EACZ,SAAS,GACV,EAAE;IACD,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;IAC7B,SAAS,EAAE,MAAM,CAAA;IACjB,YAAY,CAAC,EAAE,kBAAkB,CAAA;IACjC,SAAS,EAAE,MAAM,CAAA;CAClB,GAAG,MAAM,CAQT;AAED,4EAA4E;AAC5E,eAAO,MAAM,2BAA2B,UAAkB,CAAA;AAE1D,MAAM,WAAW,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
DELETED
|
@@ -1,103 +0,0 @@
|
|
|
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
|
-
};
|