@bymax-one/nest-auth 1.5.6 → 1.5.7
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/CHANGELOG.md +49 -1
- package/README.md +7 -1
- package/dist/react/index.cjs +3 -1
- package/dist/react/index.d.cts +3 -0
- package/dist/react/index.d.ts +3 -0
- package/dist/react/index.mjs +3 -1
- package/dist/server/index.cjs +178 -82
- package/dist/server/index.d.cts +71 -13
- package/dist/server/index.d.ts +71 -13
- package/dist/server/index.mjs +178 -83
- package/package.json +1 -1
package/dist/server/index.mjs
CHANGED
|
@@ -2428,6 +2428,42 @@ var AuthException = class extends HttpException {
|
|
|
2428
2428
|
}
|
|
2429
2429
|
};
|
|
2430
2430
|
|
|
2431
|
+
// src/server/redis/create-session-script.ts
|
|
2432
|
+
var CREATE_SESSION_LUA = `
|
|
2433
|
+
-- The commands that can fail on a key of the wrong type come FIRST: Redis does not undo the
|
|
2434
|
+
-- writes a script made before one of its commands fails, so an error here must leave no refresh
|
|
2435
|
+
-- record behind. The index and the family are the only keys this script adds to a set.
|
|
2436
|
+
redis.call('SADD', KEYS[2], ARGV[4] .. ':' .. ARGV[5])
|
|
2437
|
+
redis.call('EXPIRE', KEYS[2], ARGV[2])
|
|
2438
|
+
-- The family index holds bare hashes: it only ever tracks live sessions, so the prefix is
|
|
2439
|
+
-- implied. A session with no lineage skips it rather than writing an unkeyed member.
|
|
2440
|
+
if ARGV[3] ~= '' then
|
|
2441
|
+
redis.call('SADD', KEYS[3], ARGV[5])
|
|
2442
|
+
redis.call('EXPIRE', KEYS[3], ARGV[2])
|
|
2443
|
+
end
|
|
2444
|
+
redis.call('SET', KEYS[1], ARGV[1], 'EX', ARGV[2])
|
|
2445
|
+
-- The records of the session itself, each with its own lifetime.
|
|
2446
|
+
for i = 4, #KEYS do
|
|
2447
|
+
redis.call('SET', KEYS[i], ARGV[2 * i - 2], 'EX', ARGV[2 * i - 1])
|
|
2448
|
+
end
|
|
2449
|
+
return 1
|
|
2450
|
+
`;
|
|
2451
|
+
function sessionExtraArgs(extras) {
|
|
2452
|
+
for (const { key, value, ttl } of extras) {
|
|
2453
|
+
if (key === "" || value === "" || !Number.isInteger(ttl) || ttl <= 0) {
|
|
2454
|
+
throw new TypeError("A session record needs a key, a value and a positive whole-second TTL.");
|
|
2455
|
+
}
|
|
2456
|
+
}
|
|
2457
|
+
return {
|
|
2458
|
+
keys: extras.map(({ key }) => key),
|
|
2459
|
+
argv: extras.flatMap(({ value, ttl }) => [
|
|
2460
|
+
value,
|
|
2461
|
+
String(ttl)
|
|
2462
|
+
])
|
|
2463
|
+
};
|
|
2464
|
+
}
|
|
2465
|
+
__name(sessionExtraArgs, "sessionExtraArgs");
|
|
2466
|
+
|
|
2431
2467
|
// src/server/redis/redis-outage.ts
|
|
2432
2468
|
var MESSAGE_KINDS = /* @__PURE__ */ new Map([
|
|
2433
2469
|
[
|
|
@@ -2588,18 +2624,6 @@ if ARGV[3] ~= '' then
|
|
|
2588
2624
|
end
|
|
2589
2625
|
return 1
|
|
2590
2626
|
`;
|
|
2591
|
-
var CREATE_SESSION_LUA = `
|
|
2592
|
-
redis.call('SET', KEYS[1], ARGV[1], 'EX', ARGV[2])
|
|
2593
|
-
redis.call('SADD', KEYS[2], ARGV[4] .. ':' .. ARGV[5])
|
|
2594
|
-
redis.call('EXPIRE', KEYS[2], ARGV[2])
|
|
2595
|
-
-- The family index holds bare hashes: it only ever tracks live sessions, so the prefix is
|
|
2596
|
-
-- implied. A session with no lineage skips it rather than writing an unkeyed member.
|
|
2597
|
-
if ARGV[3] ~= '' then
|
|
2598
|
-
redis.call('SADD', KEYS[3], ARGV[5])
|
|
2599
|
-
redis.call('EXPIRE', KEYS[3], ARGV[2])
|
|
2600
|
-
end
|
|
2601
|
-
return 1
|
|
2602
|
-
`;
|
|
2603
2627
|
var ROTATE_LUA = `
|
|
2604
2628
|
local old = redis.call('GET', KEYS[1])
|
|
2605
2629
|
if old then
|
|
@@ -2953,18 +2977,21 @@ var AuthRedisService = class {
|
|
|
2953
2977
|
*/
|
|
2954
2978
|
async writeNewSession(params) {
|
|
2955
2979
|
const p = prefixesFor(params.kind);
|
|
2980
|
+
const extra = sessionExtraArgs(params.extras ?? []);
|
|
2956
2981
|
await this.eval(CREATE_SESSION_LUA, [
|
|
2957
2982
|
`${p.live}:${params.tokenHash}`,
|
|
2958
2983
|
sessionIndexKey(params.kind, params.userId, this.#hmacKey, params.tenantId),
|
|
2959
2984
|
// Always passed, even with no family: a Lua script's key list is fixed at the call
|
|
2960
2985
|
// site, and the script skips the key rather than the caller skipping the argument.
|
|
2961
|
-
`${p.family}:${params.familyId}
|
|
2986
|
+
`${p.family}:${params.familyId}`,
|
|
2987
|
+
...extra.keys
|
|
2962
2988
|
], [
|
|
2963
2989
|
params.sessionJson,
|
|
2964
2990
|
String(params.refreshTtl),
|
|
2965
2991
|
params.familyId,
|
|
2966
2992
|
p.live,
|
|
2967
|
-
params.tokenHash
|
|
2993
|
+
params.tokenHash,
|
|
2994
|
+
...extra.argv
|
|
2968
2995
|
]);
|
|
2969
2996
|
}
|
|
2970
2997
|
/**
|
|
@@ -4643,7 +4670,7 @@ function cacheKeysFor(ref, hmacKey) {
|
|
|
4643
4670
|
};
|
|
4644
4671
|
}
|
|
4645
4672
|
__name(cacheKeysFor, "cacheKeysFor");
|
|
4646
|
-
var AccountStatusService = class {
|
|
4673
|
+
var AccountStatusService = class _AccountStatusService {
|
|
4647
4674
|
static {
|
|
4648
4675
|
__name(this, "AccountStatusService");
|
|
4649
4676
|
}
|
|
@@ -4651,6 +4678,7 @@ var AccountStatusService = class {
|
|
|
4651
4678
|
userRepo;
|
|
4652
4679
|
options;
|
|
4653
4680
|
platformUserRepo;
|
|
4681
|
+
logger = new Logger(_AccountStatusService.name);
|
|
4654
4682
|
/**
|
|
4655
4683
|
* @param redis - The auth module's Redis service, holding the status and verified caches.
|
|
4656
4684
|
* @param userRepo - The consumer's dashboard user repository, read on a cache miss.
|
|
@@ -4738,10 +4766,10 @@ var AccountStatusService = class {
|
|
|
4738
4766
|
throw new AuthException(AUTH_ERROR_CODES.TOKEN_INVALID);
|
|
4739
4767
|
}
|
|
4740
4768
|
status = userRecord.status;
|
|
4741
|
-
await this.
|
|
4769
|
+
await this.fillCache(statusKey, status, cacheTtl);
|
|
4742
4770
|
if (requireVerified) {
|
|
4743
4771
|
verified = userRecord.emailVerified ? "1" : "0";
|
|
4744
|
-
await this.
|
|
4772
|
+
await this.fillCache(verifiedKey, verified, cacheTtl);
|
|
4745
4773
|
}
|
|
4746
4774
|
}
|
|
4747
4775
|
assertNotBlocked(status, this.options.blockedStatuses);
|
|
@@ -4750,6 +4778,25 @@ var AccountStatusService = class {
|
|
|
4750
4778
|
}
|
|
4751
4779
|
}
|
|
4752
4780
|
/**
|
|
4781
|
+
* Stores one cached fact, best effort.
|
|
4782
|
+
*
|
|
4783
|
+
* The repository has already answered when this runs, so the decision does not depend on the
|
|
4784
|
+
* write: a store that cannot take it must not turn that decision into an error, and above all
|
|
4785
|
+
* must not answer a blocked account with an outage a client retries. A failed write is logged
|
|
4786
|
+
* without the store's text and the next request reads the repository again.
|
|
4787
|
+
*
|
|
4788
|
+
* @param key - The cache key.
|
|
4789
|
+
* @param value - The fact just read from the repository.
|
|
4790
|
+
* @param ttl - The cache lifetime in seconds.
|
|
4791
|
+
*/
|
|
4792
|
+
async fillCache(key, value, ttl) {
|
|
4793
|
+
try {
|
|
4794
|
+
await this.redis.set(key, value, ttl);
|
|
4795
|
+
} catch (err) {
|
|
4796
|
+
this.logger.warn(`account status cache write failed, the next request reads the repository again: ${describeChannelStatus(err)}`);
|
|
4797
|
+
}
|
|
4798
|
+
}
|
|
4799
|
+
/**
|
|
4753
4800
|
* The same decision as {@link assertDashboardAccountUsable}, read from the repository now.
|
|
4754
4801
|
*
|
|
4755
4802
|
* Neither reads nor writes the status cache, so the answer is as current as the repository:
|
|
@@ -5634,6 +5681,63 @@ function runDetached(logger, run, failure) {
|
|
|
5634
5681
|
}
|
|
5635
5682
|
__name(runDetached, "runDetached");
|
|
5636
5683
|
|
|
5684
|
+
// src/server/utils/session-detail.ts
|
|
5685
|
+
var MAX_SESSION_FIELD_LENGTH = 45;
|
|
5686
|
+
function parseUserAgent(ua) {
|
|
5687
|
+
let browser = "Unknown Browser";
|
|
5688
|
+
if (/Edg\//.test(ua)) {
|
|
5689
|
+
browser = "Edge";
|
|
5690
|
+
} else if (/OPR\/|Opera/.test(ua)) {
|
|
5691
|
+
browser = "Opera";
|
|
5692
|
+
} else if (/Chrome\//.test(ua)) {
|
|
5693
|
+
browser = "Chrome";
|
|
5694
|
+
} else if (/Firefox\//.test(ua)) {
|
|
5695
|
+
browser = "Firefox";
|
|
5696
|
+
} else if (/Safari\//.test(ua) && /Version\//.test(ua)) {
|
|
5697
|
+
browser = "Safari";
|
|
5698
|
+
}
|
|
5699
|
+
let os = "Unknown OS";
|
|
5700
|
+
if (/Android/.test(ua)) {
|
|
5701
|
+
os = "Android";
|
|
5702
|
+
} else if (/iPhone|iPad|iPod/.test(ua)) {
|
|
5703
|
+
os = "iOS";
|
|
5704
|
+
} else if (/Windows/.test(ua)) {
|
|
5705
|
+
os = "Windows";
|
|
5706
|
+
} else if (/Macintosh|Mac OS X/.test(ua)) {
|
|
5707
|
+
os = "macOS";
|
|
5708
|
+
} else if (/Linux/.test(ua)) {
|
|
5709
|
+
os = "Linux";
|
|
5710
|
+
}
|
|
5711
|
+
return `${browser} on ${os}`;
|
|
5712
|
+
}
|
|
5713
|
+
__name(parseUserAgent, "parseUserAgent");
|
|
5714
|
+
function dashboardSessionDetail(ip, userAgent, now3) {
|
|
5715
|
+
return JSON.stringify({
|
|
5716
|
+
device: parseUserAgent(userAgent),
|
|
5717
|
+
ip: ip.slice(0, MAX_SESSION_FIELD_LENGTH),
|
|
5718
|
+
createdAt: now3,
|
|
5719
|
+
lastActivityAt: now3
|
|
5720
|
+
});
|
|
5721
|
+
}
|
|
5722
|
+
__name(dashboardSessionDetail, "dashboardSessionDetail");
|
|
5723
|
+
function platformSessionDetail(ip, userAgent, now3) {
|
|
5724
|
+
return JSON.stringify({
|
|
5725
|
+
device: userAgent.slice(0, MAX_SESSION_FIELD_LENGTH),
|
|
5726
|
+
ip: ip.slice(0, MAX_SESSION_FIELD_LENGTH),
|
|
5727
|
+
createdAt: now3,
|
|
5728
|
+
lastActivityAt: now3
|
|
5729
|
+
});
|
|
5730
|
+
}
|
|
5731
|
+
__name(platformSessionDetail, "platformSessionDetail");
|
|
5732
|
+
function platformSessionExtra(tokenHash, ip, userAgent, ttl) {
|
|
5733
|
+
return {
|
|
5734
|
+
key: `psd:${tokenHash}`,
|
|
5735
|
+
value: platformSessionDetail(ip, userAgent, Date.now()),
|
|
5736
|
+
ttl
|
|
5737
|
+
};
|
|
5738
|
+
}
|
|
5739
|
+
__name(platformSessionExtra, "platformSessionExtra");
|
|
5740
|
+
|
|
5637
5741
|
// src/server/utils/settle-writes.ts
|
|
5638
5742
|
async function settleWrites(writes) {
|
|
5639
5743
|
const failures = [];
|
|
@@ -5721,34 +5825,6 @@ function parseStoredDetail(raw) {
|
|
|
5721
5825
|
}
|
|
5722
5826
|
}
|
|
5723
5827
|
__name(parseStoredDetail, "parseStoredDetail");
|
|
5724
|
-
function parseUserAgent(ua) {
|
|
5725
|
-
let browser = "Unknown Browser";
|
|
5726
|
-
if (/Edg\//.test(ua)) {
|
|
5727
|
-
browser = "Edge";
|
|
5728
|
-
} else if (/OPR\/|Opera/.test(ua)) {
|
|
5729
|
-
browser = "Opera";
|
|
5730
|
-
} else if (/Chrome\//.test(ua)) {
|
|
5731
|
-
browser = "Chrome";
|
|
5732
|
-
} else if (/Firefox\//.test(ua)) {
|
|
5733
|
-
browser = "Firefox";
|
|
5734
|
-
} else if (/Safari\//.test(ua) && /Version\//.test(ua)) {
|
|
5735
|
-
browser = "Safari";
|
|
5736
|
-
}
|
|
5737
|
-
let os = "Unknown OS";
|
|
5738
|
-
if (/Android/.test(ua)) {
|
|
5739
|
-
os = "Android";
|
|
5740
|
-
} else if (/iPhone|iPad|iPod/.test(ua)) {
|
|
5741
|
-
os = "iOS";
|
|
5742
|
-
} else if (/Windows/.test(ua)) {
|
|
5743
|
-
os = "Windows";
|
|
5744
|
-
} else if (/Macintosh|Mac OS X/.test(ua)) {
|
|
5745
|
-
os = "macOS";
|
|
5746
|
-
} else if (/Linux/.test(ua)) {
|
|
5747
|
-
os = "Linux";
|
|
5748
|
-
}
|
|
5749
|
-
return `${browser} on ${os}`;
|
|
5750
|
-
}
|
|
5751
|
-
__name(parseUserAgent, "parseUserAgent");
|
|
5752
5828
|
function toSafeUser(user) {
|
|
5753
5829
|
const { passwordHash: _p, mfaSecret: _s, mfaRecoveryCodes: _r, ...safe } = user;
|
|
5754
5830
|
return safe;
|
|
@@ -5805,10 +5881,10 @@ var SessionService = class _SessionService {
|
|
|
5805
5881
|
/**
|
|
5806
5882
|
* Records a new session in Redis and enforces the concurrent session limit.
|
|
5807
5883
|
*
|
|
5808
|
-
*
|
|
5809
|
-
*
|
|
5810
|
-
* session when the user has exceeded
|
|
5811
|
-
* hook (fire-and-forget)
|
|
5884
|
+
* The device and activity record under `sd:{hash}` is written with the session itself, by
|
|
5885
|
+
* `TokenManagerService.issueTokens`, so it cannot be missing for a session that exists. This
|
|
5886
|
+
* method calls `enforceSessionLimit` to evict the oldest session when the user has exceeded
|
|
5887
|
+
* their limit, and fires the `onNewSession` hook (fire-and-forget).
|
|
5812
5888
|
*
|
|
5813
5889
|
* @remarks
|
|
5814
5890
|
* **Caller ordering contract:** This method must be called **after**
|
|
@@ -5826,17 +5902,6 @@ var SessionService = class _SessionService {
|
|
|
5826
5902
|
this.assertTenant(tenantId);
|
|
5827
5903
|
const hash = sha256(rawRefreshToken);
|
|
5828
5904
|
const device = parseUserAgent(userAgent);
|
|
5829
|
-
const now3 = Date.now();
|
|
5830
|
-
const ttl = this.options.jwt.refreshExpiresInDays * 86400;
|
|
5831
|
-
const detail = {
|
|
5832
|
-
device,
|
|
5833
|
-
// Truncate to MAX_IP_LENGTH before storage to guard against oversized
|
|
5834
|
-
// attacker-controlled values arriving via X-Forwarded-For.
|
|
5835
|
-
ip: ip.slice(0, MAX_IP_LENGTH),
|
|
5836
|
-
createdAt: now3,
|
|
5837
|
-
lastActivityAt: now3
|
|
5838
|
-
};
|
|
5839
|
-
await this.redis.set(`sd:${hash}`, JSON.stringify(detail), ttl);
|
|
5840
5905
|
await this.enforceSessionLimit(userId, tenantId, hash, ip, userAgent);
|
|
5841
5906
|
if (this.hooks?.onNewSession) {
|
|
5842
5907
|
const { onNewSession } = this.hooks;
|
|
@@ -6447,7 +6512,6 @@ function _ts_param13(paramIndex, decorator) {
|
|
|
6447
6512
|
}
|
|
6448
6513
|
__name(_ts_param13, "_ts_param");
|
|
6449
6514
|
var MFA_TEMP_TOKEN_TTL_SECONDS = 300;
|
|
6450
|
-
var MAX_SESSION_FIELD_LENGTH = 45;
|
|
6451
6515
|
var CREDENTIAL_PROVED = {
|
|
6452
6516
|
credentialProved: true
|
|
6453
6517
|
};
|
|
@@ -6570,6 +6634,7 @@ var TokenManagerService = class _TokenManagerService {
|
|
|
6570
6634
|
const tokenHash = sha256(rawRefreshToken);
|
|
6571
6635
|
const session = this.buildSession(user.id, user.tenantId, user.role, ip, userAgent, user.mfaEnabled, familyId, void 0, overrides?.mfaVerified === true);
|
|
6572
6636
|
const ttl = this.options.jwt.refreshExpiresInDays * 86400;
|
|
6637
|
+
const proved = overrides?.credentialProved === true;
|
|
6573
6638
|
await this.redis.writeNewSession({
|
|
6574
6639
|
kind: "dashboard",
|
|
6575
6640
|
tenantId: user.tenantId,
|
|
@@ -6577,9 +6642,9 @@ var TokenManagerService = class _TokenManagerService {
|
|
|
6577
6642
|
sessionJson: serializeSession(session),
|
|
6578
6643
|
familyId,
|
|
6579
6644
|
userId: user.id,
|
|
6580
|
-
refreshTtl: ttl
|
|
6645
|
+
refreshTtl: ttl,
|
|
6646
|
+
extras: this.dashboardExtras(user, familyId, tokenHash, ttl, ip, userAgent, proved)
|
|
6581
6647
|
});
|
|
6582
|
-
if (overrides?.credentialProved === true) await this.markRecentAuth(user, familyId);
|
|
6583
6648
|
return {
|
|
6584
6649
|
user,
|
|
6585
6650
|
accessToken,
|
|
@@ -6587,14 +6652,32 @@ var TokenManagerService = class _TokenManagerService {
|
|
|
6587
6652
|
};
|
|
6588
6653
|
}
|
|
6589
6654
|
/**
|
|
6590
|
-
*
|
|
6655
|
+
* The records a new dashboard session is written with, beyond the session itself.
|
|
6591
6656
|
*
|
|
6592
|
-
*
|
|
6593
|
-
* possession of a token, so `reissueTokens` never writes
|
|
6594
|
-
* another session of the same account cannot
|
|
6657
|
+
* The recent-authentication mark is there only when a credential was presented in this request;
|
|
6658
|
+
* a refresh proves possession of a token, so `reissueTokens` never writes it. It keeps its own
|
|
6659
|
+
* short lifetime and its key names the session, so another session of the same account cannot
|
|
6660
|
+
* use it. The session detail is there only when sessions are enabled.
|
|
6595
6661
|
*/
|
|
6596
|
-
|
|
6597
|
-
|
|
6662
|
+
dashboardExtras(user, sid, tokenHash, ttl, ip, userAgent, proved) {
|
|
6663
|
+
const markKey = recentAuthKey("dashboard", user.id, this.options.hmacKey, user.tenantId, sid);
|
|
6664
|
+
const detail = dashboardSessionDetail(ip, userAgent, Date.now());
|
|
6665
|
+
return [
|
|
6666
|
+
...proved ? [
|
|
6667
|
+
{
|
|
6668
|
+
key: markKey,
|
|
6669
|
+
value: "1",
|
|
6670
|
+
ttl: RECENT_AUTH_TTL_SECONDS
|
|
6671
|
+
}
|
|
6672
|
+
] : [],
|
|
6673
|
+
...this.options.sessions.enabled ? [
|
|
6674
|
+
{
|
|
6675
|
+
key: `sd:${tokenHash}`,
|
|
6676
|
+
value: detail,
|
|
6677
|
+
ttl
|
|
6678
|
+
}
|
|
6679
|
+
] : []
|
|
6680
|
+
];
|
|
6598
6681
|
}
|
|
6599
6682
|
// ---------------------------------------------------------------------------
|
|
6600
6683
|
// Platform tokens
|
|
@@ -6634,9 +6717,11 @@ var TokenManagerService = class _TokenManagerService {
|
|
|
6634
6717
|
sessionJson: serializeSession(session),
|
|
6635
6718
|
familyId,
|
|
6636
6719
|
userId: admin.id,
|
|
6637
|
-
refreshTtl: ttl
|
|
6720
|
+
refreshTtl: ttl,
|
|
6721
|
+
extras: [
|
|
6722
|
+
platformSessionExtra(tokenHash, ip, userAgent, ttl)
|
|
6723
|
+
]
|
|
6638
6724
|
});
|
|
6639
|
-
await this.writePlatformSessionDetail(tokenHash, ip, userAgent, ttl);
|
|
6640
6725
|
return {
|
|
6641
6726
|
admin,
|
|
6642
6727
|
accessToken,
|
|
@@ -6646,9 +6731,7 @@ var TokenManagerService = class _TokenManagerService {
|
|
|
6646
6731
|
/**
|
|
6647
6732
|
* Writes the per-session detail record for a platform session under `psd:{hash}`.
|
|
6648
6733
|
*
|
|
6649
|
-
* The
|
|
6650
|
-
* but platform sessions never had one, so a session listing had nothing to describe them
|
|
6651
|
-
* with. The field set and the Unix-millisecond timestamps mirror the dashboard record
|
|
6734
|
+
* The field set and the Unix-millisecond timestamps mirror the dashboard record
|
|
6652
6735
|
* exactly, so either backend sharing this Redis reads the same shape.
|
|
6653
6736
|
*
|
|
6654
6737
|
* @param tokenHash - SHA-256 of the raw refresh token; the key's `{hash}` segment.
|
|
@@ -6657,14 +6740,8 @@ var TokenManagerService = class _TokenManagerService {
|
|
|
6657
6740
|
* @param ttl - Record lifetime in seconds; matches the refresh session it describes.
|
|
6658
6741
|
*/
|
|
6659
6742
|
async writePlatformSessionDetail(tokenHash, ip, userAgent, ttl) {
|
|
6660
|
-
const
|
|
6661
|
-
|
|
6662
|
-
device: userAgent.slice(0, MAX_SESSION_FIELD_LENGTH),
|
|
6663
|
-
ip: ip.slice(0, MAX_SESSION_FIELD_LENGTH),
|
|
6664
|
-
createdAt: now3,
|
|
6665
|
-
lastActivityAt: now3
|
|
6666
|
-
};
|
|
6667
|
-
await this.redis.set(`psd:${tokenHash}`, JSON.stringify(detail), ttl);
|
|
6743
|
+
const extra = platformSessionExtra(tokenHash, ip, userAgent, ttl);
|
|
6744
|
+
await this.redis.set(extra.key, extra.value, extra.ttl);
|
|
6668
6745
|
}
|
|
6669
6746
|
// ---------------------------------------------------------------------------
|
|
6670
6747
|
// Token rotation
|
|
@@ -11017,11 +11094,29 @@ var MfaRecordService = class {
|
|
|
11017
11094
|
}
|
|
11018
11095
|
return true;
|
|
11019
11096
|
} finally {
|
|
11097
|
+
await this.releaseLock(lockKey, lockToken);
|
|
11098
|
+
}
|
|
11099
|
+
}
|
|
11100
|
+
/**
|
|
11101
|
+
* Releases the transition lock this call took, whatever the store answers.
|
|
11102
|
+
*
|
|
11103
|
+
* A compare-and-delete: only a lock still holding this call's nonce is removed. A release that
|
|
11104
|
+
* fails is logged and swallowed, because the transition has already been decided by then: an
|
|
11105
|
+
* error here would replace the transition's own result, answering failure for a write that
|
|
11106
|
+
* committed or hiding the error that did occur. The lock's short TTL ends it on its own.
|
|
11107
|
+
*
|
|
11108
|
+
* @param lockKey - The account's lock key.
|
|
11109
|
+
* @param lockToken - The nonce this call wrote when it took the lock.
|
|
11110
|
+
*/
|
|
11111
|
+
async releaseLock(lockKey, lockToken) {
|
|
11112
|
+
try {
|
|
11020
11113
|
await this.redis.eval(RELEASE_LOCK_LUA, [
|
|
11021
11114
|
lockKey
|
|
11022
11115
|
], [
|
|
11023
11116
|
lockToken
|
|
11024
11117
|
]);
|
|
11118
|
+
} catch (err) {
|
|
11119
|
+
this.logger.warn(`MFA transition lock release failed, the lock expires on its own: ${describeChannelStatus(err)}`);
|
|
11025
11120
|
}
|
|
11026
11121
|
}
|
|
11027
11122
|
/**
|
|
@@ -25574,4 +25669,4 @@ function stampJobContext(workspace) {
|
|
|
25574
25669
|
}
|
|
25575
25670
|
__name(stampJobContext, "stampJobContext");
|
|
25576
25671
|
|
|
25577
|
-
export { ALLOW_PENDING_WORKSPACE_KEY, ANY_WORKSPACE_MEMBER, API_KEY_MAX_LABEL_LENGTH, API_KEY_MAX_OVERLAP_SECONDS, AUTH_EMAIL_KINDS, AUTH_ERROR_CODES, AUTH_ERROR_MESSAGES, AUTH_ERROR_STATUS, AUTH_SECRET_MIN_LENGTH, AUTH_SECURITY_SCHEMES, AUTH_THROTTLE_CONFIGS, AcceptInvitationDto, AccountStatusService, AllowAllBreachChecker, AllowPendingWorkspace, ApiKeyGuard, ApiKeyScopes, ApiKeyService, AuthException, AuthExceptionFilter, AuthRateLimit, AuthRateLimitGuard, AuthRevocationService, AuthService, AuthTokenVerifierService, Authenticated, BYMAX_AUTH_API_KEY_CLOCK, BYMAX_AUTH_API_KEY_REPOSITORY, BYMAX_AUTH_BREACH_CHECKER, BYMAX_AUTH_EMAIL_PROVIDER, BYMAX_AUTH_HOOKS, BYMAX_AUTH_MEMBERSHIP_REPOSITORY, BYMAX_AUTH_OPTIONS, BYMAX_AUTH_PLATFORM_USER_REPOSITORY, BYMAX_AUTH_REDIS_CLIENT, BYMAX_AUTH_USER_REPOSITORY, BYMAX_AUTH_WORKSPACE_REPOSITORY, BruteForceService, BymaxAuthModule, ChangePasswordDto, CommonPasswordChecker, CreateInvitationDto, CurrentApiKey, CurrentUser, CurrentWorkspace, CurrentWsWorkspace, DefaultAuthEmailProvider, EmailChangeService, ForgotPasswordDto, HibpBreachChecker, IS_PUBLIC_KEY, InvitationService, JwtAuthGuard, JwtPlatformGuard, LoginDto, MembershipBumpFailedError, MembershipService, MfaChallengeDto, MfaDisableDto, MfaRegenerateRecoveryCodesDto, MfaRequiredGuard, MfaService, MfaVerifyDto, NoOpAuthHooks, NoOpEmailProvider, OAuthService, OptionalAuthGuard, OtpService, PLATFORM_ROLES_KEY, PasswordResetService, PlatformAuthService, PlatformLoginDto, PlatformRoles, PlatformRolesGuard, Public, ROLES_KEY, ReauthenticationService, RegisterDto, RequestEncoding, RequestEncodingGuard, ResendOtpDto, ResendVerificationDto, ResetPasswordDto, Roles, RolesGuard, SKIP_MFA_KEY, SelfOrAdminGuard, ServiceKey, SessionService, SkipMfa, TokenDeliveryService, TrustedOriginGuard, UserStatusGuard, VerifyEmailDto, VerifyOtpDto, WORKSPACE_CURSOR_MAX_LENGTH, WORKSPACE_CURSOR_PART_MAX_LENGTH, WORKSPACE_ID_MAX_LENGTH, WORKSPACE_OWNER_ROLE_MAX_LENGTH, WORKSPACE_PERMISSION_KEY, WORKSPACE_ROLES_KEY, WS_TICKET_TTL_SECONDS, WorkspaceAccessService, WorkspaceActionsService, WorkspaceCallerService, WorkspaceGuard, WorkspaceInvitationService, WorkspacePermission, WorkspaceRoles, WorkspaceService, WsAuthExceptionFilter, WsJwtGuard, WsTicketService, WsWorkspaceGuard, assertWorkspaceId, authDocumentSecurity, createAuthValidationPipe, decodeWorkspaceCursor, decodeWorkspaceScopedName, decrypt, describeChannelStatus, describeError, encodeWorkspaceCursor, encrypt, generateSecureToken, hasRole, hmacSha256, isWorkspaceOwnerRole, readWorkspacePosition, redactSecrets, reduceToBaseWord, sanitizeHeaders, sha256, sleep, stampJobContext, timingSafeCompare, workspacePositionOf, workspaceQueryKey, workspaceScopedName };
|
|
25672
|
+
export { ALLOW_PENDING_WORKSPACE_KEY, ANY_WORKSPACE_MEMBER, API_KEY_MAX_LABEL_LENGTH, API_KEY_MAX_OVERLAP_SECONDS, AUTH_EMAIL_KINDS, AUTH_ERROR_CODES, AUTH_ERROR_MESSAGES, AUTH_ERROR_STATUS, AUTH_SECRET_MIN_LENGTH, AUTH_SECURITY_SCHEMES, AUTH_THROTTLE_CONFIGS, AcceptInvitationDto, AccountStatusService, AllowAllBreachChecker, AllowPendingWorkspace, ApiKeyGuard, ApiKeyScopes, ApiKeyService, AuthException, AuthExceptionFilter, AuthRateLimit, AuthRateLimitGuard, AuthRevocationService, AuthService, AuthTokenVerifierService, Authenticated, BYMAX_AUTH_API_KEY_CLOCK, BYMAX_AUTH_API_KEY_REPOSITORY, BYMAX_AUTH_BREACH_CHECKER, BYMAX_AUTH_EMAIL_PROVIDER, BYMAX_AUTH_HOOKS, BYMAX_AUTH_MEMBERSHIP_REPOSITORY, BYMAX_AUTH_OPTIONS, BYMAX_AUTH_PLATFORM_USER_REPOSITORY, BYMAX_AUTH_REDIS_CLIENT, BYMAX_AUTH_USER_REPOSITORY, BYMAX_AUTH_WORKSPACE_REPOSITORY, BruteForceService, BymaxAuthModule, ChangePasswordDto, CommonPasswordChecker, CreateInvitationDto, CurrentApiKey, CurrentUser, CurrentWorkspace, CurrentWsWorkspace, DefaultAuthEmailProvider, EmailChangeService, ForgotPasswordDto, HibpBreachChecker, IS_PUBLIC_KEY, InvitationService, JwtAuthGuard, JwtPlatformGuard, LoginDto, MembershipBumpFailedError, MembershipService, MfaChallengeDto, MfaDisableDto, MfaRegenerateRecoveryCodesDto, MfaRequiredGuard, MfaService, MfaVerifyDto, NoOpAuthHooks, NoOpEmailProvider, OAuthService, OptionalAuthGuard, OtpService, PLATFORM_ROLES_KEY, PasswordResetService, PlatformAuthService, PlatformLoginDto, PlatformRoles, PlatformRolesGuard, Public, ROLES_KEY, ReauthenticationService, RegisterDto, RequestEncoding, RequestEncodingGuard, ResendOtpDto, ResendVerificationDto, ResetPasswordDto, Roles, RolesGuard, SKIP_MFA_KEY, SelfOrAdminGuard, ServiceKey, SessionService, SkipMfa, TokenDeliveryService, TrustedOriginGuard, UserStatusGuard, VerifyEmailDto, VerifyOtpDto, WORKSPACE_CURSOR_MAX_LENGTH, WORKSPACE_CURSOR_PART_MAX_LENGTH, WORKSPACE_ID_MAX_LENGTH, WORKSPACE_OWNER_ROLE_MAX_LENGTH, WORKSPACE_PERMISSION_KEY, WORKSPACE_ROLES_KEY, WS_TICKET_TTL_SECONDS, WorkspaceAccessService, WorkspaceActionsService, WorkspaceCallerService, WorkspaceGuard, WorkspaceInvitationService, WorkspacePermission, WorkspaceRoles, WorkspaceService, WsAuthExceptionFilter, WsJwtGuard, WsTicketService, WsWorkspaceGuard, assertWorkspaceId, authDocumentSecurity, createAuthValidationPipe, decodeWorkspaceCursor, decodeWorkspaceScopedName, decrypt, describeChannelStatus, describeError, encodeWorkspaceCursor, encrypt, generateSecureToken, hasRole, hmacSha256, isServiceUnavailable, isWorkspaceOwnerRole, readWorkspacePosition, redactSecrets, reduceToBaseWord, sanitizeHeaders, sha256, sleep, stampJobContext, timingSafeCompare, workspacePositionOf, workspaceQueryKey, workspaceScopedName };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bymax-one/nest-auth",
|
|
3
|
-
"version": "1.5.
|
|
3
|
+
"version": "1.5.7",
|
|
4
4
|
"description": "Full-stack authentication and authorization package for NestJS, React and Next.js — JWT, MFA, OAuth, sessions, multi-tenant SaaS ready",
|
|
5
5
|
"author": "Bymax One <support@bymax.one>",
|
|
6
6
|
"license": "MIT",
|