@adminforth/two-factors-auth 3.1.0 → 3.1.2
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 -10
- package/index.ts +12 -6
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -157,15 +157,15 @@ export default class TwoFactorsAuthPlugin extends AdminForthPlugin {
|
|
|
157
157
|
}
|
|
158
158
|
verify(confirmationResult, opts) {
|
|
159
159
|
return __awaiter(this, void 0, void 0, function* () {
|
|
160
|
-
var _a, _b, _c, _d, _e;
|
|
160
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
161
161
|
if (!confirmationResult)
|
|
162
162
|
return { error: "Confirmation result is required" };
|
|
163
163
|
if (!opts.adminUser)
|
|
164
164
|
return { error: "Admin user is required" };
|
|
165
165
|
if (!opts.userPk)
|
|
166
166
|
return { error: "User PK is required" };
|
|
167
|
-
const cookies = opts.extra.cookies || opts.cookies;
|
|
168
|
-
const response = opts.extra.response || opts.response;
|
|
167
|
+
const cookies = ((_a = opts.extra) === null || _a === void 0 ? void 0 : _a.cookies) || opts.cookies;
|
|
168
|
+
const response = ((_b = opts.extra) === null || _b === void 0 ? void 0 : _b.response) || opts.response;
|
|
169
169
|
if (this.options.usersFilterToApply) {
|
|
170
170
|
const res = this.options.usersFilterToApply(opts.adminUser);
|
|
171
171
|
if (res === false) {
|
|
@@ -178,7 +178,7 @@ export default class TwoFactorsAuthPlugin extends AdminForthPlugin {
|
|
|
178
178
|
return { ok: true };
|
|
179
179
|
}
|
|
180
180
|
}
|
|
181
|
-
if (this.options.stepUpMfaGracePeriodSeconds && ((
|
|
181
|
+
if (this.options.stepUpMfaGracePeriodSeconds && ((_c = opts.extra) === null || _c === void 0 ? void 0 : _c.headers) && !confirmationResult.mode) {
|
|
182
182
|
const verificationResult = yield this.isTempSkip2FAGraceValid(opts.extra.headers, cookies);
|
|
183
183
|
if (verificationResult === true) {
|
|
184
184
|
return { ok: true };
|
|
@@ -191,10 +191,10 @@ export default class TwoFactorsAuthPlugin extends AdminForthPlugin {
|
|
|
191
191
|
if (!authRes)
|
|
192
192
|
return { error: "Auth resource not found" };
|
|
193
193
|
const connector = this.adminforth.connectors[authRes.dataSource];
|
|
194
|
-
const pkName = (
|
|
194
|
+
const pkName = (_d = authRes.columns.find(c => c.primaryKey)) === null || _d === void 0 ? void 0 : _d.name;
|
|
195
195
|
if (!pkName)
|
|
196
196
|
return { error: "Primary key not found on auth resource" };
|
|
197
|
-
const pk = (
|
|
197
|
+
const pk = (_e = opts === null || opts === void 0 ? void 0 : opts.userPk) !== null && _e !== void 0 ? _e : (_g = (_f = opts === null || opts === void 0 ? void 0 : opts.adminUser) === null || _f === void 0 ? void 0 : _f.dbUser) === null || _g === void 0 ? void 0 : _g[pkName];
|
|
198
198
|
if (!pk)
|
|
199
199
|
return { error: "User PK is required" };
|
|
200
200
|
const user = yield connector.getRecordByPrimaryKey(authRes, pk);
|
|
@@ -717,7 +717,7 @@ export default class TwoFactorsAuthPlugin extends AdminForthPlugin {
|
|
|
717
717
|
method: 'POST',
|
|
718
718
|
path: `/plugin/passkeys/registerPasskeyRequest`,
|
|
719
719
|
noAuth: false,
|
|
720
|
-
handler: (_a) => __awaiter(this, [_a], void 0, function* ({ body, adminUser, response, cookies }) {
|
|
720
|
+
handler: (_a) => __awaiter(this, [_a], void 0, function* ({ body, adminUser, response, cookies, headers }) {
|
|
721
721
|
var _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o;
|
|
722
722
|
const mode = body === null || body === void 0 ? void 0 : body.mode;
|
|
723
723
|
const confirmationResult = body === null || body === void 0 ? void 0 : body.confirmationResult;
|
|
@@ -725,7 +725,10 @@ export default class TwoFactorsAuthPlugin extends AdminForthPlugin {
|
|
|
725
725
|
adminUser: adminUser,
|
|
726
726
|
userPk: adminUser.pk,
|
|
727
727
|
cookies: cookies,
|
|
728
|
-
response: response
|
|
728
|
+
response: response,
|
|
729
|
+
extra: {
|
|
730
|
+
headers,
|
|
731
|
+
}
|
|
729
732
|
});
|
|
730
733
|
if (!verificationResult || !('ok' in verificationResult)) {
|
|
731
734
|
return { ok: false, error: 'Verification failed' };
|
|
@@ -1015,7 +1018,7 @@ export default class TwoFactorsAuthPlugin extends AdminForthPlugin {
|
|
|
1015
1018
|
method: 'POST',
|
|
1016
1019
|
path: `/plugin/passkeys/resolveVerifyAuto`,
|
|
1017
1020
|
noAuth: false,
|
|
1018
|
-
handler: (_a) => __awaiter(this, [_a], void 0, function* ({ body, adminUser, response, cookies }) {
|
|
1021
|
+
handler: (_a) => __awaiter(this, [_a], void 0, function* ({ body, adminUser, response, cookies, headers }) {
|
|
1019
1022
|
const sessionId = body === null || body === void 0 ? void 0 : body.sessionId;
|
|
1020
1023
|
const confirmationResult = body === null || body === void 0 ? void 0 : body.confirmationResult;
|
|
1021
1024
|
if (!sessionId || !confirmationResult) {
|
|
@@ -1026,7 +1029,10 @@ export default class TwoFactorsAuthPlugin extends AdminForthPlugin {
|
|
|
1026
1029
|
adminUser: adminUser,
|
|
1027
1030
|
userPk: adminUser.pk,
|
|
1028
1031
|
cookies: cookies,
|
|
1029
|
-
response: response
|
|
1032
|
+
response: response,
|
|
1033
|
+
extra: {
|
|
1034
|
+
headers: headers,
|
|
1035
|
+
}
|
|
1030
1036
|
});
|
|
1031
1037
|
if (!verificationResult || !('ok' in verificationResult)) {
|
|
1032
1038
|
this.resolveResponse(sessionId, { ok: false, error: 'Verification failed' });
|
package/index.ts
CHANGED
|
@@ -172,8 +172,8 @@ export default class TwoFactorsAuthPlugin extends AdminForthPlugin {
|
|
|
172
172
|
if (!confirmationResult) return { error: "Confirmation result is required" };
|
|
173
173
|
if (!opts.adminUser) return { error: "Admin user is required" };
|
|
174
174
|
if (!opts.userPk) return { error: "User PK is required" };
|
|
175
|
-
const cookies = opts.extra
|
|
176
|
-
const response = opts.extra
|
|
175
|
+
const cookies = opts.extra?.cookies || opts.cookies;
|
|
176
|
+
const response = opts.extra?.response || opts.response;
|
|
177
177
|
if (this.options.usersFilterToApply) {
|
|
178
178
|
const res = this.options.usersFilterToApply(opts.adminUser);
|
|
179
179
|
if ( res === false ) {
|
|
@@ -777,7 +777,7 @@ export default class TwoFactorsAuthPlugin extends AdminForthPlugin {
|
|
|
777
777
|
method: 'POST',
|
|
778
778
|
path: `/plugin/passkeys/registerPasskeyRequest`,
|
|
779
779
|
noAuth: false,
|
|
780
|
-
handler: async ({ body, adminUser, response, cookies }) => {
|
|
780
|
+
handler: async ({ body, adminUser, response, cookies, headers }) => {
|
|
781
781
|
const mode = body?.mode;
|
|
782
782
|
|
|
783
783
|
const confirmationResult = body?.confirmationResult;
|
|
@@ -785,7 +785,10 @@ export default class TwoFactorsAuthPlugin extends AdminForthPlugin {
|
|
|
785
785
|
adminUser: adminUser,
|
|
786
786
|
userPk: adminUser.pk,
|
|
787
787
|
cookies: cookies,
|
|
788
|
-
response: response
|
|
788
|
+
response: response,
|
|
789
|
+
extra: {
|
|
790
|
+
headers,
|
|
791
|
+
} as HttpExtra
|
|
789
792
|
});
|
|
790
793
|
if ( !verificationResult || !('ok' in verificationResult) ) {
|
|
791
794
|
return { ok: false, error: 'Verification failed' };
|
|
@@ -1076,7 +1079,7 @@ export default class TwoFactorsAuthPlugin extends AdminForthPlugin {
|
|
|
1076
1079
|
method: 'POST',
|
|
1077
1080
|
path: `/plugin/passkeys/resolveVerifyAuto`,
|
|
1078
1081
|
noAuth: false,
|
|
1079
|
-
handler: async ({ body, adminUser, response, cookies }) => {
|
|
1082
|
+
handler: async ({ body, adminUser, response, cookies, headers }) => {
|
|
1080
1083
|
const sessionId = body?.sessionId;
|
|
1081
1084
|
const confirmationResult = body?.confirmationResult;
|
|
1082
1085
|
if (!sessionId || !confirmationResult) {
|
|
@@ -1087,7 +1090,10 @@ export default class TwoFactorsAuthPlugin extends AdminForthPlugin {
|
|
|
1087
1090
|
adminUser: adminUser,
|
|
1088
1091
|
userPk: adminUser.pk,
|
|
1089
1092
|
cookies: cookies,
|
|
1090
|
-
response: response
|
|
1093
|
+
response: response,
|
|
1094
|
+
extra: {
|
|
1095
|
+
headers: headers,
|
|
1096
|
+
} as HttpExtra
|
|
1091
1097
|
});
|
|
1092
1098
|
if ( !verificationResult || !('ok' in verificationResult) ) {
|
|
1093
1099
|
this.resolveResponse(sessionId, { ok: false, error: 'Verification failed' });
|