auth-vir 2.3.8 → 2.3.9
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.
|
@@ -144,9 +144,15 @@ export declare class BackendAuthClient<DatabaseUser extends AnyObject, UserId ex
|
|
|
144
144
|
headers: IncomingHttpHeaders;
|
|
145
145
|
}): Promise<DatabaseUser | undefined>;
|
|
146
146
|
/** Securely extract a user from their request headers. */
|
|
147
|
-
getSecureUser({ requestHeaders, isSignUpCookie, }: {
|
|
147
|
+
getSecureUser({ requestHeaders, isSignUpCookie, allowUserAuthRefresh, }: {
|
|
148
148
|
requestHeaders: IncomingHttpHeaders;
|
|
149
|
-
isSignUpCookie
|
|
149
|
+
isSignUpCookie: boolean;
|
|
150
|
+
/**
|
|
151
|
+
* If true, this method will generate headers to refresh the user's auth session. This
|
|
152
|
+
* should likely only be done with a specific endpoint, like whatever endpoint you trigger
|
|
153
|
+
* with the frontend auth client's `checkUser.performCheck` callback.
|
|
154
|
+
*/
|
|
155
|
+
allowUserAuthRefresh: boolean;
|
|
150
156
|
}): Promise<GetUserResult<DatabaseUser> | undefined>;
|
|
151
157
|
/**
|
|
152
158
|
* Get all the JWT params used when creating the auth cookie, in case you need them for
|
|
@@ -169,7 +175,13 @@ export declare class BackendAuthClient<DatabaseUser extends AnyObject, UserId ex
|
|
|
169
175
|
/** Combines `.getInsecureUser()` and `.getSecureUser()` into one method. */
|
|
170
176
|
getInsecureOrSecureUser(params: {
|
|
171
177
|
requestHeaders: IncomingHttpHeaders;
|
|
172
|
-
isSignUpCookie
|
|
178
|
+
isSignUpCookie: boolean;
|
|
179
|
+
/**
|
|
180
|
+
* If true, this method will generate headers to refresh the user's auth session. This
|
|
181
|
+
* should likely only be done with a specific endpoint, like whatever endpoint you trigger
|
|
182
|
+
* with the frontend auth client's `checkUser.performCheck` callback.
|
|
183
|
+
*/
|
|
184
|
+
allowUserAuthRefresh: boolean;
|
|
173
185
|
}): Promise<RequireOneOrNone<{
|
|
174
186
|
secureUser: GetUserResult<DatabaseUser>;
|
|
175
187
|
/**
|
|
@@ -185,7 +197,13 @@ export declare class BackendAuthClient<DatabaseUser extends AnyObject, UserId ex
|
|
|
185
197
|
* where JavaScript cannot be used to attach the CSRF token header to the request (like when
|
|
186
198
|
* opening a PDF file). Use `.getSecureUser()` instead, whenever possible.
|
|
187
199
|
*/
|
|
188
|
-
getInsecureUser({ requestHeaders, }: {
|
|
200
|
+
getInsecureUser({ requestHeaders, allowUserAuthRefresh, }: {
|
|
189
201
|
requestHeaders: IncomingHttpHeaders;
|
|
202
|
+
/**
|
|
203
|
+
* If true, this method will generate headers to refresh the user's auth session. This
|
|
204
|
+
* should likely only be done with a specific endpoint, like whatever endpoint you trigger
|
|
205
|
+
* with the frontend auth client's `checkUser.performCheck` callback.
|
|
206
|
+
*/
|
|
207
|
+
allowUserAuthRefresh: boolean;
|
|
190
208
|
}): Promise<GetUserResult<DatabaseUser> | undefined>;
|
|
191
209
|
}
|
|
@@ -110,7 +110,7 @@ export class BackendAuthClient {
|
|
|
110
110
|
return assumedUser;
|
|
111
111
|
}
|
|
112
112
|
/** Securely extract a user from their request headers. */
|
|
113
|
-
async getSecureUser({ requestHeaders, isSignUpCookie, }) {
|
|
113
|
+
async getSecureUser({ requestHeaders, isSignUpCookie, allowUserAuthRefresh, }) {
|
|
114
114
|
const userIdResult = await extractUserIdFromRequestHeaders(requestHeaders, await this.getJwtParams(), isSignUpCookie ? AuthCookieName.SignUp : AuthCookieName.Auth, this.config.overrides);
|
|
115
115
|
if (!userIdResult) {
|
|
116
116
|
return undefined;
|
|
@@ -118,7 +118,7 @@ export class BackendAuthClient {
|
|
|
118
118
|
const user = await this.getDatabaseUser({
|
|
119
119
|
userId: userIdResult.userId,
|
|
120
120
|
assumingUser: undefined,
|
|
121
|
-
isSignUpCookie
|
|
121
|
+
isSignUpCookie,
|
|
122
122
|
});
|
|
123
123
|
if (!user) {
|
|
124
124
|
return undefined;
|
|
@@ -133,7 +133,7 @@ export class BackendAuthClient {
|
|
|
133
133
|
return {
|
|
134
134
|
user: assumedUser || user,
|
|
135
135
|
isAssumed: !!assumedUser,
|
|
136
|
-
responseHeaders: cookieRefreshHeaders,
|
|
136
|
+
responseHeaders: allowUserAuthRefresh ? cookieRefreshHeaders : {},
|
|
137
137
|
};
|
|
138
138
|
}
|
|
139
139
|
/**
|
|
@@ -216,7 +216,7 @@ export class BackendAuthClient {
|
|
|
216
216
|
* where JavaScript cannot be used to attach the CSRF token header to the request (like when
|
|
217
217
|
* opening a PDF file). Use `.getSecureUser()` instead, whenever possible.
|
|
218
218
|
*/
|
|
219
|
-
async getInsecureUser({ requestHeaders, }) {
|
|
219
|
+
async getInsecureUser({ requestHeaders, allowUserAuthRefresh, }) {
|
|
220
220
|
// eslint-disable-next-line @typescript-eslint/no-deprecated
|
|
221
221
|
const userIdResult = await insecureExtractUserIdFromCookieAlone(requestHeaders, await this.getJwtParams(), AuthCookieName.Auth);
|
|
222
222
|
if (!userIdResult) {
|
|
@@ -230,12 +230,14 @@ export class BackendAuthClient {
|
|
|
230
230
|
if (!user) {
|
|
231
231
|
return undefined;
|
|
232
232
|
}
|
|
233
|
+
const refreshHeaders = allowUserAuthRefresh &&
|
|
234
|
+
(await this.createCookieRefreshHeaders({
|
|
235
|
+
userIdResult,
|
|
236
|
+
}));
|
|
233
237
|
return {
|
|
234
238
|
user,
|
|
235
239
|
isAssumed: false,
|
|
236
|
-
responseHeaders:
|
|
237
|
-
userIdResult,
|
|
238
|
-
})) || {},
|
|
240
|
+
responseHeaders: refreshHeaders || {},
|
|
239
241
|
};
|
|
240
242
|
}
|
|
241
243
|
}
|
package/package.json
CHANGED
|
@@ -305,9 +305,16 @@ export class BackendAuthClient<
|
|
|
305
305
|
public async getSecureUser({
|
|
306
306
|
requestHeaders,
|
|
307
307
|
isSignUpCookie,
|
|
308
|
+
allowUserAuthRefresh,
|
|
308
309
|
}: {
|
|
309
310
|
requestHeaders: IncomingHttpHeaders;
|
|
310
|
-
isSignUpCookie
|
|
311
|
+
isSignUpCookie: boolean;
|
|
312
|
+
/**
|
|
313
|
+
* If true, this method will generate headers to refresh the user's auth session. This
|
|
314
|
+
* should likely only be done with a specific endpoint, like whatever endpoint you trigger
|
|
315
|
+
* with the frontend auth client's `checkUser.performCheck` callback.
|
|
316
|
+
*/
|
|
317
|
+
allowUserAuthRefresh: boolean;
|
|
311
318
|
}): Promise<GetUserResult<DatabaseUser> | undefined> {
|
|
312
319
|
const userIdResult = await extractUserIdFromRequestHeaders<UserId>(
|
|
313
320
|
requestHeaders,
|
|
@@ -322,7 +329,7 @@ export class BackendAuthClient<
|
|
|
322
329
|
const user = await this.getDatabaseUser({
|
|
323
330
|
userId: userIdResult.userId,
|
|
324
331
|
assumingUser: undefined,
|
|
325
|
-
isSignUpCookie
|
|
332
|
+
isSignUpCookie,
|
|
326
333
|
});
|
|
327
334
|
|
|
328
335
|
if (!user) {
|
|
@@ -342,7 +349,7 @@ export class BackendAuthClient<
|
|
|
342
349
|
return {
|
|
343
350
|
user: assumedUser || user,
|
|
344
351
|
isAssumed: !!assumedUser,
|
|
345
|
-
responseHeaders: cookieRefreshHeaders,
|
|
352
|
+
responseHeaders: allowUserAuthRefresh ? cookieRefreshHeaders : {},
|
|
346
353
|
};
|
|
347
354
|
}
|
|
348
355
|
|
|
@@ -465,7 +472,13 @@ export class BackendAuthClient<
|
|
|
465
472
|
/** Combines `.getInsecureUser()` and `.getSecureUser()` into one method. */
|
|
466
473
|
public async getInsecureOrSecureUser(params: {
|
|
467
474
|
requestHeaders: IncomingHttpHeaders;
|
|
468
|
-
isSignUpCookie
|
|
475
|
+
isSignUpCookie: boolean;
|
|
476
|
+
/**
|
|
477
|
+
* If true, this method will generate headers to refresh the user's auth session. This
|
|
478
|
+
* should likely only be done with a specific endpoint, like whatever endpoint you trigger
|
|
479
|
+
* with the frontend auth client's `checkUser.performCheck` callback.
|
|
480
|
+
*/
|
|
481
|
+
allowUserAuthRefresh: boolean;
|
|
469
482
|
}): Promise<
|
|
470
483
|
RequireOneOrNone<{
|
|
471
484
|
secureUser: GetUserResult<DatabaseUser>;
|
|
@@ -497,8 +510,15 @@ export class BackendAuthClient<
|
|
|
497
510
|
*/
|
|
498
511
|
public async getInsecureUser({
|
|
499
512
|
requestHeaders,
|
|
513
|
+
allowUserAuthRefresh,
|
|
500
514
|
}: {
|
|
501
515
|
requestHeaders: IncomingHttpHeaders;
|
|
516
|
+
/**
|
|
517
|
+
* If true, this method will generate headers to refresh the user's auth session. This
|
|
518
|
+
* should likely only be done with a specific endpoint, like whatever endpoint you trigger
|
|
519
|
+
* with the frontend auth client's `checkUser.performCheck` callback.
|
|
520
|
+
*/
|
|
521
|
+
allowUserAuthRefresh: boolean;
|
|
502
522
|
}): Promise<GetUserResult<DatabaseUser> | undefined> {
|
|
503
523
|
// eslint-disable-next-line @typescript-eslint/no-deprecated
|
|
504
524
|
const userIdResult = await insecureExtractUserIdFromCookieAlone<UserId>(
|
|
@@ -521,13 +541,16 @@ export class BackendAuthClient<
|
|
|
521
541
|
return undefined;
|
|
522
542
|
}
|
|
523
543
|
|
|
544
|
+
const refreshHeaders =
|
|
545
|
+
allowUserAuthRefresh &&
|
|
546
|
+
(await this.createCookieRefreshHeaders({
|
|
547
|
+
userIdResult,
|
|
548
|
+
}));
|
|
549
|
+
|
|
524
550
|
return {
|
|
525
551
|
user,
|
|
526
552
|
isAssumed: false,
|
|
527
|
-
responseHeaders:
|
|
528
|
-
(await this.createCookieRefreshHeaders({
|
|
529
|
-
userIdResult,
|
|
530
|
-
})) || {},
|
|
553
|
+
responseHeaders: refreshHeaders || {},
|
|
531
554
|
};
|
|
532
555
|
}
|
|
533
556
|
}
|