@adminforth/two-factors-auth 2.10.9 → 2.10.10
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.js +16 -19
- package/index.ts +12 -13
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -63,17 +63,17 @@ export default class TwoFactorsAuthPlugin extends AdminForthPlugin {
|
|
|
63
63
|
return hmac;
|
|
64
64
|
}
|
|
65
65
|
}
|
|
66
|
-
issueTempSkip2FAGraceJWT(opts) {
|
|
67
|
-
if (
|
|
66
|
+
issueTempSkip2FAGraceJWT(opts, cookies, response) {
|
|
67
|
+
if (response) {
|
|
68
68
|
if (opts.extra.headers) {
|
|
69
|
-
const hash = this.generateHashForStepUpMfaGraceCookie(opts.extra.headers,
|
|
69
|
+
const hash = this.generateHashForStepUpMfaGraceCookie(opts.extra.headers, cookies);
|
|
70
70
|
if (!hash) {
|
|
71
71
|
return;
|
|
72
72
|
}
|
|
73
73
|
const jwt = this.adminforth.auth.issueJWT({ hash: hash }, 'MfaGrace', `${this.options.stepUpMfaGracePeriodSeconds}s`);
|
|
74
74
|
//TODO: fix ts-ignore after releasing new version of adminforth with updated types
|
|
75
75
|
//@ts-ignore
|
|
76
|
-
this.adminforth.auth.setCustomCookie({ response:
|
|
76
|
+
this.adminforth.auth.setCustomCookie({ response: response, payload: { name: "TempSkip2FA_Modal_JWT", value: jwt, expirySeconds: this.options.stepUpMfaGracePeriodSeconds, httpOnly: true } });
|
|
77
77
|
}
|
|
78
78
|
}
|
|
79
79
|
else {
|
|
@@ -104,20 +104,15 @@ export default class TwoFactorsAuthPlugin extends AdminForthPlugin {
|
|
|
104
104
|
}
|
|
105
105
|
verify(confirmationResult, opts) {
|
|
106
106
|
return __awaiter(this, void 0, void 0, function* () {
|
|
107
|
-
var _a, _b, _c, _d, _e
|
|
107
|
+
var _a, _b, _c, _d, _e;
|
|
108
108
|
if (!confirmationResult)
|
|
109
109
|
return { error: "Confirmation result is required" };
|
|
110
110
|
if (!opts.adminUser)
|
|
111
111
|
return { error: "Admin user is required" };
|
|
112
112
|
if (!opts.userPk)
|
|
113
113
|
return { error: "User PK is required" };
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
if (!opts.cookies)
|
|
117
|
-
return { error: "Cookies are required" };
|
|
118
|
-
if (!(opts === null || opts === void 0 ? void 0 : opts.cookies)) {
|
|
119
|
-
opts.cookies = (_a = opts.extra) === null || _a === void 0 ? void 0 : _a.cookies;
|
|
120
|
-
}
|
|
114
|
+
const cookies = opts.extra.cookies || opts.cookies;
|
|
115
|
+
const response = opts.extra.response || opts.response;
|
|
121
116
|
if (this.options.usersFilterToApply) {
|
|
122
117
|
const res = this.options.usersFilterToApply(opts.adminUser);
|
|
123
118
|
if (res === false) {
|
|
@@ -130,8 +125,8 @@ export default class TwoFactorsAuthPlugin extends AdminForthPlugin {
|
|
|
130
125
|
return { ok: true };
|
|
131
126
|
}
|
|
132
127
|
}
|
|
133
|
-
if (this.options.stepUpMfaGracePeriodSeconds && ((
|
|
134
|
-
const verificationResult = yield this.isTempSkip2FAGraceValid(opts.extra.headers,
|
|
128
|
+
if (this.options.stepUpMfaGracePeriodSeconds && ((_a = opts.extra) === null || _a === void 0 ? void 0 : _a.headers) && !confirmationResult.mode) {
|
|
129
|
+
const verificationResult = yield this.isTempSkip2FAGraceValid(opts.extra.headers, cookies);
|
|
135
130
|
if (verificationResult === true) {
|
|
136
131
|
return { ok: true };
|
|
137
132
|
}
|
|
@@ -143,10 +138,10 @@ export default class TwoFactorsAuthPlugin extends AdminForthPlugin {
|
|
|
143
138
|
if (!authRes)
|
|
144
139
|
return { error: "Auth resource not found" };
|
|
145
140
|
const connector = this.adminforth.connectors[authRes.dataSource];
|
|
146
|
-
const pkName = (
|
|
141
|
+
const pkName = (_b = authRes.columns.find(c => c.primaryKey)) === null || _b === void 0 ? void 0 : _b.name;
|
|
147
142
|
if (!pkName)
|
|
148
143
|
return { error: "Primary key not found on auth resource" };
|
|
149
|
-
const pk = (
|
|
144
|
+
const pk = (_c = opts === null || opts === void 0 ? void 0 : opts.userPk) !== null && _c !== void 0 ? _c : (_e = (_d = opts === null || opts === void 0 ? void 0 : opts.adminUser) === null || _d === void 0 ? void 0 : _d.dbUser) === null || _e === void 0 ? void 0 : _e[pkName];
|
|
150
145
|
if (!pk)
|
|
151
146
|
return { error: "User PK is required" };
|
|
152
147
|
const user = yield connector.getRecordByPrimaryKey(authRes, pk);
|
|
@@ -159,7 +154,7 @@ export default class TwoFactorsAuthPlugin extends AdminForthPlugin {
|
|
|
159
154
|
//* SET GRACE COOKIE *//
|
|
160
155
|
if (verified) {
|
|
161
156
|
if (this.options.stepUpMfaGracePeriodSeconds) {
|
|
162
|
-
this.issueTempSkip2FAGraceJWT(opts);
|
|
157
|
+
this.issueTempSkip2FAGraceJWT(opts, cookies, response);
|
|
163
158
|
}
|
|
164
159
|
return { ok: true };
|
|
165
160
|
}
|
|
@@ -169,7 +164,9 @@ export default class TwoFactorsAuthPlugin extends AdminForthPlugin {
|
|
|
169
164
|
;
|
|
170
165
|
}
|
|
171
166
|
else if (confirmationResult.mode === "passkey") {
|
|
172
|
-
|
|
167
|
+
//TODO: fix ts-ignore after releasing new version of adminforth with updated types
|
|
168
|
+
//@ts-ignore
|
|
169
|
+
const passkeysCookies = this.adminforth.auth.getCustomCookie({ cookies: cookies, name: `passkeyLoginTemporaryJWT` });
|
|
173
170
|
if (!passkeysCookies) {
|
|
174
171
|
return { error: 'Passkey token is required' };
|
|
175
172
|
}
|
|
@@ -181,7 +178,7 @@ export default class TwoFactorsAuthPlugin extends AdminForthPlugin {
|
|
|
181
178
|
if (verificationResult.ok && verificationResult.passkeyConfirmed) {
|
|
182
179
|
//* SET GRACE COOKIE *//
|
|
183
180
|
if (this.options.stepUpMfaGracePeriodSeconds) {
|
|
184
|
-
this.issueTempSkip2FAGraceJWT(opts);
|
|
181
|
+
this.issueTempSkip2FAGraceJWT(opts, cookies, response);
|
|
185
182
|
}
|
|
186
183
|
return { ok: true };
|
|
187
184
|
}
|
package/index.ts
CHANGED
|
@@ -73,17 +73,17 @@ export default class TwoFactorsAuthPlugin extends AdminForthPlugin {
|
|
|
73
73
|
}
|
|
74
74
|
}
|
|
75
75
|
|
|
76
|
-
private issueTempSkip2FAGraceJWT(opts): void {
|
|
77
|
-
if (
|
|
76
|
+
private issueTempSkip2FAGraceJWT(opts, cookies, response): void {
|
|
77
|
+
if (response) {
|
|
78
78
|
if (opts.extra.headers) {
|
|
79
|
-
const hash = this.generateHashForStepUpMfaGraceCookie(opts.extra.headers,
|
|
79
|
+
const hash = this.generateHashForStepUpMfaGraceCookie(opts.extra.headers, cookies);
|
|
80
80
|
if (!hash) {
|
|
81
81
|
return;
|
|
82
82
|
}
|
|
83
83
|
const jwt = this.adminforth.auth.issueJWT({ hash: hash }, 'MfaGrace', `${this.options.stepUpMfaGracePeriodSeconds}s`);
|
|
84
84
|
//TODO: fix ts-ignore after releasing new version of adminforth with updated types
|
|
85
85
|
//@ts-ignore
|
|
86
|
-
this.adminforth.auth.setCustomCookie({response:
|
|
86
|
+
this.adminforth.auth.setCustomCookie({response: response, payload: {name: "TempSkip2FA_Modal_JWT", value: jwt, expirySeconds: this.options.stepUpMfaGracePeriodSeconds, httpOnly: true}});
|
|
87
87
|
}
|
|
88
88
|
} else {
|
|
89
89
|
console.error("❗️❗️❗️ Cannot set step-up MFA grace cookie: response object is missing. You probably called verify() method without response parameter ❗️❗️❗️");
|
|
@@ -118,11 +118,8 @@ export default class TwoFactorsAuthPlugin extends AdminForthPlugin {
|
|
|
118
118
|
if (!confirmationResult) return { error: "Confirmation result is required" };
|
|
119
119
|
if (!opts.adminUser) return { error: "Admin user is required" };
|
|
120
120
|
if (!opts.userPk) return { error: "User PK is required" };
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
if (!opts?.cookies) {
|
|
124
|
-
opts.cookies = opts.extra?.cookies;
|
|
125
|
-
}
|
|
121
|
+
const cookies = opts.extra.cookies || opts.cookies;
|
|
122
|
+
const response = opts.extra.response || opts.response;
|
|
126
123
|
if (this.options.usersFilterToApply) {
|
|
127
124
|
const res = this.options.usersFilterToApply(opts.adminUser);
|
|
128
125
|
if ( res === false ) {
|
|
@@ -136,7 +133,7 @@ export default class TwoFactorsAuthPlugin extends AdminForthPlugin {
|
|
|
136
133
|
}
|
|
137
134
|
}
|
|
138
135
|
if ( this.options.stepUpMfaGracePeriodSeconds && opts.extra?.headers && !confirmationResult.mode) {
|
|
139
|
-
const verificationResult = await this.isTempSkip2FAGraceValid(opts.extra.headers,
|
|
136
|
+
const verificationResult = await this.isTempSkip2FAGraceValid(opts.extra.headers, cookies);
|
|
140
137
|
if ( verificationResult === true ) {
|
|
141
138
|
return { ok: true };
|
|
142
139
|
}
|
|
@@ -167,14 +164,16 @@ export default class TwoFactorsAuthPlugin extends AdminForthPlugin {
|
|
|
167
164
|
//* SET GRACE COOKIE *//
|
|
168
165
|
if ( verified ) {
|
|
169
166
|
if (this.options.stepUpMfaGracePeriodSeconds) {
|
|
170
|
-
this.issueTempSkip2FAGraceJWT(opts);
|
|
167
|
+
this.issueTempSkip2FAGraceJWT(opts, cookies, response);
|
|
171
168
|
}
|
|
172
169
|
return { ok: true }
|
|
173
170
|
} else {
|
|
174
171
|
return { error: "Wrong or expired OTP code" }
|
|
175
172
|
};
|
|
176
173
|
} else if (confirmationResult.mode === "passkey") {
|
|
177
|
-
|
|
174
|
+
//TODO: fix ts-ignore after releasing new version of adminforth with updated types
|
|
175
|
+
//@ts-ignore
|
|
176
|
+
const passkeysCookies = this.adminforth.auth.getCustomCookie({cookies: cookies, name: `passkeyLoginTemporaryJWT`});
|
|
178
177
|
if (!passkeysCookies) {
|
|
179
178
|
return { error: 'Passkey token is required' };
|
|
180
179
|
}
|
|
@@ -189,7 +188,7 @@ export default class TwoFactorsAuthPlugin extends AdminForthPlugin {
|
|
|
189
188
|
|
|
190
189
|
//* SET GRACE COOKIE *//
|
|
191
190
|
if (this.options.stepUpMfaGracePeriodSeconds) {
|
|
192
|
-
this.issueTempSkip2FAGraceJWT(opts);
|
|
191
|
+
this.issueTempSkip2FAGraceJWT(opts, cookies, response);
|
|
193
192
|
}
|
|
194
193
|
return { ok: true }
|
|
195
194
|
}
|