auth-vir 2.3.9 → 2.4.1
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.
|
@@ -119,14 +119,16 @@ export declare class BackendAuthClient<DatabaseUser extends AnyObject, UserId ex
|
|
|
119
119
|
protected cachedParsedJwtKeys: Record<string, Readonly<JwtKeys>>;
|
|
120
120
|
constructor(config: BackendAuthClientConfig<DatabaseUser, UserId, AssumedUserParams, CsrfHeaderName>);
|
|
121
121
|
/** Get all the parameters used for cookie generation. */
|
|
122
|
-
protected getCookieParams({ isSignUpCookie, }: {
|
|
122
|
+
protected getCookieParams({ isSignUpCookie, serviceOrigin, }: {
|
|
123
123
|
/**
|
|
124
124
|
* Set this to `true` when we are setting the initial cookie right after a user signs up.
|
|
125
125
|
* This allows them to auto-authorize when they verify their email address.
|
|
126
126
|
*
|
|
127
127
|
* This should only be set to `true` when a new user is signing up.
|
|
128
128
|
*/
|
|
129
|
-
isSignUpCookie
|
|
129
|
+
isSignUpCookie: boolean;
|
|
130
|
+
/** Overrides the client's already established `serviceOrigin`. */
|
|
131
|
+
serviceOrigin: string | undefined;
|
|
130
132
|
}): Promise<Readonly<CookieParams>>;
|
|
131
133
|
/** Calls the provided `getUserFromDatabase` config. */
|
|
132
134
|
protected getDatabaseUser({ isSignUpCookie, userId, assumingUser, }: {
|
|
@@ -160,17 +162,22 @@ export declare class BackendAuthClient<DatabaseUser extends AnyObject, UserId ex
|
|
|
160
162
|
*/
|
|
161
163
|
getJwtParams(): Promise<Readonly<CreateJwtParams>>;
|
|
162
164
|
/** Use these headers to log out the user. */
|
|
163
|
-
createLogoutHeaders(params: RequireExactlyOne<{
|
|
165
|
+
createLogoutHeaders(params: Readonly<RequireExactlyOne<{
|
|
164
166
|
allCookies: true;
|
|
165
167
|
isSignUpCookie: boolean;
|
|
168
|
+
}> & {
|
|
169
|
+
/** Overrides the client's already established `serviceOrigin`. */
|
|
170
|
+
serviceOrigin?: string | undefined;
|
|
166
171
|
}>): Promise<Partial<Record<CsrfHeaderName, string>> & {
|
|
167
172
|
'set-cookie': string[];
|
|
168
173
|
}>;
|
|
169
174
|
/** Use these headers to log a user in. */
|
|
170
|
-
createLoginHeaders({ userId, requestHeaders, isSignUpCookie, }: {
|
|
175
|
+
createLoginHeaders({ userId, requestHeaders, isSignUpCookie, serviceOrigin, }: {
|
|
171
176
|
userId: UserId;
|
|
172
177
|
requestHeaders: IncomingHttpHeaders;
|
|
173
178
|
isSignUpCookie: boolean;
|
|
179
|
+
/** Overrides the client's already established `serviceOrigin`. */
|
|
180
|
+
serviceOrigin?: string | undefined;
|
|
174
181
|
}): Promise<OutgoingHttpHeaders>;
|
|
175
182
|
/** Combines `.getInsecureUser()` and `.getSecureUser()` into one method. */
|
|
176
183
|
getInsecureOrSecureUser(params: {
|
|
@@ -24,10 +24,10 @@ export class BackendAuthClient {
|
|
|
24
24
|
this.config = config;
|
|
25
25
|
}
|
|
26
26
|
/** Get all the parameters used for cookie generation. */
|
|
27
|
-
async getCookieParams({ isSignUpCookie, }) {
|
|
27
|
+
async getCookieParams({ isSignUpCookie, serviceOrigin, }) {
|
|
28
28
|
return {
|
|
29
29
|
cookieDuration: this.config.userSessionIdleTimeout || defaultSessionIdleTimeout,
|
|
30
|
-
hostOrigin: this.config.serviceOrigin,
|
|
30
|
+
hostOrigin: serviceOrigin || this.config.serviceOrigin,
|
|
31
31
|
jwtParams: await this.getJwtParams(),
|
|
32
32
|
isDev: this.config.isDev,
|
|
33
33
|
cookieName: isSignUpCookie ? AuthCookieName.SignUp : AuthCookieName.Auth,
|
|
@@ -160,11 +160,13 @@ export class BackendAuthClient {
|
|
|
160
160
|
const signUpCookieHeaders = params.allCookies || params.isSignUpCookie
|
|
161
161
|
? generateLogoutHeaders(await this.getCookieParams({
|
|
162
162
|
isSignUpCookie: true,
|
|
163
|
+
serviceOrigin: params.serviceOrigin,
|
|
163
164
|
}), this.config.overrides)
|
|
164
165
|
: undefined;
|
|
165
166
|
const authCookieHeaders = params.allCookies || !params.isSignUpCookie
|
|
166
167
|
? generateLogoutHeaders(await this.getCookieParams({
|
|
167
168
|
isSignUpCookie: false,
|
|
169
|
+
serviceOrigin: params.serviceOrigin,
|
|
168
170
|
}), this.config.overrides)
|
|
169
171
|
: undefined;
|
|
170
172
|
const setCookieHeader = {
|
|
@@ -180,16 +182,18 @@ export class BackendAuthClient {
|
|
|
180
182
|
};
|
|
181
183
|
}
|
|
182
184
|
/** Use these headers to log a user in. */
|
|
183
|
-
async createLoginHeaders({ userId, requestHeaders, isSignUpCookie, }) {
|
|
185
|
+
async createLoginHeaders({ userId, requestHeaders, isSignUpCookie, serviceOrigin, }) {
|
|
184
186
|
const oppositeCookieName = isSignUpCookie ? AuthCookieName.Auth : AuthCookieName.SignUp;
|
|
185
187
|
const hasExistingOppositeCookie = requestHeaders.cookie?.includes(`${oppositeCookieName}=`);
|
|
186
188
|
const discardOppositeCookieHeaders = hasExistingOppositeCookie
|
|
187
189
|
? generateLogoutHeaders(await this.getCookieParams({
|
|
188
190
|
isSignUpCookie: !isSignUpCookie,
|
|
191
|
+
serviceOrigin,
|
|
189
192
|
}), this.config.overrides)
|
|
190
193
|
: undefined;
|
|
191
194
|
const newCookieHeaders = await generateSuccessfulLoginHeaders(userId, await this.getCookieParams({
|
|
192
195
|
isSignUpCookie,
|
|
196
|
+
serviceOrigin,
|
|
193
197
|
}), this.config.overrides);
|
|
194
198
|
return {
|
|
195
199
|
...newCookieHeaders,
|
package/package.json
CHANGED
|
@@ -168,6 +168,7 @@ export class BackendAuthClient<
|
|
|
168
168
|
/** Get all the parameters used for cookie generation. */
|
|
169
169
|
protected async getCookieParams({
|
|
170
170
|
isSignUpCookie,
|
|
171
|
+
serviceOrigin,
|
|
171
172
|
}: {
|
|
172
173
|
/**
|
|
173
174
|
* Set this to `true` when we are setting the initial cookie right after a user signs up.
|
|
@@ -175,11 +176,13 @@ export class BackendAuthClient<
|
|
|
175
176
|
*
|
|
176
177
|
* This should only be set to `true` when a new user is signing up.
|
|
177
178
|
*/
|
|
178
|
-
isSignUpCookie
|
|
179
|
+
isSignUpCookie: boolean;
|
|
180
|
+
/** Overrides the client's already established `serviceOrigin`. */
|
|
181
|
+
serviceOrigin: string | undefined;
|
|
179
182
|
}): Promise<Readonly<CookieParams>> {
|
|
180
183
|
return {
|
|
181
184
|
cookieDuration: this.config.userSessionIdleTimeout || defaultSessionIdleTimeout,
|
|
182
|
-
hostOrigin: this.config.serviceOrigin,
|
|
185
|
+
hostOrigin: serviceOrigin || this.config.serviceOrigin,
|
|
183
186
|
jwtParams: await this.getJwtParams(),
|
|
184
187
|
isDev: this.config.isDev,
|
|
185
188
|
cookieName: isSignUpCookie ? AuthCookieName.SignUp : AuthCookieName.Auth,
|
|
@@ -378,10 +381,15 @@ export class BackendAuthClient<
|
|
|
378
381
|
|
|
379
382
|
/** Use these headers to log out the user. */
|
|
380
383
|
public async createLogoutHeaders(
|
|
381
|
-
params:
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
384
|
+
params: Readonly<
|
|
385
|
+
RequireExactlyOne<{
|
|
386
|
+
allCookies: true;
|
|
387
|
+
isSignUpCookie: boolean;
|
|
388
|
+
}> & {
|
|
389
|
+
/** Overrides the client's already established `serviceOrigin`. */
|
|
390
|
+
serviceOrigin?: string | undefined;
|
|
391
|
+
}
|
|
392
|
+
>,
|
|
385
393
|
): Promise<
|
|
386
394
|
Partial<Record<CsrfHeaderName, string>> & {
|
|
387
395
|
'set-cookie': string[];
|
|
@@ -392,6 +400,7 @@ export class BackendAuthClient<
|
|
|
392
400
|
? (generateLogoutHeaders(
|
|
393
401
|
await this.getCookieParams({
|
|
394
402
|
isSignUpCookie: true,
|
|
403
|
+
serviceOrigin: params.serviceOrigin,
|
|
395
404
|
}),
|
|
396
405
|
this.config.overrides,
|
|
397
406
|
) satisfies Record<CsrfHeaderName, string>)
|
|
@@ -401,6 +410,7 @@ export class BackendAuthClient<
|
|
|
401
410
|
? (generateLogoutHeaders(
|
|
402
411
|
await this.getCookieParams({
|
|
403
412
|
isSignUpCookie: false,
|
|
413
|
+
serviceOrigin: params.serviceOrigin,
|
|
404
414
|
}),
|
|
405
415
|
this.config.overrides,
|
|
406
416
|
) satisfies Record<CsrfHeaderName, string>)
|
|
@@ -430,10 +440,13 @@ export class BackendAuthClient<
|
|
|
430
440
|
userId,
|
|
431
441
|
requestHeaders,
|
|
432
442
|
isSignUpCookie,
|
|
443
|
+
serviceOrigin,
|
|
433
444
|
}: {
|
|
434
445
|
userId: UserId;
|
|
435
446
|
requestHeaders: IncomingHttpHeaders;
|
|
436
447
|
isSignUpCookie: boolean;
|
|
448
|
+
/** Overrides the client's already established `serviceOrigin`. */
|
|
449
|
+
serviceOrigin?: string | undefined;
|
|
437
450
|
}): Promise<OutgoingHttpHeaders> {
|
|
438
451
|
const oppositeCookieName = isSignUpCookie ? AuthCookieName.Auth : AuthCookieName.SignUp;
|
|
439
452
|
const hasExistingOppositeCookie = requestHeaders.cookie?.includes(`${oppositeCookieName}=`);
|
|
@@ -442,6 +455,7 @@ export class BackendAuthClient<
|
|
|
442
455
|
? generateLogoutHeaders(
|
|
443
456
|
await this.getCookieParams({
|
|
444
457
|
isSignUpCookie: !isSignUpCookie,
|
|
458
|
+
serviceOrigin,
|
|
445
459
|
}),
|
|
446
460
|
this.config.overrides,
|
|
447
461
|
)
|
|
@@ -451,6 +465,7 @@ export class BackendAuthClient<
|
|
|
451
465
|
userId,
|
|
452
466
|
await this.getCookieParams({
|
|
453
467
|
isSignUpCookie,
|
|
468
|
+
serviceOrigin,
|
|
454
469
|
}),
|
|
455
470
|
this.config.overrides,
|
|
456
471
|
);
|