@cedarjs/auth-dbauth-api 7.0.1-next.467 → 7.1.0-rc.34
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 +34 -45
- package/dist/DbAuthHandler.d.ts.map +1 -1
- package/dist/DbAuthHandler.js +57 -135
- package/dist/errors.d.ts +0 -6
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +0 -14
- package/dist/index.d.ts +0 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +0 -1
- package/package.json +9 -16
- 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.
|
|
@@ -97,33 +96,6 @@ interface ResetPasswordFlowOptions<TUser = UserType> {
|
|
|
97
96
|
flowNotEnabled?: string;
|
|
98
97
|
};
|
|
99
98
|
}
|
|
100
|
-
interface ChangePasswordFlowOptions<TUser = UserType> {
|
|
101
|
-
/**
|
|
102
|
-
* Allow logged in users to change their password by providing their current
|
|
103
|
-
* one. Defaults to true.
|
|
104
|
-
* Needs to be explicitly set to false to disable the flow
|
|
105
|
-
*/
|
|
106
|
-
enabled?: boolean;
|
|
107
|
-
/**
|
|
108
|
-
* Invoked after the new password has been saved. This is where you can
|
|
109
|
-
* notify the user that their password was changed. Returning anything
|
|
110
|
-
* truthy keeps the user logged in. Returning anything falsy logs them out.
|
|
111
|
-
*/
|
|
112
|
-
handler: (user: TUser) => boolean | Promise<boolean>;
|
|
113
|
-
/**
|
|
114
|
-
* If `false` (the default) the new password MUST be different from the
|
|
115
|
-
* current one
|
|
116
|
-
*/
|
|
117
|
-
allowReusedPassword?: boolean;
|
|
118
|
-
errors?: {
|
|
119
|
-
currentPasswordRequired?: string;
|
|
120
|
-
newPasswordRequired?: string;
|
|
121
|
-
incorrectCurrentPassword?: string;
|
|
122
|
-
passwordNotSet?: string;
|
|
123
|
-
reusedPassword?: string;
|
|
124
|
-
flowNotEnabled?: string;
|
|
125
|
-
};
|
|
126
|
-
}
|
|
127
99
|
interface WebAuthnFlowOptions {
|
|
128
100
|
enabled: boolean;
|
|
129
101
|
expires: number;
|
|
@@ -195,16 +167,36 @@ export interface DbAuthHandlerOptions<TUser = UserType, TUserAttributes = Record
|
|
|
195
167
|
resetTokenExpiresAt: string;
|
|
196
168
|
challenge?: string;
|
|
197
169
|
};
|
|
198
|
-
/**
|
|
199
|
-
* Object containing change password options
|
|
200
|
-
*/
|
|
201
|
-
changePassword: ChangePasswordFlowOptions<TUser> | {
|
|
202
|
-
enabled: false;
|
|
203
|
-
};
|
|
204
170
|
/**
|
|
205
171
|
* Object containing cookie config options
|
|
206
172
|
*/
|
|
207
|
-
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
|
+
};
|
|
208
200
|
/**
|
|
209
201
|
* Object containing forgot password options
|
|
210
202
|
*/
|
|
@@ -257,13 +249,11 @@ export interface SignupHandlerOptions<TUserAttributes> {
|
|
|
257
249
|
salt: string;
|
|
258
250
|
userAttributes?: TUserAttributes;
|
|
259
251
|
}
|
|
260
|
-
export type AuthMethodNames = '
|
|
252
|
+
export type AuthMethodNames = 'forgotPassword' | 'getToken' | 'login' | 'logout' | 'resetPassword' | 'signup' | 'webAuthnAuthenticate' | 'webAuthnAuthOptions' | 'webAuthnRegOptions' | 'webAuthnRegister' | 'validateResetToken';
|
|
261
253
|
type Params = AuthenticationResponseJSON & RegistrationResponseJSON & {
|
|
262
254
|
username?: string;
|
|
263
255
|
password?: string;
|
|
264
256
|
resetToken?: string;
|
|
265
|
-
currentPassword?: string;
|
|
266
|
-
newPassword?: string;
|
|
267
257
|
method: AuthMethodNames;
|
|
268
258
|
[key: string]: any;
|
|
269
259
|
} & {
|
|
@@ -300,7 +290,6 @@ export declare class DbAuthHandler<TUser extends UserType, TUserAttributes = Rec
|
|
|
300
290
|
get normalizedRequest(): PartialRequest<Params>;
|
|
301
291
|
static get METHODS(): AuthMethodNames[];
|
|
302
292
|
static get VERBS(): {
|
|
303
|
-
changePassword: string;
|
|
304
293
|
forgotPassword: string;
|
|
305
294
|
getToken: string;
|
|
306
295
|
login: string;
|
|
@@ -336,7 +325,6 @@ export declare class DbAuthHandler<TUser extends UserType, TUserAttributes = Rec
|
|
|
336
325
|
}>;
|
|
337
326
|
_requestHost(): string | null;
|
|
338
327
|
_requestProtocol(): string | null;
|
|
339
|
-
changePassword(): Promise<AuthMethodOutput>;
|
|
340
328
|
forgotPassword(): Promise<AuthMethodOutput>;
|
|
341
329
|
getToken(): Promise<AuthMethodOutput>;
|
|
342
330
|
login(): Promise<AuthMethodOutput>;
|
|
@@ -351,24 +339,25 @@ export declare class DbAuthHandler<TUser extends UserType, TUserAttributes = Rec
|
|
|
351
339
|
_validateOptions(): void;
|
|
352
340
|
_saveChallenge(userId: string | number, value: string | null): Promise<void>;
|
|
353
341
|
_webAuthnCookie(id: string, expires: string): string;
|
|
354
|
-
_sanitizeUser(user: Record<string, unknown>):
|
|
342
|
+
_sanitizeUser(user: Record<string, unknown>): any;
|
|
355
343
|
_decodeEvent(): void;
|
|
356
344
|
_cookieAttributes({ expires, options, }: {
|
|
357
345
|
expires?: 'now' | string;
|
|
358
346
|
options?: DbAuthHandlerOptions['cookie'];
|
|
359
|
-
}): string[];
|
|
347
|
+
}): (string | null)[];
|
|
360
348
|
_createAuthProviderCookieString(): string;
|
|
361
349
|
_createSessionCookieString<TIdType = any>(data: DbAuthSession<TIdType>, csrfToken: string): string;
|
|
362
350
|
_findUserByToken(token: string): Promise<any>;
|
|
363
351
|
_clearResetToken(user: Record<string, unknown>): Promise<void>;
|
|
364
352
|
_verifyUser(username: string | undefined, password: string | undefined): Promise<any>;
|
|
365
353
|
_verifyPassword(user: Record<string, unknown>, password: string): Promise<Record<string, unknown>>;
|
|
366
|
-
_passwordMatches(user: Record<string, unknown>, password: string): boolean;
|
|
367
354
|
_getCurrentUser(): Promise<any>;
|
|
368
355
|
_createUser(): Promise<any>;
|
|
369
356
|
_getAuthMethod(): Promise<AuthMethodNames>;
|
|
370
357
|
_validateField(name: string, value: string | undefined): value is string;
|
|
371
|
-
_loginResponse(user: Record<string, any>, statusCode?: number): [
|
|
358
|
+
_loginResponse(user: Record<string, any>, statusCode?: number): [{
|
|
359
|
+
id: string;
|
|
360
|
+
}, Headers, {
|
|
372
361
|
statusCode: number;
|
|
373
362
|
}];
|
|
374
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;IACjB,OAAO,EAAE,CAAC,IAAI,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,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gB9C"}
|
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;
|
|
@@ -65,7 +57,6 @@ class DbAuthHandler {
|
|
|
65
57
|
// class constant: list of auth methods that are supported
|
|
66
58
|
static get METHODS() {
|
|
67
59
|
return [
|
|
68
|
-
"changePassword",
|
|
69
60
|
"forgotPassword",
|
|
70
61
|
"getToken",
|
|
71
62
|
"login",
|
|
@@ -82,7 +73,6 @@ class DbAuthHandler {
|
|
|
82
73
|
// class constant: maps the auth functions to their required HTTP verb for access
|
|
83
74
|
static get VERBS() {
|
|
84
75
|
return {
|
|
85
|
-
changePassword: "POST",
|
|
86
76
|
forgotPassword: "POST",
|
|
87
77
|
getToken: "GET",
|
|
88
78
|
login: "POST",
|
|
@@ -102,7 +92,7 @@ class DbAuthHandler {
|
|
|
102
92
|
}
|
|
103
93
|
// generate a new token (standard UUID)
|
|
104
94
|
static get CSRF_TOKEN() {
|
|
105
|
-
return
|
|
95
|
+
return uuidv4();
|
|
106
96
|
}
|
|
107
97
|
static get AVAILABLE_WEBAUTHN_TRANSPORTS() {
|
|
108
98
|
return ["usb", "ble", "nfc", "internal"];
|
|
@@ -145,9 +135,11 @@ class DbAuthHandler {
|
|
|
145
135
|
this.dbCredentialAccessor = this.options.credentialModelAccessor ? this.db[this.options.credentialModelAccessor] : null;
|
|
146
136
|
this.hasInvalidSession = false;
|
|
147
137
|
this.allowedUserFields = this.options.allowedUserFields || DEFAULT_ALLOWED_USER_FIELDS;
|
|
148
|
-
|
|
149
|
-
|
|
138
|
+
const sessionExpiresAt = /* @__PURE__ */ new Date();
|
|
139
|
+
sessionExpiresAt.setSeconds(
|
|
140
|
+
sessionExpiresAt.getSeconds() + this.options.login.expires
|
|
150
141
|
);
|
|
142
|
+
this.sessionExpiresDate = sessionExpiresAt.toUTCString();
|
|
151
143
|
const webAuthnExpiresAt = /* @__PURE__ */ new Date();
|
|
152
144
|
webAuthnExpiresAt.setSeconds(
|
|
153
145
|
webAuthnExpiresAt.getSeconds() + (this.options?.webAuthn?.expires || 0)
|
|
@@ -252,83 +244,6 @@ class DbAuthHandler {
|
|
|
252
244
|
isFetchApiRequest(this.event) ? this.event.url : void 0
|
|
253
245
|
);
|
|
254
246
|
}
|
|
255
|
-
async changePassword() {
|
|
256
|
-
const options = this.options.changePassword;
|
|
257
|
-
if (!options || options.enabled === false) {
|
|
258
|
-
throw new DbAuthError.FlowNotEnabledError(
|
|
259
|
-
options?.errors?.flowNotEnabled || `Change password flow is not enabled`
|
|
260
|
-
);
|
|
261
|
-
}
|
|
262
|
-
const sessionUserId = this.session?.[this.options.authFields.id];
|
|
263
|
-
if (!sessionUserId) {
|
|
264
|
-
throw new DbAuthError.NotLoggedInError();
|
|
265
|
-
}
|
|
266
|
-
const { currentPassword, newPassword } = this.normalizedRequest.jsonBody || {};
|
|
267
|
-
if (currentPassword == null || String(currentPassword).trim() === "") {
|
|
268
|
-
throw new DbAuthError.PasswordRequiredError(
|
|
269
|
-
options.errors?.currentPasswordRequired || "Current password is required"
|
|
270
|
-
);
|
|
271
|
-
}
|
|
272
|
-
if (newPassword == null || String(newPassword).trim() === "") {
|
|
273
|
-
throw new DbAuthError.PasswordRequiredError(
|
|
274
|
-
options.errors?.newPasswordRequired || "New password is required"
|
|
275
|
-
);
|
|
276
|
-
}
|
|
277
|
-
;
|
|
278
|
-
this.options.signup.passwordValidation?.(
|
|
279
|
-
newPassword
|
|
280
|
-
);
|
|
281
|
-
let user;
|
|
282
|
-
try {
|
|
283
|
-
user = await this.dbAccessor.findUnique({
|
|
284
|
-
where: { [this.options.authFields.id]: sessionUserId }
|
|
285
|
-
});
|
|
286
|
-
} catch {
|
|
287
|
-
throw new DbAuthError.GenericError();
|
|
288
|
-
}
|
|
289
|
-
if (!user) {
|
|
290
|
-
throw new DbAuthError.UserNotFoundError();
|
|
291
|
-
}
|
|
292
|
-
if (!user[this.options.authFields.hashedPassword]) {
|
|
293
|
-
throw new DbAuthError.PasswordNotSetError(options.errors?.passwordNotSet);
|
|
294
|
-
}
|
|
295
|
-
try {
|
|
296
|
-
await this._verifyPassword(user, currentPassword);
|
|
297
|
-
} catch (e) {
|
|
298
|
-
if (e instanceof DbAuthError.IncorrectPasswordError) {
|
|
299
|
-
throw new DbAuthError.IncorrectPasswordError(
|
|
300
|
-
user[this.options.authFields.username],
|
|
301
|
-
options.errors?.incorrectCurrentPassword || "Current password is incorrect"
|
|
302
|
-
);
|
|
303
|
-
}
|
|
304
|
-
throw e;
|
|
305
|
-
}
|
|
306
|
-
if (!options.allowReusedPassword && this._passwordMatches(user, newPassword)) {
|
|
307
|
-
throw new DbAuthError.ReusedPasswordError(options.errors?.reusedPassword);
|
|
308
|
-
}
|
|
309
|
-
const [hashedPassword, salt] = hashPassword(newPassword);
|
|
310
|
-
try {
|
|
311
|
-
user = await this.dbAccessor.update({
|
|
312
|
-
where: {
|
|
313
|
-
[this.options.authFields.id]: user[this.options.authFields.id]
|
|
314
|
-
},
|
|
315
|
-
data: {
|
|
316
|
-
[this.options.authFields.hashedPassword]: hashedPassword,
|
|
317
|
-
[this.options.authFields.salt]: salt,
|
|
318
|
-
[this.options.authFields.resetToken]: null,
|
|
319
|
-
[this.options.authFields.resetTokenExpiresAt]: null
|
|
320
|
-
}
|
|
321
|
-
});
|
|
322
|
-
} catch {
|
|
323
|
-
throw new DbAuthError.GenericError();
|
|
324
|
-
}
|
|
325
|
-
const response = await options.handler(this._sanitizeUser(user));
|
|
326
|
-
if (response) {
|
|
327
|
-
return this._loginResponse(user);
|
|
328
|
-
} else {
|
|
329
|
-
return this._logoutResponse({});
|
|
330
|
-
}
|
|
331
|
-
}
|
|
332
247
|
async forgotPassword() {
|
|
333
248
|
const { enabled = true } = this.options.forgotPassword;
|
|
334
249
|
if (!enabled) {
|
|
@@ -527,9 +442,9 @@ class DbAuthHandler {
|
|
|
527
442
|
expectedChallenge: user[this.options.authFields.challenge],
|
|
528
443
|
expectedOrigin: webAuthnOptions.origin,
|
|
529
444
|
expectedRPID: webAuthnOptions.domain,
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
445
|
+
authenticator: {
|
|
446
|
+
credentialID: credential[webAuthnOptions.credentialFields.id],
|
|
447
|
+
credentialPublicKey: credential[webAuthnOptions.credentialFields.publicKey],
|
|
533
448
|
counter: credential[webAuthnOptions.credentialFields.counter],
|
|
534
449
|
transports: credential[webAuthnOptions.credentialFields.transports] ? JSON.parse(
|
|
535
450
|
credential[webAuthnOptions.credentialFields.transports]
|
|
@@ -671,11 +586,7 @@ class DbAuthHandler {
|
|
|
671
586
|
if (!verified || !registrationInfo) {
|
|
672
587
|
throw new DbAuthError.WebAuthnError("Registration failed");
|
|
673
588
|
}
|
|
674
|
-
const {
|
|
675
|
-
id: credentialID,
|
|
676
|
-
publicKey: credentialPublicKey,
|
|
677
|
-
counter
|
|
678
|
-
} = registrationInfo.credential;
|
|
589
|
+
const { credentialPublicKey, credentialID, counter } = registrationInfo;
|
|
679
590
|
const existingDevice = await this.dbCredentialAccessor.findFirst({
|
|
680
591
|
where: {
|
|
681
592
|
[this.options.webAuthn.credentialFields.id]: credentialID,
|
|
@@ -723,9 +634,6 @@ class DbAuthHandler {
|
|
|
723
634
|
if (this.options?.resetPassword?.enabled !== false && !this.options?.resetPassword?.handler) {
|
|
724
635
|
throw new DbAuthError.NoResetPasswordHandlerError();
|
|
725
636
|
}
|
|
726
|
-
if (this.options?.changePassword && this.options.changePassword.enabled !== false && !this.options.changePassword.handler) {
|
|
727
|
-
throw new DbAuthError.NoChangePasswordHandlerError();
|
|
728
|
-
}
|
|
729
637
|
if (this.options?.credentialModelAccessor && !this.options?.webAuthn || this.options?.webAuthn && !this.options?.credentialModelAccessor) {
|
|
730
638
|
throw new DbAuthError.NoWebAuthnConfigError();
|
|
731
639
|
}
|
|
@@ -757,7 +665,13 @@ class DbAuthHandler {
|
|
|
757
665
|
// removes any fields not explicitly allowed to be sent to the client before
|
|
758
666
|
// sending a response over the wire
|
|
759
667
|
_sanitizeUser(user) {
|
|
760
|
-
|
|
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;
|
|
761
675
|
}
|
|
762
676
|
// Converts LambdaEvent or FetchRequest to
|
|
763
677
|
_decodeEvent() {
|
|
@@ -770,27 +684,41 @@ class DbAuthHandler {
|
|
|
770
684
|
expires = "now",
|
|
771
685
|
options = {}
|
|
772
686
|
}) {
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
}
|
|
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;
|
|
778
705
|
}
|
|
779
706
|
_createAuthProviderCookieString() {
|
|
780
|
-
return
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
707
|
+
return [
|
|
708
|
+
`auth-provider=dbAuth`,
|
|
709
|
+
...this._cookieAttributes({ expires: this.sessionExpiresDate })
|
|
710
|
+
].join(";");
|
|
784
711
|
}
|
|
785
712
|
// returns the set-cookie header to be returned in the request (effectively
|
|
786
713
|
// creates the session)
|
|
787
714
|
_createSessionCookieString(data, csrfToken) {
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
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;
|
|
794
722
|
}
|
|
795
723
|
async _findUserByToken(token) {
|
|
796
724
|
const tokenExpires = /* @__PURE__ */ new Date();
|
|
@@ -895,16 +823,6 @@ class DbAuthHandler {
|
|
|
895
823
|
this.options.login?.errors?.incorrectPassword
|
|
896
824
|
);
|
|
897
825
|
}
|
|
898
|
-
// compares a plain text password with the user's stored hash, using the
|
|
899
|
-
// same algorithm and options the stored hash was created with. Unlike
|
|
900
|
-
// `_verifyPassword` this has no side effects and does not throw
|
|
901
|
-
_passwordMatches(user, password) {
|
|
902
|
-
const storedHash = user[this.options.authFields.hashedPassword];
|
|
903
|
-
const salt = user[this.options.authFields.salt];
|
|
904
|
-
const options = extractHashingOptions(storedHash);
|
|
905
|
-
const [hashedPassword] = Object.keys(options).length ? hashPassword(password, { salt, options }) : legacyHashPassword(password, salt);
|
|
906
|
-
return hashedPassword === storedHash;
|
|
907
|
-
}
|
|
908
826
|
// gets the user from the database and returns only its ID
|
|
909
827
|
async _getCurrentUser() {
|
|
910
828
|
if (!this.session?.[this.options.authFields.id]) {
|
|
@@ -983,12 +901,16 @@ class DbAuthHandler {
|
|
|
983
901
|
}
|
|
984
902
|
}
|
|
985
903
|
_loginResponse(user, statusCode = 200) {
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
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 }];
|
|
992
914
|
}
|
|
993
915
|
_logoutResponse(response) {
|
|
994
916
|
return [response ? JSON.stringify(response) : "", this._deleteSessionHeader];
|
package/dist/errors.d.ts
CHANGED
|
@@ -16,9 +16,6 @@ export declare class NoForgotPasswordHandlerError extends Error {
|
|
|
16
16
|
export declare class NoResetPasswordHandlerError extends Error {
|
|
17
17
|
constructor();
|
|
18
18
|
}
|
|
19
|
-
export declare class NoChangePasswordHandlerError extends Error {
|
|
20
|
-
constructor();
|
|
21
|
-
}
|
|
22
19
|
export declare class NoWebAuthnConfigError extends Error {
|
|
23
20
|
constructor();
|
|
24
21
|
}
|
|
@@ -82,9 +79,6 @@ export declare class ResetTokenRequiredError extends Error {
|
|
|
82
79
|
export declare class ReusedPasswordError extends Error {
|
|
83
80
|
constructor(message?: string);
|
|
84
81
|
}
|
|
85
|
-
export declare class PasswordNotSetError extends Error {
|
|
86
|
-
constructor(message?: string);
|
|
87
|
-
}
|
|
88
82
|
export declare class PasswordValidationError extends Error {
|
|
89
83
|
constructor(message?: string);
|
|
90
84
|
}
|
package/dist/errors.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA,qBAAa,oBAAqB,SAAQ,KAAK;;CAO9C;AAED,qBAAa,wBAAyB,SAAQ,KAAK;;CAKlD;AAED,qBAAa,mBAAoB,SAAQ,KAAK;;CAK7C;AAED,qBAAa,oBAAqB,SAAQ,KAAK;;CAK9C;AAED,qBAAa,4BAA6B,SAAQ,KAAK;;CAKtD;AAED,qBAAa,2BAA4B,SAAQ,KAAK;;CAKrD;AAED,qBAAa,
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA,qBAAa,oBAAqB,SAAQ,KAAK;;CAO9C;AAED,qBAAa,wBAAyB,SAAQ,KAAK;;CAKlD;AAED,qBAAa,mBAAoB,SAAQ,KAAK;;CAK7C;AAED,qBAAa,oBAAqB,SAAQ,KAAK;;CAK9C;AAED,qBAAa,4BAA6B,SAAQ,KAAK;;CAKtD;AAED,qBAAa,2BAA4B,SAAQ,KAAK;;CAKrD;AAED,qBAAa,qBAAsB,SAAQ,KAAK;;CAO/C;AAED,qBAAa,0BAA2B,SAAQ,KAAK;;CAOpD;AAED,qBAAa,sBAAuB,SAAQ,KAAK;gBACnC,IAAI,EAAE,MAAM;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K;gBAChC,OAAO,SAA+B;CAInD;AAED,qBAAa,uBAAwB,SAAQ,KAAK;gBACpC,OAAO,SAAwB;CAI5C;AAED,qBAAa,YAAa,SAAQ,KAAK;gBACzB,OAAO,SAA2B;CAI/C;AAED,qBAAa,aAAc,SAAQ,KAAK;gBAC1B,OAAO,SAAmB;CAIvC;AAED,qBAAa,sBAAuB,SAAQ,aAAa;gBAErD,OAAO,SAAyD;CAKnE"}
|
package/dist/errors.js
CHANGED
|
@@ -36,12 +36,6 @@ class NoResetPasswordHandlerError extends Error {
|
|
|
36
36
|
this.name = "NoResetPasswordHandlerError";
|
|
37
37
|
}
|
|
38
38
|
}
|
|
39
|
-
class NoChangePasswordHandlerError extends Error {
|
|
40
|
-
constructor() {
|
|
41
|
-
super("dbAuth requires a change password handler in order to notify user");
|
|
42
|
-
this.name = "NoChangePasswordHandlerError";
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
39
|
class NoWebAuthnConfigError extends Error {
|
|
46
40
|
constructor() {
|
|
47
41
|
super(
|
|
@@ -178,12 +172,6 @@ class ReusedPasswordError extends Error {
|
|
|
178
172
|
this.name = "ReusedPasswordError";
|
|
179
173
|
}
|
|
180
174
|
}
|
|
181
|
-
class PasswordNotSetError extends Error {
|
|
182
|
-
constructor(message = 'This account does not have a password. Use "Forgot password" to set one') {
|
|
183
|
-
super(message);
|
|
184
|
-
this.name = "PasswordNotSetError";
|
|
185
|
-
}
|
|
186
|
-
}
|
|
187
175
|
class PasswordValidationError extends Error {
|
|
188
176
|
constructor(message = "Password is invalid") {
|
|
189
177
|
super(message);
|
|
@@ -215,7 +203,6 @@ export {
|
|
|
215
203
|
GenericError,
|
|
216
204
|
IncorrectPasswordError,
|
|
217
205
|
MissingWebAuthnConfigError,
|
|
218
|
-
NoChangePasswordHandlerError,
|
|
219
206
|
NoForgotPasswordHandlerError,
|
|
220
207
|
NoLoginHandlerError,
|
|
221
208
|
NoResetPasswordHandlerError,
|
|
@@ -226,7 +213,6 @@ export {
|
|
|
226
213
|
NoWebAuthnConfigError,
|
|
227
214
|
NoWebAuthnSessionError,
|
|
228
215
|
NotLoggedInError,
|
|
229
|
-
PasswordNotSetError,
|
|
230
216
|
PasswordRequiredError,
|
|
231
217
|
PasswordValidationError,
|
|
232
218
|
ResetTokenExpiredError,
|
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
|
|
3
|
+
"version": "7.1.0-rc.34",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "git+https://github.com/cedarjs/cedar.git",
|
|
@@ -57,29 +57,22 @@
|
|
|
57
57
|
"test:watch": "vitest watch"
|
|
58
58
|
},
|
|
59
59
|
"dependencies": {
|
|
60
|
-
"@cedarjs/project-config": "7.0
|
|
60
|
+
"@cedarjs/project-config": "7.1.0-rc.34",
|
|
61
61
|
"md5": "2.3.0",
|
|
62
62
|
"uuid": "11.1.1"
|
|
63
63
|
},
|
|
64
64
|
"devDependencies": {
|
|
65
|
-
"@cedarjs/api": "7.0
|
|
66
|
-
"@cedarjs/framework-tools": "7.0
|
|
67
|
-
"@simplewebauthn/server": "
|
|
68
|
-
"@types
|
|
65
|
+
"@cedarjs/api": "7.1.0-rc.34",
|
|
66
|
+
"@cedarjs/framework-tools": "7.1.0-rc.34",
|
|
67
|
+
"@simplewebauthn/server": "10.0.1",
|
|
68
|
+
"@simplewebauthn/types": "10.0.0",
|
|
69
|
+
"@types/aws-lambda": "8.10.163",
|
|
69
70
|
"@types/md5": "2.3.6",
|
|
70
|
-
"concurrently": "9.2.
|
|
71
|
-
"publint": "0.3.
|
|
71
|
+
"concurrently": "9.2.4",
|
|
72
|
+
"publint": "0.3.24",
|
|
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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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
|
-
};
|