najm-auth 4.2.1 → 4.2.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 +22 -4
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -2118,6 +2118,24 @@ CredentialSetupRequirementRepository = __decorate11([
|
|
|
2118
2118
|
// src/credentialSetup/types.ts
|
|
2119
2119
|
var PASSWORD_SETUP_PURPOSE = "password";
|
|
2120
2120
|
|
|
2121
|
+
// src/shared/storedTime.ts
|
|
2122
|
+
function storedTimeMs(value) {
|
|
2123
|
+
if (value instanceof Date)
|
|
2124
|
+
return value.getTime();
|
|
2125
|
+
const text3 = value.trim().replace(" ", "T");
|
|
2126
|
+
const time = text3.split("T")[1];
|
|
2127
|
+
if (!time)
|
|
2128
|
+
return Date.parse(text3);
|
|
2129
|
+
if (/Z$/i.test(time))
|
|
2130
|
+
return Date.parse(text3);
|
|
2131
|
+
const offset = /([+-])(\d{2}):?(\d{2})?$/.exec(time);
|
|
2132
|
+
if (!offset)
|
|
2133
|
+
return Date.parse(`${text3}Z`);
|
|
2134
|
+
const [zone, sign, hours, minutes = "00"] = offset;
|
|
2135
|
+
return Date.parse(`${text3.slice(0, -zone.length)}${sign}${hours}:${minutes}`);
|
|
2136
|
+
}
|
|
2137
|
+
__name(storedTimeMs, "storedTimeMs");
|
|
2138
|
+
|
|
2121
2139
|
// src/tokens/TokenService.ts
|
|
2122
2140
|
import { Err as Err7 } from "najm-core";
|
|
2123
2141
|
var __decorate12 = function(decorators, target, key, desc) {
|
|
@@ -2297,7 +2315,7 @@ var TokenService = class TokenService2 {
|
|
|
2297
2315
|
if (presentedHash === stored.token) {
|
|
2298
2316
|
return { userId, tokenFamily };
|
|
2299
2317
|
}
|
|
2300
|
-
const canRecover = stored.previousHash && presentedHash === stored.previousHash && stored.previousValidUntil &&
|
|
2318
|
+
const canRecover = stored.previousHash && presentedHash === stored.previousHash && stored.previousValidUntil && storedTimeMs(stored.previousValidUntil) > Date.now() && !stored.previousUsedAt;
|
|
2301
2319
|
if (canRecover) {
|
|
2302
2320
|
return { userId, tokenFamily };
|
|
2303
2321
|
}
|
|
@@ -2557,7 +2575,7 @@ var TokenService = class TokenService2 {
|
|
|
2557
2575
|
if (presentedHash === stored.token) {
|
|
2558
2576
|
return this.rotateTokens(userId, tokenFamily, stored.token);
|
|
2559
2577
|
}
|
|
2560
|
-
const canRecover = stored.previousHash && presentedHash === stored.previousHash && stored.previousValidUntil &&
|
|
2578
|
+
const canRecover = stored.previousHash && presentedHash === stored.previousHash && stored.previousValidUntil && storedTimeMs(stored.previousValidUntil) > Date.now() && !stored.previousUsedAt;
|
|
2561
2579
|
if (canRecover) {
|
|
2562
2580
|
const claimed = await this.tokenRepository.markPreviousUsed(tokenFamily, presentedHash);
|
|
2563
2581
|
if (!claimed?.length) {
|
|
@@ -2695,7 +2713,7 @@ var TokenService = class TokenService2 {
|
|
|
2695
2713
|
if (presentedHash === stored.token) {
|
|
2696
2714
|
return decoded.tokenFamily;
|
|
2697
2715
|
}
|
|
2698
|
-
const canRecover = stored.previousHash && presentedHash === stored.previousHash && stored.previousValidUntil &&
|
|
2716
|
+
const canRecover = stored.previousHash && presentedHash === stored.previousHash && stored.previousValidUntil && storedTimeMs(stored.previousValidUntil) > Date.now() && !stored.previousUsedAt;
|
|
2699
2717
|
return canRecover ? decoded.tokenFamily : null;
|
|
2700
2718
|
} catch {
|
|
2701
2719
|
return null;
|
|
@@ -3503,7 +3521,7 @@ var AuthService = class AuthService2 {
|
|
|
3503
3521
|
isLockoutActive(lockoutUntil) {
|
|
3504
3522
|
if (!lockoutUntil)
|
|
3505
3523
|
return false;
|
|
3506
|
-
return
|
|
3524
|
+
return storedTimeMs(lockoutUntil) > Date.now();
|
|
3507
3525
|
}
|
|
3508
3526
|
nextLockoutUntil() {
|
|
3509
3527
|
const durationMs = timestring4(this.config.lockout.duration, "ms");
|