@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.d.cts
CHANGED
|
@@ -551,12 +551,14 @@ declare class AuthService {
|
|
|
551
551
|
tokens: {
|
|
552
552
|
accessToken: string;
|
|
553
553
|
expiresInSec: number;
|
|
554
|
+
csrfToken?: string;
|
|
554
555
|
};
|
|
555
556
|
}>;
|
|
556
557
|
trustDevice(userId: string, res: Response, label: string): Promise<void>;
|
|
557
558
|
refresh(req: Request, res: Response): Promise<{
|
|
558
559
|
accessToken: string;
|
|
559
560
|
expiresInSec: number;
|
|
561
|
+
csrfToken?: string;
|
|
560
562
|
}>;
|
|
561
563
|
logout(req: Request, res: Response, sid: string): Promise<void>;
|
|
562
564
|
listActiveMethods(userId: string): Promise<Method[]>;
|
package/dist/index.d.ts
CHANGED
|
@@ -551,12 +551,14 @@ declare class AuthService {
|
|
|
551
551
|
tokens: {
|
|
552
552
|
accessToken: string;
|
|
553
553
|
expiresInSec: number;
|
|
554
|
+
csrfToken?: string;
|
|
554
555
|
};
|
|
555
556
|
}>;
|
|
556
557
|
trustDevice(userId: string, res: Response, label: string): Promise<void>;
|
|
557
558
|
refresh(req: Request, res: Response): Promise<{
|
|
558
559
|
accessToken: string;
|
|
559
560
|
expiresInSec: number;
|
|
561
|
+
csrfToken?: string;
|
|
560
562
|
}>;
|
|
561
563
|
logout(req: Request, res: Response, sid: string): Promise<void>;
|
|
562
564
|
listActiveMethods(userId: string): Promise<Method[]>;
|
package/dist/index.js
CHANGED
|
@@ -860,7 +860,8 @@ var AuthService = class {
|
|
|
860
860
|
const bundle = await this.tokens.issueTokens(userId, amr, ctx);
|
|
861
861
|
const refreshDays = opts.rememberMe ? this.config.ttl.refreshTokenDays : Math.min(this.config.ttl.refreshTokenDays, 1);
|
|
862
862
|
setCookie(res, this.config, REFRESH_COOKIE, bundle.refreshToken, refreshDays * 864e5);
|
|
863
|
-
|
|
863
|
+
const csrfToken = randomToken();
|
|
864
|
+
setCookie(res, this.config, CSRF_COOKIE, csrfToken, this.config.ttl.refreshTokenDays * 864e5, false);
|
|
864
865
|
if (opts.rememberDevice) {
|
|
865
866
|
await this.trustDevice(userId, res, opts.deviceLabel ?? "This device");
|
|
866
867
|
}
|
|
@@ -868,7 +869,7 @@ var AuthService = class {
|
|
|
868
869
|
return {
|
|
869
870
|
status: "AUTHENTICATED",
|
|
870
871
|
user: { id: userId, username: user?.username, email: user?.email },
|
|
871
|
-
tokens: { accessToken: bundle.accessToken, expiresInSec: bundle.expiresInSec }
|
|
872
|
+
tokens: { accessToken: bundle.accessToken, expiresInSec: bundle.expiresInSec, csrfToken }
|
|
872
873
|
};
|
|
873
874
|
}
|
|
874
875
|
async trustDevice(userId, res, label) {
|
|
@@ -894,7 +895,7 @@ var AuthService = class {
|
|
|
894
895
|
if (!raw) throw apiError(401, "INVALID_CREDENTIALS", "No refresh token.");
|
|
895
896
|
const bundle = await this.tokens.rotateRefreshToken(raw, ctxOf(req));
|
|
896
897
|
setCookie(res, this.config, REFRESH_COOKIE, bundle.refreshToken, this.config.ttl.refreshTokenDays * 864e5);
|
|
897
|
-
return { accessToken: bundle.accessToken, expiresInSec: bundle.expiresInSec };
|
|
898
|
+
return { accessToken: bundle.accessToken, expiresInSec: bundle.expiresInSec, csrfToken: csrfCookie };
|
|
898
899
|
}
|
|
899
900
|
async logout(req, res, sid) {
|
|
900
901
|
await this.tokens.revokeSession(sid);
|