@adminforth/two-factors-auth 2.9.18 → 2.9.20
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 +9 -10
- package/index.ts +9 -11
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -306,8 +306,8 @@ export default class TwoFactorsAuthPlugin extends AdminForthPlugin {
|
|
|
306
306
|
}
|
|
307
307
|
const beforeLoginConfirmation = this.adminforth.config.auth.beforeLoginConfirmation;
|
|
308
308
|
const beforeLoginConfirmationArray = Array.isArray(beforeLoginConfirmation) ? beforeLoginConfirmation : [beforeLoginConfirmation];
|
|
309
|
-
beforeLoginConfirmationArray.push((_a) => __awaiter(this, [_a], void 0, function* ({ adminUser, response, adminforth, extra,
|
|
310
|
-
var _b, _c, _d
|
|
309
|
+
beforeLoginConfirmationArray.push((_a) => __awaiter(this, [_a], void 0, function* ({ adminUser, response, adminforth, extra, sessionDuration }) {
|
|
310
|
+
var _b, _c, _d;
|
|
311
311
|
if (((_b = extra === null || extra === void 0 ? void 0 : extra.meta) === null || _b === void 0 ? void 0 : _b.loginAllowedByPasskeyDirectSignIn) === true) {
|
|
312
312
|
return { body: { loginAllowed: true }, ok: true };
|
|
313
313
|
}
|
|
@@ -321,8 +321,6 @@ export default class TwoFactorsAuthPlugin extends AdminForthPlugin {
|
|
|
321
321
|
const authResource = adminforth.config.resources.find((res) => res.resourceId === adminforth.config.auth.usersResourceId);
|
|
322
322
|
const authPk = authResource.columns.find((col) => col.primaryKey).name;
|
|
323
323
|
const userPk = adminUser.dbUser[authPk];
|
|
324
|
-
const rememberMe = ((_c = extra === null || extra === void 0 ? void 0 : extra.body) === null || _c === void 0 ? void 0 : _c.rememberMe) || false;
|
|
325
|
-
// const rememberMeDays = rememberMe ? adminforth.config.auth.rememberMeDays || 30 : 1;
|
|
326
324
|
let newSecret = null;
|
|
327
325
|
const userNeeds2FA = this.options.usersFilterToApply ? this.options.usersFilterToApply(adminUser) : true;
|
|
328
326
|
if (!userNeeds2FA) {
|
|
@@ -332,7 +330,7 @@ export default class TwoFactorsAuthPlugin extends AdminForthPlugin {
|
|
|
332
330
|
if (!secret) {
|
|
333
331
|
const tempSecret = twofactor.generateSecret({ name: issuerName, account: userName });
|
|
334
332
|
newSecret = tempSecret.secret;
|
|
335
|
-
const totpTemporaryJWT = this.adminforth.auth.issueJWT({ userName, newSecret, issuer: issuerName, pk: userPk, userCanSkipSetup,
|
|
333
|
+
const totpTemporaryJWT = this.adminforth.auth.issueJWT({ userName, newSecret, issuer: issuerName, pk: userPk, userCanSkipSetup, sessionDuration }, 'temp2FA', ((_c = this.options.passkeys) === null || _c === void 0 ? void 0 : _c.challengeValidityPeriod) || '1m');
|
|
336
334
|
this.adminforth.auth.setCustomCookie({ response, payload: { name: "2FaTemporaryJWT", value: totpTemporaryJWT, expiry: undefined, expirySeconds: 10 * 60, httpOnly: true } });
|
|
337
335
|
return {
|
|
338
336
|
body: {
|
|
@@ -343,7 +341,7 @@ export default class TwoFactorsAuthPlugin extends AdminForthPlugin {
|
|
|
343
341
|
};
|
|
344
342
|
}
|
|
345
343
|
else {
|
|
346
|
-
const value = this.adminforth.auth.issueJWT({ userName, issuer: issuerName, pk: userPk, userCanSkipSetup,
|
|
344
|
+
const value = this.adminforth.auth.issueJWT({ userName, issuer: issuerName, pk: userPk, userCanSkipSetup, sessionDuration }, 'temp2FA', ((_d = this.options.passkeys) === null || _d === void 0 ? void 0 : _d.challengeValidityPeriod) || '1m');
|
|
347
345
|
this.adminforth.auth.setCustomCookie({ response, payload: { name: "2FaTemporaryJWT", value: value, expiry: undefined, expirySeconds: 10 * 60, httpOnly: true } });
|
|
348
346
|
return {
|
|
349
347
|
body: {
|
|
@@ -394,7 +392,7 @@ export default class TwoFactorsAuthPlugin extends AdminForthPlugin {
|
|
|
394
392
|
yield connector.updateRecord({ resource: this.authResource, recordId: decoded.pk, newValues: { [this.options.twoFaSecretFieldName]: decoded.newSecret } });
|
|
395
393
|
}
|
|
396
394
|
this.adminforth.auth.removeCustomCookie({ response, name: '2FaTemporaryJWT' });
|
|
397
|
-
this.adminforth.auth.setAuthCookie({
|
|
395
|
+
this.adminforth.auth.setAuthCookie({ expireInDuration: decoded.sessionDuration, response, username: decoded.userName, pk: decoded.pk });
|
|
398
396
|
return { status: 'ok', allowedLogin: true };
|
|
399
397
|
}
|
|
400
398
|
else {
|
|
@@ -428,7 +426,7 @@ export default class TwoFactorsAuthPlugin extends AdminForthPlugin {
|
|
|
428
426
|
}
|
|
429
427
|
if (verified) {
|
|
430
428
|
this.adminforth.auth.removeCustomCookie({ response, name: '2FaTemporaryJWT' });
|
|
431
|
-
this.adminforth.auth.setAuthCookie({
|
|
429
|
+
this.adminforth.auth.setAuthCookie({ expireInDuration: decoded.sessionDuration, response, username: decoded.userName, pk: decoded.pk });
|
|
432
430
|
return { status: 'ok', allowedLogin: true };
|
|
433
431
|
}
|
|
434
432
|
else {
|
|
@@ -505,13 +503,14 @@ export default class TwoFactorsAuthPlugin extends AdminForthPlugin {
|
|
|
505
503
|
meta: {
|
|
506
504
|
loginAllowedByPasskeyDirectSignIn: true
|
|
507
505
|
},
|
|
508
|
-
}, rememberMe ? this.adminforth.config.auth.
|
|
506
|
+
}, rememberMe ? this.adminforth.config.auth.rememberMeDuration || '30d' : '1d');
|
|
507
|
+
const rememberDaysAfterPasskeyLogin = (this.options.passkeys.rememberDaysAfterPasskeyLogin ? this.options.passkeys.rememberDaysAfterPasskeyLogin.toString().concat('d') : null);
|
|
509
508
|
if (toReturn.allowedLogin === true) {
|
|
510
509
|
this.adminforth.auth.setAuthCookie({
|
|
511
510
|
response,
|
|
512
511
|
username,
|
|
513
512
|
pk: user.id,
|
|
514
|
-
|
|
513
|
+
expireInDuration: rememberDaysAfterPasskeyLogin ? rememberDaysAfterPasskeyLogin : this.adminforth.config.auth.rememberMeDuration,
|
|
515
514
|
});
|
|
516
515
|
}
|
|
517
516
|
return toReturn;
|
package/index.ts
CHANGED
|
@@ -341,7 +341,7 @@ export default class TwoFactorsAuthPlugin extends AdminForthPlugin {
|
|
|
341
341
|
const beforeLoginConfirmation = this.adminforth.config.auth.beforeLoginConfirmation;
|
|
342
342
|
const beforeLoginConfirmationArray = Array.isArray(beforeLoginConfirmation) ? beforeLoginConfirmation : [beforeLoginConfirmation];
|
|
343
343
|
beforeLoginConfirmationArray.push(
|
|
344
|
-
async({ adminUser, response, adminforth, extra,
|
|
344
|
+
async({ adminUser, response, adminforth, extra, sessionDuration }: { adminUser: AdminUser, response: IAdminForthHttpResponse, adminforth: IAdminForth, extra?: HttpExtra, sessionDuration?: string} )=> {
|
|
345
345
|
if ( extra?.meta?.loginAllowedByPasskeyDirectSignIn === true) {
|
|
346
346
|
return { body: { loginAllowed: true }, ok: true };
|
|
347
347
|
}
|
|
@@ -355,8 +355,6 @@ export default class TwoFactorsAuthPlugin extends AdminForthPlugin {
|
|
|
355
355
|
const authResource = adminforth.config.resources.find((res)=>res.resourceId === adminforth.config.auth.usersResourceId )
|
|
356
356
|
const authPk = authResource.columns.find((col)=>col.primaryKey).name
|
|
357
357
|
const userPk = adminUser.dbUser[authPk]
|
|
358
|
-
const rememberMe = extra?.body?.rememberMe || false;
|
|
359
|
-
// const rememberMeDays = rememberMe ? adminforth.config.auth.rememberMeDays || 30 : 1;
|
|
360
358
|
let newSecret = null;
|
|
361
359
|
|
|
362
360
|
const userNeeds2FA = this.options.usersFilterToApply ? this.options.usersFilterToApply(adminUser) : true;
|
|
@@ -368,8 +366,7 @@ export default class TwoFactorsAuthPlugin extends AdminForthPlugin {
|
|
|
368
366
|
if (!secret){
|
|
369
367
|
const tempSecret = twofactor.generateSecret({name: issuerName,account: userName})
|
|
370
368
|
newSecret = tempSecret.secret;
|
|
371
|
-
|
|
372
|
-
const totpTemporaryJWT = this.adminforth.auth.issueJWT({userName, newSecret, issuer:issuerName, pk:userPk, userCanSkipSetup, rememberMeDays }, 'temp2FA', this.options.passkeys?.challengeValidityPeriod || '1m');
|
|
369
|
+
const totpTemporaryJWT = this.adminforth.auth.issueJWT({userName, newSecret, issuer:issuerName, pk:userPk, userCanSkipSetup, sessionDuration }, 'temp2FA', this.options.passkeys?.challengeValidityPeriod || '1m');
|
|
373
370
|
this.adminforth.auth.setCustomCookie({response, payload: {name: "2FaTemporaryJWT", value: totpTemporaryJWT, expiry: undefined, expirySeconds: 10 * 60, httpOnly: true}});
|
|
374
371
|
|
|
375
372
|
return {
|
|
@@ -381,7 +378,7 @@ export default class TwoFactorsAuthPlugin extends AdminForthPlugin {
|
|
|
381
378
|
}
|
|
382
379
|
|
|
383
380
|
} else {
|
|
384
|
-
const value = this.adminforth.auth.issueJWT({userName, issuer:issuerName, pk:userPk, userCanSkipSetup,
|
|
381
|
+
const value = this.adminforth.auth.issueJWT({userName, issuer:issuerName, pk:userPk, userCanSkipSetup, sessionDuration }, 'temp2FA', this.options.passkeys?.challengeValidityPeriod || '1m');
|
|
385
382
|
this.adminforth.auth.setCustomCookie({response, payload: {name: "2FaTemporaryJWT", value: value, expiry: undefined, expirySeconds: 10 * 60, httpOnly: true}});
|
|
386
383
|
|
|
387
384
|
return {
|
|
@@ -437,7 +434,7 @@ export default class TwoFactorsAuthPlugin extends AdminForthPlugin {
|
|
|
437
434
|
await connector.updateRecord({resource:this.authResource, recordId:decoded.pk, newValues:{[this.options.twoFaSecretFieldName]: decoded.newSecret}})
|
|
438
435
|
}
|
|
439
436
|
this.adminforth.auth.removeCustomCookie({response, name:'2FaTemporaryJWT'})
|
|
440
|
-
this.adminforth.auth.setAuthCookie({
|
|
437
|
+
this.adminforth.auth.setAuthCookie({expireInDuration: decoded.sessionDuration, response, username:decoded.userName, pk:decoded.pk})
|
|
441
438
|
return { status: 'ok', allowedLogin: true }
|
|
442
439
|
} else {
|
|
443
440
|
return {error: 'Wrong or expired OTP code'}
|
|
@@ -468,7 +465,7 @@ export default class TwoFactorsAuthPlugin extends AdminForthPlugin {
|
|
|
468
465
|
}
|
|
469
466
|
if (verified) {
|
|
470
467
|
this.adminforth.auth.removeCustomCookie({response, name:'2FaTemporaryJWT'})
|
|
471
|
-
this.adminforth.auth.setAuthCookie({
|
|
468
|
+
this.adminforth.auth.setAuthCookie({expireInDuration: decoded.sessionDuration, response, username:decoded.userName, pk:decoded.pk})
|
|
472
469
|
return { status: 'ok', allowedLogin: true }
|
|
473
470
|
} else {
|
|
474
471
|
return {error: 'Verification failed'}
|
|
@@ -559,16 +556,17 @@ export default class TwoFactorsAuthPlugin extends AdminForthPlugin {
|
|
|
559
556
|
loginAllowedByPasskeyDirectSignIn: true
|
|
560
557
|
},
|
|
561
558
|
},
|
|
562
|
-
rememberMe ? this.adminforth.config.auth.
|
|
559
|
+
rememberMe ? this.adminforth.config.auth.rememberMeDuration || '30d' : '1d',
|
|
563
560
|
|
|
564
561
|
);
|
|
565
|
-
|
|
562
|
+
|
|
563
|
+
const rememberDaysAfterPasskeyLogin = (this.options.passkeys.rememberDaysAfterPasskeyLogin ? this.options.passkeys.rememberDaysAfterPasskeyLogin.toString().concat('d') : null);
|
|
566
564
|
if ( toReturn.allowedLogin === true ) {
|
|
567
565
|
this.adminforth.auth.setAuthCookie({
|
|
568
566
|
response,
|
|
569
567
|
username,
|
|
570
568
|
pk: user.id,
|
|
571
|
-
|
|
569
|
+
expireInDuration: rememberDaysAfterPasskeyLogin ? rememberDaysAfterPasskeyLogin : this.adminforth.config.auth.rememberMeDuration,
|
|
572
570
|
});
|
|
573
571
|
}
|
|
574
572
|
return toReturn;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@adminforth/two-factors-auth",
|
|
3
|
-
"version": "2.9.
|
|
3
|
+
"version": "2.9.20",
|
|
4
4
|
"description": "AdminForth plugin for two factors authentication",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
"node-2fa": "^2.0.3"
|
|
30
30
|
},
|
|
31
31
|
"peerDependencies": {
|
|
32
|
-
"adminforth": "
|
|
32
|
+
"adminforth": "next"
|
|
33
33
|
},
|
|
34
34
|
"devDependencies": {
|
|
35
35
|
"@types/node": "^22.10.7",
|