@cairs-npm/express-auth-2fa 0.1.0 → 0.1.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.
- package/dist/index.cjs +4 -3
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +4 -3
- package/dist/index.js.map +1 -1
- package/package.json +11 -4
package/dist/index.cjs
CHANGED
|
@@ -952,7 +952,8 @@ var AuthService = class {
|
|
|
952
952
|
const bundle = await this.tokens.issueTokens(userId, amr, ctx);
|
|
953
953
|
const refreshDays = opts.rememberMe ? this.config.ttl.refreshTokenDays : Math.min(this.config.ttl.refreshTokenDays, 1);
|
|
954
954
|
setCookie(res, this.config, REFRESH_COOKIE, bundle.refreshToken, refreshDays * 864e5);
|
|
955
|
-
|
|
955
|
+
const csrfToken = randomToken();
|
|
956
|
+
setCookie(res, this.config, CSRF_COOKIE, csrfToken, this.config.ttl.refreshTokenDays * 864e5, false);
|
|
956
957
|
if (opts.rememberDevice) {
|
|
957
958
|
await this.trustDevice(userId, res, opts.deviceLabel ?? "This device");
|
|
958
959
|
}
|
|
@@ -960,7 +961,7 @@ var AuthService = class {
|
|
|
960
961
|
return {
|
|
961
962
|
status: "AUTHENTICATED",
|
|
962
963
|
user: { id: userId, username: user?.username, email: user?.email },
|
|
963
|
-
tokens: { accessToken: bundle.accessToken, expiresInSec: bundle.expiresInSec }
|
|
964
|
+
tokens: { accessToken: bundle.accessToken, expiresInSec: bundle.expiresInSec, csrfToken }
|
|
964
965
|
};
|
|
965
966
|
}
|
|
966
967
|
async trustDevice(userId, res, label) {
|
|
@@ -986,7 +987,7 @@ var AuthService = class {
|
|
|
986
987
|
if (!raw) throw apiError(401, "INVALID_CREDENTIALS", "No refresh token.");
|
|
987
988
|
const bundle = await this.tokens.rotateRefreshToken(raw, ctxOf(req));
|
|
988
989
|
setCookie(res, this.config, REFRESH_COOKIE, bundle.refreshToken, this.config.ttl.refreshTokenDays * 864e5);
|
|
989
|
-
return { accessToken: bundle.accessToken, expiresInSec: bundle.expiresInSec };
|
|
990
|
+
return { accessToken: bundle.accessToken, expiresInSec: bundle.expiresInSec, csrfToken: csrfCookie };
|
|
990
991
|
}
|
|
991
992
|
async logout(req, res, sid) {
|
|
992
993
|
await this.tokens.revokeSession(sid);
|