@adminforth/two-factors-auth 2.10.8 → 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 +20 -15
- package/index.ts +14 -11
- 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,12 +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
|
-
if (!
|
|
111
|
-
|
|
112
|
-
|
|
110
|
+
if (!opts.adminUser)
|
|
111
|
+
return { error: "Admin user is required" };
|
|
112
|
+
if (!opts.userPk)
|
|
113
|
+
return { error: "User PK is required" };
|
|
114
|
+
const cookies = opts.extra.cookies || opts.cookies;
|
|
115
|
+
const response = opts.extra.response || opts.response;
|
|
113
116
|
if (this.options.usersFilterToApply) {
|
|
114
117
|
const res = this.options.usersFilterToApply(opts.adminUser);
|
|
115
118
|
if (res === false) {
|
|
@@ -122,8 +125,8 @@ export default class TwoFactorsAuthPlugin extends AdminForthPlugin {
|
|
|
122
125
|
return { ok: true };
|
|
123
126
|
}
|
|
124
127
|
}
|
|
125
|
-
if (this.options.stepUpMfaGracePeriodSeconds && ((
|
|
126
|
-
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);
|
|
127
130
|
if (verificationResult === true) {
|
|
128
131
|
return { ok: true };
|
|
129
132
|
}
|
|
@@ -135,10 +138,10 @@ export default class TwoFactorsAuthPlugin extends AdminForthPlugin {
|
|
|
135
138
|
if (!authRes)
|
|
136
139
|
return { error: "Auth resource not found" };
|
|
137
140
|
const connector = this.adminforth.connectors[authRes.dataSource];
|
|
138
|
-
const pkName = (
|
|
141
|
+
const pkName = (_b = authRes.columns.find(c => c.primaryKey)) === null || _b === void 0 ? void 0 : _b.name;
|
|
139
142
|
if (!pkName)
|
|
140
143
|
return { error: "Primary key not found on auth resource" };
|
|
141
|
-
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];
|
|
142
145
|
if (!pk)
|
|
143
146
|
return { error: "User PK is required" };
|
|
144
147
|
const user = yield connector.getRecordByPrimaryKey(authRes, pk);
|
|
@@ -151,7 +154,7 @@ export default class TwoFactorsAuthPlugin extends AdminForthPlugin {
|
|
|
151
154
|
//* SET GRACE COOKIE *//
|
|
152
155
|
if (verified) {
|
|
153
156
|
if (this.options.stepUpMfaGracePeriodSeconds) {
|
|
154
|
-
this.issueTempSkip2FAGraceJWT(opts);
|
|
157
|
+
this.issueTempSkip2FAGraceJWT(opts, cookies, response);
|
|
155
158
|
}
|
|
156
159
|
return { ok: true };
|
|
157
160
|
}
|
|
@@ -161,7 +164,9 @@ export default class TwoFactorsAuthPlugin extends AdminForthPlugin {
|
|
|
161
164
|
;
|
|
162
165
|
}
|
|
163
166
|
else if (confirmationResult.mode === "passkey") {
|
|
164
|
-
|
|
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` });
|
|
165
170
|
if (!passkeysCookies) {
|
|
166
171
|
return { error: 'Passkey token is required' };
|
|
167
172
|
}
|
|
@@ -173,7 +178,7 @@ export default class TwoFactorsAuthPlugin extends AdminForthPlugin {
|
|
|
173
178
|
if (verificationResult.ok && verificationResult.passkeyConfirmed) {
|
|
174
179
|
//* SET GRACE COOKIE *//
|
|
175
180
|
if (this.options.stepUpMfaGracePeriodSeconds) {
|
|
176
|
-
this.issueTempSkip2FAGraceJWT(opts);
|
|
181
|
+
this.issueTempSkip2FAGraceJWT(opts, cookies, response);
|
|
177
182
|
}
|
|
178
183
|
return { ok: true };
|
|
179
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 ❗️❗️❗️");
|
|
@@ -116,9 +116,10 @@ export default class TwoFactorsAuthPlugin extends AdminForthPlugin {
|
|
|
116
116
|
opts?: { adminUser?: AdminUser; userPk?: string; cookies?: any, response?: IAdminForthHttpResponse, extra?: HttpExtra }
|
|
117
117
|
): Promise<{ ok: true } | { error: string }> {
|
|
118
118
|
if (!confirmationResult) return { error: "Confirmation result is required" };
|
|
119
|
-
if (!opts
|
|
120
|
-
|
|
121
|
-
|
|
119
|
+
if (!opts.adminUser) return { error: "Admin user is required" };
|
|
120
|
+
if (!opts.userPk) return { error: "User PK is required" };
|
|
121
|
+
const cookies = opts.extra.cookies || opts.cookies;
|
|
122
|
+
const response = opts.extra.response || opts.response;
|
|
122
123
|
if (this.options.usersFilterToApply) {
|
|
123
124
|
const res = this.options.usersFilterToApply(opts.adminUser);
|
|
124
125
|
if ( res === false ) {
|
|
@@ -132,7 +133,7 @@ export default class TwoFactorsAuthPlugin extends AdminForthPlugin {
|
|
|
132
133
|
}
|
|
133
134
|
}
|
|
134
135
|
if ( this.options.stepUpMfaGracePeriodSeconds && opts.extra?.headers && !confirmationResult.mode) {
|
|
135
|
-
const verificationResult = await this.isTempSkip2FAGraceValid(opts.extra.headers,
|
|
136
|
+
const verificationResult = await this.isTempSkip2FAGraceValid(opts.extra.headers, cookies);
|
|
136
137
|
if ( verificationResult === true ) {
|
|
137
138
|
return { ok: true };
|
|
138
139
|
}
|
|
@@ -163,14 +164,16 @@ export default class TwoFactorsAuthPlugin extends AdminForthPlugin {
|
|
|
163
164
|
//* SET GRACE COOKIE *//
|
|
164
165
|
if ( verified ) {
|
|
165
166
|
if (this.options.stepUpMfaGracePeriodSeconds) {
|
|
166
|
-
this.issueTempSkip2FAGraceJWT(opts);
|
|
167
|
+
this.issueTempSkip2FAGraceJWT(opts, cookies, response);
|
|
167
168
|
}
|
|
168
169
|
return { ok: true }
|
|
169
170
|
} else {
|
|
170
171
|
return { error: "Wrong or expired OTP code" }
|
|
171
172
|
};
|
|
172
173
|
} else if (confirmationResult.mode === "passkey") {
|
|
173
|
-
|
|
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`});
|
|
174
177
|
if (!passkeysCookies) {
|
|
175
178
|
return { error: 'Passkey token is required' };
|
|
176
179
|
}
|
|
@@ -185,7 +188,7 @@ export default class TwoFactorsAuthPlugin extends AdminForthPlugin {
|
|
|
185
188
|
|
|
186
189
|
//* SET GRACE COOKIE *//
|
|
187
190
|
if (this.options.stepUpMfaGracePeriodSeconds) {
|
|
188
|
-
this.issueTempSkip2FAGraceJWT(opts);
|
|
191
|
+
this.issueTempSkip2FAGraceJWT(opts, cookies, response);
|
|
189
192
|
}
|
|
190
193
|
return { ok: true }
|
|
191
194
|
}
|