@c9up/warden 0.1.20 → 0.1.21
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/AuthManager.d.ts +0 -3
- package/dist/AuthManager.d.ts.map +1 -1
- package/dist/AuthManager.js +21 -21
- package/dist/AuthManager.js.map +1 -1
- package/dist/AuthRateLimiter.d.ts +1 -6
- package/dist/AuthRateLimiter.d.ts.map +1 -1
- package/dist/AuthRateLimiter.js +31 -31
- package/dist/AuthRateLimiter.js.map +1 -1
- package/dist/RefreshTokenStore.d.ts +1 -1
- package/dist/RefreshTokenStore.d.ts.map +1 -1
- package/dist/RefreshTokenStore.js +9 -9
- package/dist/RefreshTokenStore.js.map +1 -1
- package/dist/TokenBlacklist.d.ts +1 -1
- package/dist/TokenBlacklist.d.ts.map +1 -1
- package/dist/TokenBlacklist.js +6 -6
- package/dist/TokenBlacklist.js.map +1 -1
- package/dist/augmentations.d.ts +0 -1
- package/dist/augmentations.d.ts.map +1 -1
- package/dist/bouncer/AuthorizationResponse.d.ts +6 -0
- package/dist/bouncer/AuthorizationResponse.d.ts.map +1 -1
- package/dist/bouncer/AuthorizationResponse.js +6 -0
- package/dist/bouncer/AuthorizationResponse.js.map +1 -1
- package/dist/rights/MemoryRightsStore.d.ts +1 -6
- package/dist/rights/MemoryRightsStore.d.ts.map +1 -1
- package/dist/rights/MemoryRightsStore.js +10 -10
- package/dist/rights/MemoryRightsStore.js.map +1 -1
- package/index.win32-x64-msvc.node +0 -0
- package/package.json +1 -1
- package/src/AuthManager.ts +21 -21
- package/src/AuthRateLimiter.ts +29 -29
- package/src/RefreshTokenStore.ts +9 -9
- package/src/TokenBlacklist.ts +6 -6
- package/src/augmentations.ts +0 -2
- package/src/bouncer/AuthorizationResponse.ts +6 -0
- package/src/rights/MemoryRightsStore.ts +10 -10
package/dist/AuthManager.d.ts
CHANGED
|
@@ -111,9 +111,6 @@ export interface WardenEmitter {
|
|
|
111
111
|
}
|
|
112
112
|
export declare class AuthManager {
|
|
113
113
|
#private;
|
|
114
|
-
private guards;
|
|
115
|
-
private default;
|
|
116
|
-
private readonly rights;
|
|
117
114
|
/**
|
|
118
115
|
* Publish auth events on `emitter`. AdonisJS emits six of them from its
|
|
119
116
|
* session guard, and an app that audits logins reads exactly those.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AuthManager.d.ts","sourceRoot":"","sources":["../src/AuthManager.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAEnD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AACrD,OAAO,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAEhD,OAAO,EAAE,eAAe,EAAE,CAAC;AAG3B,OAAO,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAC;AAC5D,OAAO,KAAK,EAAE,oBAAoB,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AACrE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,iCAAiC,CAAC;AAEpE,MAAM,WAAW,WAAW;IAC3B,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,CAAC,EAAE,MAAM,EAAE,CAAC;IACjB,WAAW,CAAC,EAAE,MAAM,EAAE,CAAC;IACvB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CACvB;AAED,MAAM,WAAW,UAAU;IAC1B,aAAa,EAAE,OAAO,CAAC;IACvB,IAAI,CAAC,EAAE,WAAW,CAAC;IACnB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf;;;;;;OAMG;IACH,aAAa,CAAC,EAAE,IAAI,CAAC;CACrB;AAED;;;;;;GAMG;AACH,MAAM,WAAW,kBAAkB;IAClC,qCAAqC;IACrC,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACjC,iDAAiD;IACjD,OAAO,CAAC,EAAE,MAAM,CAA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mBAAmB,IAAI,MAAM,CAEhC;IAED,0CAA0C;IAC1C,gBAAgB,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,YAAY,GAAG,IAAI;IAI5D,yCAAyC;IACzC,gBAAgB,IAAI,MAAM,EAAE;IAI5B;;;;;;;;;OASG;IACG,KAAK,CACV,IAAI,EAAE,WAAW,EACjB,OAAO,EAAE,YAAY,EACrB,YAAY,CAAC,EAAE,MAAM,GACnB,OAAO,CAAC,IAAI,CAAC;IAwBhB;;;;OAIG;IACG,MAAM,CAAC,OAAO,EAAE,YAAY,EAAE,YAAY,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;CAezE;AAwBD,kEAAkE;AAClE;;;;;;GAMG"}
|
package/dist/AuthManager.js
CHANGED
|
@@ -39,9 +39,9 @@ function isTokenIssuer(strategy) {
|
|
|
39
39
|
export class AuthManager {
|
|
40
40
|
// AdonisJS names: `guards` (name → strategy) and `default` (the guard used
|
|
41
41
|
// when none is named). Renamed from the previous `strategies`/`defaultStrategy`.
|
|
42
|
-
guards = new Map();
|
|
43
|
-
default;
|
|
44
|
-
rights;
|
|
42
|
+
#guards = new Map();
|
|
43
|
+
#default;
|
|
44
|
+
#rights;
|
|
45
45
|
/**
|
|
46
46
|
* Where auth events go. Structural and optional: warden is a leaf and must
|
|
47
47
|
* not import an emitter — a host wires its own through `setEmitter`, and one
|
|
@@ -81,10 +81,10 @@ export class AuthManager {
|
|
|
81
81
|
if (!guards || defaultGuard === undefined) {
|
|
82
82
|
throw new WardenError("INVALID_CONFIG", "AuthManager: config must supply `default` + `guards` (or the legacy `defaultStrategy` + `strategies`).");
|
|
83
83
|
}
|
|
84
|
-
this
|
|
85
|
-
this
|
|
84
|
+
this.#default = defaultGuard;
|
|
85
|
+
this.#rights = config.rights ?? new RightsResolver(new MemoryRightsStore());
|
|
86
86
|
for (const [name, strategy] of Object.entries(guards)) {
|
|
87
|
-
this
|
|
87
|
+
this.#guards.set(name, strategy);
|
|
88
88
|
}
|
|
89
89
|
// Fail-fast at construction: an AuthManager with zero guards is a
|
|
90
90
|
// configuration bug. Previously, an empty `guards: {}` passed the
|
|
@@ -92,10 +92,10 @@ export class AuthManager {
|
|
|
92
92
|
// runtime when `getStrategy('jwt')` threw — opaque 401 or 500 instead
|
|
93
93
|
// of a boot-time INVALID_CONFIG that points the operator at the missing
|
|
94
94
|
// `config.auth.jwt` (or other guard).
|
|
95
|
-
if (this
|
|
95
|
+
if (this.#guards.size === 0) {
|
|
96
96
|
throw new WardenError("INVALID_CONFIG", `AuthManager: no authentication guards registered. Configure at least one guard (e.g. config.warden.auth.jwt) before booting WardenProvider.`);
|
|
97
97
|
}
|
|
98
|
-
if (!this
|
|
98
|
+
if (!this.#guards.has(defaultGuard)) {
|
|
99
99
|
throw new WardenError("INVALID_CONFIG", `default guard '${defaultGuard}' is not present in guards`);
|
|
100
100
|
}
|
|
101
101
|
}
|
|
@@ -157,7 +157,7 @@ export class AuthManager {
|
|
|
157
157
|
issueFor(user, strategyName) {
|
|
158
158
|
const strategy = this.getStrategy(strategyName);
|
|
159
159
|
if (!isTokenIssuer(strategy)) {
|
|
160
|
-
throw new WardenError("STRATEGY_CANNOT_ISSUE", `Auth strategy '${strategyName ?? this
|
|
160
|
+
throw new WardenError("STRATEGY_CANNOT_ISSUE", `Auth strategy '${strategyName ?? this.#default}' cannot issue tokens.`, {
|
|
161
161
|
hint: "issueFor() needs a token-minting strategy (e.g. JwtStrategy with signToken). Session / API-key strategies don't mint tokens.",
|
|
162
162
|
});
|
|
163
163
|
}
|
|
@@ -172,7 +172,7 @@ export class AuthManager {
|
|
|
172
172
|
* same `(user, scope)` (the single unification point — AC-E3).
|
|
173
173
|
*/
|
|
174
174
|
resolvePermissions(user, scope = "global") {
|
|
175
|
-
return this
|
|
175
|
+
return this.#rights.resolve(user, scope);
|
|
176
176
|
}
|
|
177
177
|
/**
|
|
178
178
|
* Check if a user has a specific role within a scope (default `"global"`).
|
|
@@ -222,7 +222,7 @@ export class AuthManager {
|
|
|
222
222
|
const strategy = this.getStrategy(guard);
|
|
223
223
|
const seam = strategy.authenticateAsClient?.bind(strategy);
|
|
224
224
|
if (!seam) {
|
|
225
|
-
throw new WardenError("STRATEGY_HAS_NO_CLIENT", `Auth strategy '${guard ?? this
|
|
225
|
+
throw new WardenError("STRATEGY_HAS_NO_CLIENT", `Auth strategy '${guard ?? this.#default}' has no authenticateAsClient() — it cannot forge a client request.`, {
|
|
226
226
|
hint: "Implement authenticateAsClient() on the strategy, or authenticate through a real login in the test.",
|
|
227
227
|
});
|
|
228
228
|
}
|
|
@@ -244,8 +244,8 @@ export class AuthManager {
|
|
|
244
244
|
}
|
|
245
245
|
}
|
|
246
246
|
getStrategy(name) {
|
|
247
|
-
const strategyName = name ?? this
|
|
248
|
-
const strategy = this
|
|
247
|
+
const strategyName = name ?? this.#default;
|
|
248
|
+
const strategy = this.#guards.get(strategyName);
|
|
249
249
|
if (!strategy) {
|
|
250
250
|
throw new WardenError("STRATEGY_NOT_FOUND", `Auth strategy '${strategyName}' not registered`, {
|
|
251
251
|
hint: "Call registerStrategy() before using this strategy name.",
|
|
@@ -259,15 +259,15 @@ export class AuthManager {
|
|
|
259
259
|
* declares none.
|
|
260
260
|
*/
|
|
261
261
|
get defaultStrategyName() {
|
|
262
|
-
return this
|
|
262
|
+
return this.#default;
|
|
263
263
|
}
|
|
264
264
|
/** Register a new strategy at runtime. */
|
|
265
265
|
registerStrategy(name, strategy) {
|
|
266
|
-
this
|
|
266
|
+
this.#guards.set(name, strategy);
|
|
267
267
|
}
|
|
268
268
|
/** Get all registered strategy names. */
|
|
269
269
|
getStrategyNames() {
|
|
270
|
-
return [...this
|
|
270
|
+
return [...this.#guards.keys()];
|
|
271
271
|
}
|
|
272
272
|
/**
|
|
273
273
|
* Log a user in through a session-capable guard (AdonisJS
|
|
@@ -282,18 +282,18 @@ export class AuthManager {
|
|
|
282
282
|
async login(user, session, strategyName) {
|
|
283
283
|
const strategy = this.getStrategy(strategyName);
|
|
284
284
|
if (!isLoginCapable(strategy)) {
|
|
285
|
-
throw new WardenError("STRATEGY_CANNOT_LOGIN", `Auth strategy '${strategyName ?? this
|
|
285
|
+
throw new WardenError("STRATEGY_CANNOT_LOGIN", `Auth strategy '${strategyName ?? this.#default}' does not support session login.`, {
|
|
286
286
|
hint: "login()/logout() need a stateful guard (e.g. SessionStrategy). JWT / API-key guards are stateless — mint a token with issueFor() instead.",
|
|
287
287
|
});
|
|
288
288
|
}
|
|
289
289
|
const prefix = authEventPrefix(strategy.name);
|
|
290
290
|
this.#emit(`${prefix}:login_attempted`, {
|
|
291
|
-
guardName: strategyName ?? this
|
|
291
|
+
guardName: strategyName ?? this.#default,
|
|
292
292
|
user,
|
|
293
293
|
});
|
|
294
294
|
await strategy.login(user, session);
|
|
295
295
|
this.#emit(`${prefix}:login_succeeded`, {
|
|
296
|
-
guardName: strategyName ?? this
|
|
296
|
+
guardName: strategyName ?? this.#default,
|
|
297
297
|
user,
|
|
298
298
|
sessionId: undefined,
|
|
299
299
|
});
|
|
@@ -306,11 +306,11 @@ export class AuthManager {
|
|
|
306
306
|
async logout(session, strategyName) {
|
|
307
307
|
const strategy = this.getStrategy(strategyName);
|
|
308
308
|
if (!isLoginCapable(strategy)) {
|
|
309
|
-
throw new WardenError("STRATEGY_CANNOT_LOGIN", `Auth strategy '${strategyName ?? this
|
|
309
|
+
throw new WardenError("STRATEGY_CANNOT_LOGIN", `Auth strategy '${strategyName ?? this.#default}' does not support session logout.`);
|
|
310
310
|
}
|
|
311
311
|
await strategy.logout(session);
|
|
312
312
|
this.#emit(`${authEventPrefix(strategy.name)}:logged_out`, {
|
|
313
|
-
guardName: strategyName ?? this
|
|
313
|
+
guardName: strategyName ?? this.#default,
|
|
314
314
|
user: null,
|
|
315
315
|
error: null,
|
|
316
316
|
});
|
package/dist/AuthManager.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AuthManager.js","sourceRoot":"","sources":["../src/A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E,YAAY,IAAI,IAAI,CAAC,QAAQ;YACxC,IAAI,EAAE,IAAI;YACV,KAAK,EAAE,IAAI;SACX,CAAC,CAAC;IACJ,CAAC;CACD;AAQD;;;;GAIG;AACH,SAAS,cAAc,CACtB,QAAsB;IAEtB,OAAO,CACN,OAAO,IAAI,QAAQ;QACnB,OAAO,QAAQ,CAAC,KAAK,KAAK,UAAU;QACpC,QAAQ,IAAI,QAAQ;QACpB,OAAO,QAAQ,CAAC,MAAM,KAAK,UAAU,CACrC,CAAC;AACH,CAAC;AAED,kEAAkE;AAClE;;;;;;GAMG"}
|
|
@@ -10,10 +10,7 @@ export interface AuthRateLimiterConfig {
|
|
|
10
10
|
windowSeconds?: number;
|
|
11
11
|
}
|
|
12
12
|
export declare class AuthRateLimiter {
|
|
13
|
-
private
|
|
14
|
-
private window;
|
|
15
|
-
private store;
|
|
16
|
-
private maxStoreSize;
|
|
13
|
+
#private;
|
|
17
14
|
constructor(config?: AuthRateLimiterConfig);
|
|
18
15
|
/** Check if an attempt is allowed. Returns false if rate limited. */
|
|
19
16
|
check(ip: string, identifier: string): boolean;
|
|
@@ -23,7 +20,5 @@ export declare class AuthRateLimiter {
|
|
|
23
20
|
recordSuccess(ip: string, identifier: string): void;
|
|
24
21
|
/** Get remaining attempts for an identifier. */
|
|
25
22
|
remaining(ip: string, identifier: string): number;
|
|
26
|
-
private checkKey;
|
|
27
|
-
private increment;
|
|
28
23
|
}
|
|
29
24
|
//# sourceMappingURL=AuthRateLimiter.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AuthRateLimiter.d.ts","sourceRoot":"","sources":["../src/AuthRateLimiter.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,MAAM,WAAW,qBAAqB;IACrC,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,aAAa,CAAC,EAAE,MAAM,CAAC;CACvB;AAOD,qBAAa,eAAe
|
|
1
|
+
{"version":3,"file":"AuthRateLimiter.d.ts","sourceRoot":"","sources":["../src/AuthRateLimiter.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,MAAM,WAAW,qBAAqB;IACrC,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,aAAa,CAAC,EAAE,MAAM,CAAC;CACvB;AAOD,qBAAa,eAAe;;gBAMf,MAAM,CAAC,EAAE,qBAAqB;IAO1C,qEAAqE;IACrE,KAAK,CAAC,EAAE,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,OAAO;IAW9C,+BAA+B;IAC/B,aAAa,CAAC,EAAE,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,IAAI;IAQnD,0CAA0C;IAC1C,aAAa,CAAC,EAAE,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,IAAI;IAOnD,gDAAgD;IAChD,SAAS,CAAC,EAAE,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,MAAM;CAmCjD"}
|
package/dist/AuthRateLimiter.js
CHANGED
|
@@ -6,17 +6,17 @@
|
|
|
6
6
|
* @implements MISS-26
|
|
7
7
|
*/
|
|
8
8
|
export class AuthRateLimiter {
|
|
9
|
-
maxAttempts;
|
|
10
|
-
window;
|
|
11
|
-
store = new Map();
|
|
12
|
-
maxStoreSize = 100_000;
|
|
9
|
+
#maxAttempts;
|
|
10
|
+
#window;
|
|
11
|
+
#store = new Map();
|
|
12
|
+
#maxStoreSize = 100_000;
|
|
13
13
|
constructor(config) {
|
|
14
|
-
this
|
|
15
|
-
if (this
|
|
16
|
-
this
|
|
17
|
-
this
|
|
18
|
-
if (this
|
|
19
|
-
this
|
|
14
|
+
this.#maxAttempts = config?.maxAttempts ?? 5;
|
|
15
|
+
if (this.#maxAttempts <= 0)
|
|
16
|
+
this.#maxAttempts = 1;
|
|
17
|
+
this.#window = (config?.windowSeconds ?? 900) * 1000;
|
|
18
|
+
if (this.#window <= 0)
|
|
19
|
+
this.#window = 900_000; // prevent bypass via 0/negative
|
|
20
20
|
}
|
|
21
21
|
/** Check if an attempt is allowed. Returns false if rate limited. */
|
|
22
22
|
check(ip, identifier) {
|
|
@@ -26,55 +26,55 @@ export class AuthRateLimiter {
|
|
|
26
26
|
// Dual key: limit both by IP and by identifier (email)
|
|
27
27
|
const ipKey = `ip:${ipNorm}`;
|
|
28
28
|
const idKey = `id:${identifierNorm}`;
|
|
29
|
-
return this
|
|
29
|
+
return this.#checkKey(ipKey, now) && this.#checkKey(idKey, now);
|
|
30
30
|
}
|
|
31
31
|
/** Record a failed attempt. */
|
|
32
32
|
recordFailure(ip, identifier) {
|
|
33
33
|
const now = Date.now();
|
|
34
34
|
const ipNorm = normalizeIp(ip);
|
|
35
35
|
const identifierNorm = normalizeIdentifier(identifier);
|
|
36
|
-
this
|
|
37
|
-
this
|
|
36
|
+
this.#increment(`ip:${ipNorm}`, now);
|
|
37
|
+
this.#increment(`id:${identifierNorm}`, now);
|
|
38
38
|
}
|
|
39
39
|
/** Reset counters on successful login. */
|
|
40
40
|
recordSuccess(ip, identifier) {
|
|
41
41
|
const ipNorm = normalizeIp(ip);
|
|
42
42
|
const identifierNorm = normalizeIdentifier(identifier);
|
|
43
|
-
this
|
|
44
|
-
this
|
|
43
|
+
this.#store.delete(`ip:${ipNorm}`);
|
|
44
|
+
this.#store.delete(`id:${identifierNorm}`);
|
|
45
45
|
}
|
|
46
46
|
/** Get remaining attempts for an identifier. */
|
|
47
47
|
remaining(ip, identifier) {
|
|
48
48
|
const ipNorm = normalizeIp(ip);
|
|
49
49
|
const identifierNorm = normalizeIdentifier(identifier);
|
|
50
|
-
const ipEntry = this
|
|
51
|
-
const idEntry = this
|
|
50
|
+
const ipEntry = this.#store.get(`ip:${ipNorm}`);
|
|
51
|
+
const idEntry = this.#store.get(`id:${identifierNorm}`);
|
|
52
52
|
const ipRemaining = ipEntry
|
|
53
|
-
? Math.max(0, this
|
|
54
|
-
: this
|
|
53
|
+
? Math.max(0, this.#maxAttempts - ipEntry.count)
|
|
54
|
+
: this.#maxAttempts;
|
|
55
55
|
const idRemaining = idEntry
|
|
56
|
-
? Math.max(0, this
|
|
57
|
-
: this
|
|
56
|
+
? Math.max(0, this.#maxAttempts - idEntry.count)
|
|
57
|
+
: this.#maxAttempts;
|
|
58
58
|
return Math.min(ipRemaining, idRemaining);
|
|
59
59
|
}
|
|
60
|
-
checkKey(key, now) {
|
|
61
|
-
const entry = this
|
|
60
|
+
#checkKey(key, now) {
|
|
61
|
+
const entry = this.#store.get(key);
|
|
62
62
|
if (!entry || entry.resetAt < now)
|
|
63
63
|
return true;
|
|
64
|
-
return entry.count < this
|
|
64
|
+
return entry.count < this.#maxAttempts;
|
|
65
65
|
}
|
|
66
|
-
increment(key, now) {
|
|
66
|
+
#increment(key, now) {
|
|
67
67
|
// Evict expired entries when store grows too large (prevent OOM)
|
|
68
|
-
if (this
|
|
69
|
-
for (const [k, v] of this
|
|
68
|
+
if (this.#store.size > this.#maxStoreSize) {
|
|
69
|
+
for (const [k, v] of this.#store) {
|
|
70
70
|
if (v.resetAt < now)
|
|
71
|
-
this
|
|
71
|
+
this.#store.delete(k);
|
|
72
72
|
}
|
|
73
73
|
}
|
|
74
|
-
let entry = this
|
|
74
|
+
let entry = this.#store.get(key);
|
|
75
75
|
if (!entry || entry.resetAt < now) {
|
|
76
|
-
entry = { count: 0, resetAt: now + this
|
|
77
|
-
this
|
|
76
|
+
entry = { count: 0, resetAt: now + this.#window };
|
|
77
|
+
this.#store.set(key, entry);
|
|
78
78
|
}
|
|
79
79
|
entry.count++;
|
|
80
80
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AuthRateLimiter.js","sourceRoot":"","sources":["../src/AuthRateLimiter.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAYH,MAAM,OAAO,eAAe;
|
|
1
|
+
{"version":3,"file":"AuthRateLimiter.js","sourceRoot":"","sources":["../src/AuthRateLimiter.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAYH,MAAM,OAAO,eAAe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
|
|
24
24
|
export declare class MemoryRefreshTokenDriver implements RefreshTokenDriver {
|
|
25
|
-
private
|
|
25
|
+
#private;
|
|
26
26
|
store(token: StoredRefreshToken): Promise<void>;
|
|
27
27
|
find(token: string): Promise<StoredRefreshToken | null>;
|
|
28
28
|
revoke(token: string): Promise<void>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RefreshTokenStore.d.ts","sourceRoot":"","sources":["../src/RefreshTokenStore.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAIH,MAAM,WAAW,kBAAkB;IAClC,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,GAAG,MAAM,CAAC;IACxB,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,WAAW,kBAAkB;IAClC,KAAK,CAAC,KAAK,EAAE,kBAAkB,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAChD,IAAI,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,kBAAkB,GAAG,IAAI,CAAC,CAAC;IACxD,MAAM,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACrC,gBAAgB,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACzD,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CACzB;AAED,wCAAwC;AACxC,qBAAa,wBAAyB,YAAW,kBAAkB
|
|
1
|
+
{"version":3,"file":"RefreshTokenStore.d.ts","sourceRoot":"","sources":["../src/RefreshTokenStore.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAIH,MAAM,WAAW,kBAAkB;IAClC,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,GAAG,MAAM,CAAC;IACxB,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,WAAW,kBAAkB;IAClC,KAAK,CAAC,KAAK,EAAE,kBAAkB,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAChD,IAAI,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,kBAAkB,GAAG,IAAI,CAAC,CAAC;IACxD,MAAM,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACrC,gBAAgB,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACzD,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CACzB;AAED,wCAAwC;AACxC,qBAAa,wBAAyB,YAAW,kBAAkB;;IAG5D,KAAK,CAAC,KAAK,EAAE,kBAAkB,GAAG,OAAO,CAAC,IAAI,CAAC;IAI/C,IAAI,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,kBAAkB,GAAG,IAAI,CAAC;IAUvD,MAAM,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAIpC,gBAAgB,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAMxD,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;CAM9B;AAED,wCAAwC;AACxC,wBAAgB,oBAAoB,IAAI,MAAM,CAE7C"}
|
|
@@ -10,34 +10,34 @@
|
|
|
10
10
|
import { randomBytes } from "node:crypto";
|
|
11
11
|
/** In-memory driver for development. */
|
|
12
12
|
export class MemoryRefreshTokenDriver {
|
|
13
|
-
tokens = new Map();
|
|
13
|
+
#tokens = new Map();
|
|
14
14
|
async store(token) {
|
|
15
|
-
this
|
|
15
|
+
this.#tokens.set(token.token, token);
|
|
16
16
|
}
|
|
17
17
|
async find(token) {
|
|
18
|
-
const stored = this
|
|
18
|
+
const stored = this.#tokens.get(token);
|
|
19
19
|
if (!stored)
|
|
20
20
|
return null;
|
|
21
21
|
if (stored.expiresAt < Date.now()) {
|
|
22
|
-
this
|
|
22
|
+
this.#tokens.delete(token);
|
|
23
23
|
return null;
|
|
24
24
|
}
|
|
25
25
|
return stored;
|
|
26
26
|
}
|
|
27
27
|
async revoke(token) {
|
|
28
|
-
this
|
|
28
|
+
this.#tokens.delete(token);
|
|
29
29
|
}
|
|
30
30
|
async revokeAllForUser(userId) {
|
|
31
|
-
for (const [key, val] of this
|
|
31
|
+
for (const [key, val] of this.#tokens) {
|
|
32
32
|
if (val.userId === userId)
|
|
33
|
-
this
|
|
33
|
+
this.#tokens.delete(key);
|
|
34
34
|
}
|
|
35
35
|
}
|
|
36
36
|
async cleanup() {
|
|
37
37
|
const now = Date.now();
|
|
38
|
-
for (const [key, val] of this
|
|
38
|
+
for (const [key, val] of this.#tokens) {
|
|
39
39
|
if (val.expiresAt < now)
|
|
40
|
-
this
|
|
40
|
+
this.#tokens.delete(key);
|
|
41
41
|
}
|
|
42
42
|
}
|
|
43
43
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RefreshTokenStore.js","sourceRoot":"","sources":["../src/RefreshTokenStore.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAiB1C,wCAAwC;AACxC,MAAM,OAAO,wBAAwB;
|
|
1
|
+
{"version":3,"file":"RefreshTokenStore.js","sourceRoot":"","sources":["../src/RefreshTokenStore.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAiB1C,wCAAwC;AACxC,MAAM,OAAO,wBAAwB;IACpC,OAAO,GAAoC,IAAI,GAAG,EAAE,CAAC;IAErD,KAAK,CAAC,KAAK,CAAC,KAAyB;QACpC,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC;IACtC,CAAC;IAED,KAAK,CAAC,IAAI,CAAC,KAAa;QACvB,MAAM,MAAM,GAAG,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;QACvC,IAAI,CAAC,MAAM;YAAE,OAAO,IAAI,CAAC;QACzB,IAAI,MAAM,CAAC,SAAS,GAAG,IAAI,CAAC,GAAG,EAAE,EAAE,CAAC;YACnC,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;YAC3B,OAAO,IAAI,CAAC;QACb,CAAC;QACD,OAAO,MAAM,CAAC;IACf,CAAC;IAED,KAAK,CAAC,MAAM,CAAC,KAAa;QACzB,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;IAC5B,CAAC;IAED,KAAK,CAAC,gBAAgB,CAAC,MAAuB;QAC7C,KAAK,MAAM,CAAC,GAAG,EAAE,GAAG,CAAC,IAAI,IAAI,CAAC,OAAO,EAAE,CAAC;YACvC,IAAI,GAAG,CAAC,MAAM,KAAK,MAAM;gBAAE,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;QACrD,CAAC;IACF,CAAC;IAED,KAAK,CAAC,OAAO;QACZ,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;QACvB,KAAK,MAAM,CAAC,GAAG,EAAE,GAAG,CAAC,IAAI,IAAI,CAAC,OAAO,EAAE,CAAC;YACvC,IAAI,GAAG,CAAC,SAAS,GAAG,GAAG;gBAAE,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;QACnD,CAAC;IACF,CAAC;CACD;AAED,wCAAwC;AACxC,MAAM,UAAU,oBAAoB;IACnC,OAAO,WAAW,CAAC,EAAE,CAAC,CAAC,QAAQ,CAAC,WAAW,CAAC,CAAC;AAC9C,CAAC"}
|
package/dist/TokenBlacklist.d.ts
CHANGED
|
@@ -16,7 +16,7 @@ export interface BlacklistDriver {
|
|
|
16
16
|
}
|
|
17
17
|
/** In-memory blacklist for development. */
|
|
18
18
|
export declare class MemoryBlacklistDriver implements BlacklistDriver {
|
|
19
|
-
private
|
|
19
|
+
#private;
|
|
20
20
|
add(jti: string, expiresAt: number): Promise<void>;
|
|
21
21
|
has(jti: string): Promise<boolean>;
|
|
22
22
|
cleanup(): Promise<void>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TokenBlacklist.d.ts","sourceRoot":"","sources":["../src/TokenBlacklist.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,MAAM,WAAW,eAAe;IAC/B,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACnD,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;IACnC;;;OAGG;IACH,OAAO,CAAC,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CAC1B;AAED,2CAA2C;AAC3C,qBAAa,qBAAsB,YAAW,eAAe
|
|
1
|
+
{"version":3,"file":"TokenBlacklist.d.ts","sourceRoot":"","sources":["../src/TokenBlacklist.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,MAAM,WAAW,eAAe;IAC/B,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACnD,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;IACnC;;;OAGG;IACH,OAAO,CAAC,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CAC1B;AAED,2CAA2C;AAC3C,qBAAa,qBAAsB,YAAW,eAAe;;IAGtD,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAIlD,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAUlC,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;CAM9B;AAED,qBAAa,cAAc;IACd,OAAO,CAAC,MAAM;gBAAN,MAAM,EAAE,eAAe;IAE3C,uCAAuC;IACjC,MAAM,CAAC,GAAG,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAI3D,2CAA2C;IACrC,SAAS,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAI9C,2EAA2E;IACrE,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;CAG9B"}
|
package/dist/TokenBlacklist.js
CHANGED
|
@@ -7,25 +7,25 @@
|
|
|
7
7
|
*/
|
|
8
8
|
/** In-memory blacklist for development. */
|
|
9
9
|
export class MemoryBlacklistDriver {
|
|
10
|
-
entries = new Map();
|
|
10
|
+
#entries = new Map();
|
|
11
11
|
async add(jti, expiresAt) {
|
|
12
|
-
this
|
|
12
|
+
this.#entries.set(jti, expiresAt);
|
|
13
13
|
}
|
|
14
14
|
async has(jti) {
|
|
15
|
-
const expiresAt = this
|
|
15
|
+
const expiresAt = this.#entries.get(jti);
|
|
16
16
|
if (expiresAt === undefined)
|
|
17
17
|
return false;
|
|
18
18
|
if (expiresAt < Date.now()) {
|
|
19
|
-
this
|
|
19
|
+
this.#entries.delete(jti);
|
|
20
20
|
return false;
|
|
21
21
|
}
|
|
22
22
|
return true;
|
|
23
23
|
}
|
|
24
24
|
async cleanup() {
|
|
25
25
|
const now = Date.now();
|
|
26
|
-
for (const [jti, exp] of this
|
|
26
|
+
for (const [jti, exp] of this.#entries) {
|
|
27
27
|
if (exp < now)
|
|
28
|
-
this
|
|
28
|
+
this.#entries.delete(jti);
|
|
29
29
|
}
|
|
30
30
|
}
|
|
31
31
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TokenBlacklist.js","sourceRoot":"","sources":["../src/TokenBlacklist.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAYH,2CAA2C;AAC3C,MAAM,OAAO,qBA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2CAA2C;IAC3C,KAAK,CAAC,SAAS,CAAC,GAAW;QAC1B,OAAO,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;IAC7B,CAAC;IAED,2EAA2E;IAC3E,KAAK,CAAC,OAAO;QACZ,MAAM,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,EAAE,CAAC;IAC/B,CAAC;CACD"}
|
package/dist/augmentations.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"augmentations.d.ts","sourceRoot":"","sources":["../src/augmentations.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAIH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAExD,OAAO,QAAQ,kBAAkB,CAAC;IACjC,UAAU,cAAc;QACvB,CAAC,SAAS,EAAE,MAAM,GAAG,aAAa,CAAC;KACnC;CACD
|
|
1
|
+
{"version":3,"file":"augmentations.d.ts","sourceRoot":"","sources":["../src/augmentations.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAIH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAExD,OAAO,QAAQ,kBAAkB,CAAC;IACjC,UAAU,cAAc;QACvB,CAAC,SAAS,EAAE,MAAM,GAAG,aAAa,CAAC;KACnC;CACD"}
|
|
@@ -17,6 +17,12 @@ export declare class AuthorizationResponse {
|
|
|
17
17
|
identifier: string;
|
|
18
18
|
data?: Record<string, unknown>;
|
|
19
19
|
};
|
|
20
|
+
/**
|
|
21
|
+
* Private because a response is only ever built through allow() / deny(), so the pair stays consistent.
|
|
22
|
+
*
|
|
23
|
+
* `private` and not `#`: a private CONSTRUCTOR has no native form. It is the
|
|
24
|
+
* one place the keyword expresses something `#` cannot.
|
|
25
|
+
*/
|
|
20
26
|
private constructor();
|
|
21
27
|
/** Authorized response (no status). */
|
|
22
28
|
static allow(): AuthorizationResponse;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AuthorizationResponse.d.ts","sourceRoot":"","sources":["../../src/bouncer/AuthorizationResponse.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,qBAAa,qBAAqB;IACjC,QAAQ,CAAC,UAAU,EAAE,OAAO,CAAC;IAC7B,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,yEAAyE;IACzE,WAAW,CAAC,EAAE;QAAE,UAAU,EAAE,MAAM,CAAC;QAAC,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;KAAE,CAAC;IAErE,OAAO;IAMP,uCAAuC;IACvC,MAAM,CAAC,KAAK,IAAI,qBAAqB;IAIrC;;;;OAIG;IACH,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,GAAG,qBAAqB;IAIrE;;;OAGG;IACH,CAAC,CAAC,UAAU,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI;CAI3D"}
|
|
1
|
+
{"version":3,"file":"AuthorizationResponse.d.ts","sourceRoot":"","sources":["../../src/bouncer/AuthorizationResponse.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,qBAAa,qBAAqB;IACjC,QAAQ,CAAC,UAAU,EAAE,OAAO,CAAC;IAC7B,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,yEAAyE;IACzE,WAAW,CAAC,EAAE;QAAE,UAAU,EAAE,MAAM,CAAC;QAAC,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;KAAE,CAAC;IAErE;;;;;OAKG;IACH,OAAO;IAMP,uCAAuC;IACvC,MAAM,CAAC,KAAK,IAAI,qBAAqB;IAIrC;;;;OAIG;IACH,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,GAAG,qBAAqB;IAIrE;;;OAGG;IACH,CAAC,CAAC,UAAU,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI;CAI3D"}
|
|
@@ -14,6 +14,12 @@ export class AuthorizationResponse {
|
|
|
14
14
|
status;
|
|
15
15
|
/** i18n binding set via {@link t} (Adonis `AuthorizationResponse.t`). */
|
|
16
16
|
translation;
|
|
17
|
+
/**
|
|
18
|
+
* Private because a response is only ever built through allow() / deny(), so the pair stays consistent.
|
|
19
|
+
*
|
|
20
|
+
* `private` and not `#`: a private CONSTRUCTOR has no native form. It is the
|
|
21
|
+
* one place the keyword expresses something `#` cannot.
|
|
22
|
+
*/
|
|
17
23
|
constructor(authorized, message, status) {
|
|
18
24
|
this.authorized = authorized;
|
|
19
25
|
this.message = message;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AuthorizationResponse.js","sourceRoot":"","sources":["../../src/bouncer/AuthorizationResponse.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,MAAM,OAAO,qBAAqB;IACxB,UAAU,CAAU;IAC7B,OAAO,CAAU;IACjB,MAAM,CAAU;IAChB,yEAAyE;IACzE,WAAW,CAA0D;IAErE,YAAoB,UAAmB,EAAE,OAAgB,EAAE,MAAe;QACzE,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;QAC7B,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACvB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACtB,CAAC;IAED,uCAAuC;IACvC,MAAM,CAAC,KAAK;QACX,OAAO,IAAI,qBAAqB,CAAC,IAAI,CAAC,CAAC;IACxC,CAAC;IAED;;;;OAIG;IACH,MAAM,CAAC,IAAI,CAAC,OAAgB,EAAE,MAAe;QAC5C,OAAO,IAAI,qBAAqB,CAAC,KAAK,EAAE,OAAO,EAAE,MAAM,CAAC,CAAC;IAC1D,CAAC;IAED;;;OAGG;IACH,CAAC,CAAC,UAAkB,EAAE,IAA8B;QACnD,IAAI,CAAC,WAAW,GAAG,EAAE,UAAU,EAAE,IAAI,EAAE,CAAC;QACxC,OAAO,IAAI,CAAC;IACb,CAAC;CACD"}
|
|
1
|
+
{"version":3,"file":"AuthorizationResponse.js","sourceRoot":"","sources":["../../src/bouncer/AuthorizationResponse.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,MAAM,OAAO,qBAAqB;IACxB,UAAU,CAAU;IAC7B,OAAO,CAAU;IACjB,MAAM,CAAU;IAChB,yEAAyE;IACzE,WAAW,CAA0D;IAErE;;;;;OAKG;IACH,YAAoB,UAAmB,EAAE,OAAgB,EAAE,MAAe;QACzE,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;QAC7B,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACvB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACtB,CAAC;IAED,uCAAuC;IACvC,MAAM,CAAC,KAAK;QACX,OAAO,IAAI,qBAAqB,CAAC,IAAI,CAAC,CAAC;IACxC,CAAC;IAED;;;;OAIG;IACH,MAAM,CAAC,IAAI,CAAC,OAAgB,EAAE,MAAe;QAC5C,OAAO,IAAI,qBAAqB,CAAC,KAAK,EAAE,OAAO,EAAE,MAAM,CAAC,CAAC;IAC1D,CAAC;IAED;;;OAGG;IACH,CAAC,CAAC,UAAkB,EAAE,IAA8B;QACnD,IAAI,CAAC,WAAW,GAAG,EAAE,UAAU,EAAE,IAAI,EAAE,CAAC;QACxC,OAAO,IAAI,CAAC;IACb,CAAC;CACD"}
|
|
@@ -12,12 +12,7 @@
|
|
|
12
12
|
*/
|
|
13
13
|
import { type RightsStore, type Scope } from "./types.js";
|
|
14
14
|
export declare class MemoryRightsStore implements RightsStore {
|
|
15
|
-
|
|
16
|
-
private readonly roleDefs;
|
|
17
|
-
/** scopeKey → userId → roles */
|
|
18
|
-
private readonly userRoleMap;
|
|
19
|
-
/** scopeKey → userId → directly granted permissions */
|
|
20
|
-
private readonly userGrantMap;
|
|
15
|
+
#private;
|
|
21
16
|
rolePermissions(role: string, scope: Scope): Promise<readonly string[]>;
|
|
22
17
|
userRoles(userId: string, scope: Scope): Promise<readonly string[]>;
|
|
23
18
|
userGrants(userId: string, scope: Scope): Promise<readonly string[]>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MemoryRightsStore.d.ts","sourceRoot":"","sources":["../../src/rights/MemoryRightsStore.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,EAAE,KAAK,WAAW,EAAE,KAAK,KAAK,EAAY,MAAM,YAAY,CAAC;AAEpE,qBAAa,iBAAkB,YAAW,WAAW
|
|
1
|
+
{"version":3,"file":"MemoryRightsStore.d.ts","sourceRoot":"","sources":["../../src/rights/MemoryRightsStore.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,EAAE,KAAK,WAAW,EAAE,KAAK,KAAK,EAAY,MAAM,YAAY,CAAC;AAEpE,qBAAa,iBAAkB,YAAW,WAAW;;IAU9C,eAAe,CACpB,IAAI,EAAE,MAAM,EACZ,KAAK,EAAE,KAAK,GACV,OAAO,CAAC,SAAS,MAAM,EAAE,CAAC;IAIvB,SAAS,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,KAAK,GAAG,OAAO,CAAC,SAAS,MAAM,EAAE,CAAC;IAInE,UAAU,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,KAAK,GAAG,OAAO,CAAC,SAAS,MAAM,EAAE,CAAC;IAM1E,UAAU,CACT,IAAI,EAAE,MAAM,EACZ,WAAW,EAAE,SAAS,MAAM,EAAE,EAC9B,KAAK,GAAE,KAAgB,GACrB,IAAI;IAOP,UAAU,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,GAAE,KAAgB,GAAG,IAAI;IAKvE,KAAK,CAAC,MAAM,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,KAAK,GAAE,KAAgB,GAAG,IAAI;IAKxE,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,KAAK,GAAE,KAAgB,GAAG,IAAI;CAIzE"}
|
|
@@ -13,39 +13,39 @@
|
|
|
13
13
|
import { scopeKey } from "./types.js";
|
|
14
14
|
export class MemoryRightsStore {
|
|
15
15
|
/** scopeKey → role → permissions */
|
|
16
|
-
roleDefs = new Map();
|
|
16
|
+
#roleDefs = new Map();
|
|
17
17
|
/** scopeKey → userId → roles */
|
|
18
|
-
userRoleMap = new Map();
|
|
18
|
+
#userRoleMap = new Map();
|
|
19
19
|
/** scopeKey → userId → directly granted permissions */
|
|
20
|
-
userGrantMap = new Map();
|
|
20
|
+
#userGrantMap = new Map();
|
|
21
21
|
// — read contract —
|
|
22
22
|
async rolePermissions(role, scope) {
|
|
23
|
-
return snapshot(this
|
|
23
|
+
return snapshot(this.#roleDefs.get(scopeKey(scope))?.get(role));
|
|
24
24
|
}
|
|
25
25
|
async userRoles(userId, scope) {
|
|
26
|
-
return snapshot(this
|
|
26
|
+
return snapshot(this.#userRoleMap.get(scopeKey(scope))?.get(userId));
|
|
27
27
|
}
|
|
28
28
|
async userGrants(userId, scope) {
|
|
29
|
-
return snapshot(this
|
|
29
|
+
return snapshot(this.#userGrantMap.get(scopeKey(scope))?.get(userId));
|
|
30
30
|
}
|
|
31
31
|
// — seeding (in-memory driver only; not part of RightsStore) —
|
|
32
32
|
defineRole(role, permissions, scope = "global") {
|
|
33
|
-
const set = bucket(this
|
|
33
|
+
const set = bucket(this.#roleDefs, scopeKey(scope), role);
|
|
34
34
|
set.clear();
|
|
35
35
|
for (const perm of permissions)
|
|
36
36
|
set.add(perm);
|
|
37
37
|
return this;
|
|
38
38
|
}
|
|
39
39
|
assignRole(userId, role, scope = "global") {
|
|
40
|
-
bucket(this
|
|
40
|
+
bucket(this.#userRoleMap, scopeKey(scope), userId).add(role);
|
|
41
41
|
return this;
|
|
42
42
|
}
|
|
43
43
|
grant(userId, permission, scope = "global") {
|
|
44
|
-
bucket(this
|
|
44
|
+
bucket(this.#userGrantMap, scopeKey(scope), userId).add(permission);
|
|
45
45
|
return this;
|
|
46
46
|
}
|
|
47
47
|
revoke(userId, permission, scope = "global") {
|
|
48
|
-
this
|
|
48
|
+
this.#userGrantMap.get(scopeKey(scope))?.get(userId)?.delete(permission);
|
|
49
49
|
return this;
|
|
50
50
|
}
|
|
51
51
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MemoryRightsStore.js","sourceRoot":"","sources":["../../src/rights/MemoryRightsStore.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,EAAgC,QAAQ,EAAE,MAAM,YAAY,CAAC;AAEpE,MAAM,OAAO,iBAAiB;IAC7B,oCAAoC;
|
|
1
|
+
{"version":3,"file":"MemoryRightsStore.js","sourceRoot":"","sources":["../../src/rights/MemoryRightsStore.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,EAAgC,QAAQ,EAAE,MAAM,YAAY,CAAC;AAEpE,MAAM,OAAO,iBAAiB;IAC7B,oCAAoC;IAC3B,SAAS,GAAG,IAAI,GAAG,EAAoC,CAAC;IACjE,gCAAgC;IACvB,YAAY,GAAG,IAAI,GAAG,EAAoC,CAAC;IACpE,uDAAuD;IAC9C,aAAa,GAAG,IAAI,GAAG,EAAoC,CAAC;IAErE,oBAAoB;IAEpB,KAAK,CAAC,eAAe,CACpB,IAAY,EACZ,KAAY;QAEZ,OAAO,QAAQ,CAAC,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,EAAE,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC;IACjE,CAAC;IAED,KAAK,CAAC,SAAS,CAAC,MAAc,EAAE,KAAY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AAC,EAAE,GAAG,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC,UAAU,CAAC,CAAC;QACzE,OAAO,IAAI,CAAC;IACb,CAAC;CACD;AAED,sFAAsF;AACtF,SAAS,QAAQ,CAAC,GAA4B;IAC7C,OAAO,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;AAC5B,CAAC;AAED,6DAA6D;AAC7D,SAAS,MAAM,CACd,KAA4C,EAC5C,GAAW,EACX,KAAa;IAEb,IAAI,GAAG,GAAG,KAAK,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;IACzB,IAAI,CAAC,GAAG,EAAE,CAAC;QACV,GAAG,GAAG,IAAI,GAAG,EAAuB,CAAC;QACrC,KAAK,CAAC,GAAG,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;IACrB,CAAC;IACD,IAAI,GAAG,GAAG,GAAG,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;IACzB,IAAI,CAAC,GAAG,EAAE,CAAC;QACV,GAAG,GAAG,IAAI,GAAG,EAAU,CAAC;QACxB,GAAG,CAAC,GAAG,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;IACrB,CAAC;IACD,OAAO,GAAG,CAAC;AACZ,CAAC"}
|
|
Binary file
|
package/package.json
CHANGED
package/src/AuthManager.ts
CHANGED
|
@@ -146,9 +146,9 @@ export interface WardenEmitter {
|
|
|
146
146
|
export class AuthManager {
|
|
147
147
|
// AdonisJS names: `guards` (name → strategy) and `default` (the guard used
|
|
148
148
|
// when none is named). Renamed from the previous `strategies`/`defaultStrategy`.
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
149
|
+
#guards: Map<string, AuthStrategy> = new Map();
|
|
150
|
+
#default: string;
|
|
151
|
+
readonly #rights: RightsResolver;
|
|
152
152
|
|
|
153
153
|
/**
|
|
154
154
|
* Where auth events go. Structural and optional: warden is a leaf and must
|
|
@@ -195,10 +195,10 @@ export class AuthManager {
|
|
|
195
195
|
"AuthManager: config must supply `default` + `guards` (or the legacy `defaultStrategy` + `strategies`).",
|
|
196
196
|
);
|
|
197
197
|
}
|
|
198
|
-
this
|
|
199
|
-
this
|
|
198
|
+
this.#default = defaultGuard;
|
|
199
|
+
this.#rights = config.rights ?? new RightsResolver(new MemoryRightsStore());
|
|
200
200
|
for (const [name, strategy] of Object.entries(guards)) {
|
|
201
|
-
this
|
|
201
|
+
this.#guards.set(name, strategy);
|
|
202
202
|
}
|
|
203
203
|
// Fail-fast at construction: an AuthManager with zero guards is a
|
|
204
204
|
// configuration bug. Previously, an empty `guards: {}` passed the
|
|
@@ -206,13 +206,13 @@ export class AuthManager {
|
|
|
206
206
|
// runtime when `getStrategy('jwt')` threw — opaque 401 or 500 instead
|
|
207
207
|
// of a boot-time INVALID_CONFIG that points the operator at the missing
|
|
208
208
|
// `config.auth.jwt` (or other guard).
|
|
209
|
-
if (this
|
|
209
|
+
if (this.#guards.size === 0) {
|
|
210
210
|
throw new WardenError(
|
|
211
211
|
"INVALID_CONFIG",
|
|
212
212
|
`AuthManager: no authentication guards registered. Configure at least one guard (e.g. config.warden.auth.jwt) before booting WardenProvider.`,
|
|
213
213
|
);
|
|
214
214
|
}
|
|
215
|
-
if (!this
|
|
215
|
+
if (!this.#guards.has(defaultGuard)) {
|
|
216
216
|
throw new WardenError(
|
|
217
217
|
"INVALID_CONFIG",
|
|
218
218
|
`default guard '${defaultGuard}' is not present in guards`,
|
|
@@ -285,7 +285,7 @@ export class AuthManager {
|
|
|
285
285
|
if (!isTokenIssuer(strategy)) {
|
|
286
286
|
throw new WardenError(
|
|
287
287
|
"STRATEGY_CANNOT_ISSUE",
|
|
288
|
-
`Auth strategy '${strategyName ?? this
|
|
288
|
+
`Auth strategy '${strategyName ?? this.#default}' cannot issue tokens.`,
|
|
289
289
|
{
|
|
290
290
|
hint: "issueFor() needs a token-minting strategy (e.g. JwtStrategy with signToken). Session / API-key strategies don't mint tokens.",
|
|
291
291
|
},
|
|
@@ -306,7 +306,7 @@ export class AuthManager {
|
|
|
306
306
|
user: UserPayload,
|
|
307
307
|
scope: Scope = "global",
|
|
308
308
|
): Promise<EffectivePermissions> {
|
|
309
|
-
return this
|
|
309
|
+
return this.#rights.resolve(user, scope);
|
|
310
310
|
}
|
|
311
311
|
|
|
312
312
|
/**
|
|
@@ -381,7 +381,7 @@ export class AuthManager {
|
|
|
381
381
|
if (!seam) {
|
|
382
382
|
throw new WardenError(
|
|
383
383
|
"STRATEGY_HAS_NO_CLIENT",
|
|
384
|
-
`Auth strategy '${guard ?? this
|
|
384
|
+
`Auth strategy '${guard ?? this.#default}' has no authenticateAsClient() — it cannot forge a client request.`,
|
|
385
385
|
{
|
|
386
386
|
hint: "Implement authenticateAsClient() on the strategy, or authenticate through a real login in the test.",
|
|
387
387
|
},
|
|
@@ -406,8 +406,8 @@ export class AuthManager {
|
|
|
406
406
|
}
|
|
407
407
|
|
|
408
408
|
getStrategy(name?: string): AuthStrategy {
|
|
409
|
-
const strategyName = name ?? this
|
|
410
|
-
const strategy = this
|
|
409
|
+
const strategyName = name ?? this.#default;
|
|
410
|
+
const strategy = this.#guards.get(strategyName);
|
|
411
411
|
if (!strategy) {
|
|
412
412
|
throw new WardenError(
|
|
413
413
|
"STRATEGY_NOT_FOUND",
|
|
@@ -426,17 +426,17 @@ export class AuthManager {
|
|
|
426
426
|
* declares none.
|
|
427
427
|
*/
|
|
428
428
|
get defaultStrategyName(): string {
|
|
429
|
-
return this
|
|
429
|
+
return this.#default;
|
|
430
430
|
}
|
|
431
431
|
|
|
432
432
|
/** Register a new strategy at runtime. */
|
|
433
433
|
registerStrategy(name: string, strategy: AuthStrategy): void {
|
|
434
|
-
this
|
|
434
|
+
this.#guards.set(name, strategy);
|
|
435
435
|
}
|
|
436
436
|
|
|
437
437
|
/** Get all registered strategy names. */
|
|
438
438
|
getStrategyNames(): string[] {
|
|
439
|
-
return [...this
|
|
439
|
+
return [...this.#guards.keys()];
|
|
440
440
|
}
|
|
441
441
|
|
|
442
442
|
/**
|
|
@@ -458,7 +458,7 @@ export class AuthManager {
|
|
|
458
458
|
if (!isLoginCapable(strategy)) {
|
|
459
459
|
throw new WardenError(
|
|
460
460
|
"STRATEGY_CANNOT_LOGIN",
|
|
461
|
-
`Auth strategy '${strategyName ?? this
|
|
461
|
+
`Auth strategy '${strategyName ?? this.#default}' does not support session login.`,
|
|
462
462
|
{
|
|
463
463
|
hint: "login()/logout() need a stateful guard (e.g. SessionStrategy). JWT / API-key guards are stateless — mint a token with issueFor() instead.",
|
|
464
464
|
},
|
|
@@ -466,12 +466,12 @@ export class AuthManager {
|
|
|
466
466
|
}
|
|
467
467
|
const prefix = authEventPrefix(strategy.name);
|
|
468
468
|
this.#emit(`${prefix}:login_attempted`, {
|
|
469
|
-
guardName: strategyName ?? this
|
|
469
|
+
guardName: strategyName ?? this.#default,
|
|
470
470
|
user,
|
|
471
471
|
});
|
|
472
472
|
await strategy.login(user, session);
|
|
473
473
|
this.#emit(`${prefix}:login_succeeded`, {
|
|
474
|
-
guardName: strategyName ?? this
|
|
474
|
+
guardName: strategyName ?? this.#default,
|
|
475
475
|
user,
|
|
476
476
|
sessionId: undefined,
|
|
477
477
|
});
|
|
@@ -487,12 +487,12 @@ export class AuthManager {
|
|
|
487
487
|
if (!isLoginCapable(strategy)) {
|
|
488
488
|
throw new WardenError(
|
|
489
489
|
"STRATEGY_CANNOT_LOGIN",
|
|
490
|
-
`Auth strategy '${strategyName ?? this
|
|
490
|
+
`Auth strategy '${strategyName ?? this.#default}' does not support session logout.`,
|
|
491
491
|
);
|
|
492
492
|
}
|
|
493
493
|
await strategy.logout(session);
|
|
494
494
|
this.#emit(`${authEventPrefix(strategy.name)}:logged_out`, {
|
|
495
|
-
guardName: strategyName ?? this
|
|
495
|
+
guardName: strategyName ?? this.#default,
|
|
496
496
|
user: null,
|
|
497
497
|
error: null,
|
|
498
498
|
});
|
package/src/AuthRateLimiter.ts
CHANGED
|
@@ -17,16 +17,16 @@ interface AttemptEntry {
|
|
|
17
17
|
}
|
|
18
18
|
|
|
19
19
|
export class AuthRateLimiter {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
20
|
+
#maxAttempts: number;
|
|
21
|
+
#window: number;
|
|
22
|
+
#store: Map<string, AttemptEntry> = new Map();
|
|
23
|
+
#maxStoreSize = 100_000;
|
|
24
24
|
|
|
25
25
|
constructor(config?: AuthRateLimiterConfig) {
|
|
26
|
-
this
|
|
27
|
-
if (this
|
|
28
|
-
this
|
|
29
|
-
if (this
|
|
26
|
+
this.#maxAttempts = config?.maxAttempts ?? 5;
|
|
27
|
+
if (this.#maxAttempts <= 0) this.#maxAttempts = 1;
|
|
28
|
+
this.#window = (config?.windowSeconds ?? 900) * 1000;
|
|
29
|
+
if (this.#window <= 0) this.#window = 900_000; // prevent bypass via 0/negative
|
|
30
30
|
}
|
|
31
31
|
|
|
32
32
|
/** Check if an attempt is allowed. Returns false if rate limited. */
|
|
@@ -38,7 +38,7 @@ export class AuthRateLimiter {
|
|
|
38
38
|
const ipKey = `ip:${ipNorm}`;
|
|
39
39
|
const idKey = `id:${identifierNorm}`;
|
|
40
40
|
|
|
41
|
-
return this
|
|
41
|
+
return this.#checkKey(ipKey, now) && this.#checkKey(idKey, now);
|
|
42
42
|
}
|
|
43
43
|
|
|
44
44
|
/** Record a failed attempt. */
|
|
@@ -46,51 +46,51 @@ export class AuthRateLimiter {
|
|
|
46
46
|
const now = Date.now();
|
|
47
47
|
const ipNorm = normalizeIp(ip);
|
|
48
48
|
const identifierNorm = normalizeIdentifier(identifier);
|
|
49
|
-
this
|
|
50
|
-
this
|
|
49
|
+
this.#increment(`ip:${ipNorm}`, now);
|
|
50
|
+
this.#increment(`id:${identifierNorm}`, now);
|
|
51
51
|
}
|
|
52
52
|
|
|
53
53
|
/** Reset counters on successful login. */
|
|
54
54
|
recordSuccess(ip: string, identifier: string): void {
|
|
55
55
|
const ipNorm = normalizeIp(ip);
|
|
56
56
|
const identifierNorm = normalizeIdentifier(identifier);
|
|
57
|
-
this
|
|
58
|
-
this
|
|
57
|
+
this.#store.delete(`ip:${ipNorm}`);
|
|
58
|
+
this.#store.delete(`id:${identifierNorm}`);
|
|
59
59
|
}
|
|
60
60
|
|
|
61
61
|
/** Get remaining attempts for an identifier. */
|
|
62
62
|
remaining(ip: string, identifier: string): number {
|
|
63
63
|
const ipNorm = normalizeIp(ip);
|
|
64
64
|
const identifierNorm = normalizeIdentifier(identifier);
|
|
65
|
-
const ipEntry = this
|
|
66
|
-
const idEntry = this
|
|
65
|
+
const ipEntry = this.#store.get(`ip:${ipNorm}`);
|
|
66
|
+
const idEntry = this.#store.get(`id:${identifierNorm}`);
|
|
67
67
|
const ipRemaining = ipEntry
|
|
68
|
-
? Math.max(0, this
|
|
69
|
-
: this
|
|
68
|
+
? Math.max(0, this.#maxAttempts - ipEntry.count)
|
|
69
|
+
: this.#maxAttempts;
|
|
70
70
|
const idRemaining = idEntry
|
|
71
|
-
? Math.max(0, this
|
|
72
|
-
: this
|
|
71
|
+
? Math.max(0, this.#maxAttempts - idEntry.count)
|
|
72
|
+
: this.#maxAttempts;
|
|
73
73
|
return Math.min(ipRemaining, idRemaining);
|
|
74
74
|
}
|
|
75
75
|
|
|
76
|
-
|
|
77
|
-
const entry = this
|
|
76
|
+
#checkKey(key: string, now: number): boolean {
|
|
77
|
+
const entry = this.#store.get(key);
|
|
78
78
|
if (!entry || entry.resetAt < now) return true;
|
|
79
|
-
return entry.count < this
|
|
79
|
+
return entry.count < this.#maxAttempts;
|
|
80
80
|
}
|
|
81
81
|
|
|
82
|
-
|
|
82
|
+
#increment(key: string, now: number): void {
|
|
83
83
|
// Evict expired entries when store grows too large (prevent OOM)
|
|
84
|
-
if (this
|
|
85
|
-
for (const [k, v] of this
|
|
86
|
-
if (v.resetAt < now) this
|
|
84
|
+
if (this.#store.size > this.#maxStoreSize) {
|
|
85
|
+
for (const [k, v] of this.#store) {
|
|
86
|
+
if (v.resetAt < now) this.#store.delete(k);
|
|
87
87
|
}
|
|
88
88
|
}
|
|
89
89
|
|
|
90
|
-
let entry = this
|
|
90
|
+
let entry = this.#store.get(key);
|
|
91
91
|
if (!entry || entry.resetAt < now) {
|
|
92
|
-
entry = { count: 0, resetAt: now + this
|
|
93
|
-
this
|
|
92
|
+
entry = { count: 0, resetAt: now + this.#window };
|
|
93
|
+
this.#store.set(key, entry);
|
|
94
94
|
}
|
|
95
95
|
entry.count++;
|
|
96
96
|
}
|
package/src/RefreshTokenStore.ts
CHANGED
|
@@ -27,36 +27,36 @@ export interface RefreshTokenDriver {
|
|
|
27
27
|
|
|
28
28
|
/** In-memory driver for development. */
|
|
29
29
|
export class MemoryRefreshTokenDriver implements RefreshTokenDriver {
|
|
30
|
-
|
|
30
|
+
#tokens: Map<string, StoredRefreshToken> = new Map();
|
|
31
31
|
|
|
32
32
|
async store(token: StoredRefreshToken): Promise<void> {
|
|
33
|
-
this
|
|
33
|
+
this.#tokens.set(token.token, token);
|
|
34
34
|
}
|
|
35
35
|
|
|
36
36
|
async find(token: string): Promise<StoredRefreshToken | null> {
|
|
37
|
-
const stored = this
|
|
37
|
+
const stored = this.#tokens.get(token);
|
|
38
38
|
if (!stored) return null;
|
|
39
39
|
if (stored.expiresAt < Date.now()) {
|
|
40
|
-
this
|
|
40
|
+
this.#tokens.delete(token);
|
|
41
41
|
return null;
|
|
42
42
|
}
|
|
43
43
|
return stored;
|
|
44
44
|
}
|
|
45
45
|
|
|
46
46
|
async revoke(token: string): Promise<void> {
|
|
47
|
-
this
|
|
47
|
+
this.#tokens.delete(token);
|
|
48
48
|
}
|
|
49
49
|
|
|
50
50
|
async revokeAllForUser(userId: string | number): Promise<void> {
|
|
51
|
-
for (const [key, val] of this
|
|
52
|
-
if (val.userId === userId) this
|
|
51
|
+
for (const [key, val] of this.#tokens) {
|
|
52
|
+
if (val.userId === userId) this.#tokens.delete(key);
|
|
53
53
|
}
|
|
54
54
|
}
|
|
55
55
|
|
|
56
56
|
async cleanup(): Promise<void> {
|
|
57
57
|
const now = Date.now();
|
|
58
|
-
for (const [key, val] of this
|
|
59
|
-
if (val.expiresAt < now) this
|
|
58
|
+
for (const [key, val] of this.#tokens) {
|
|
59
|
+
if (val.expiresAt < now) this.#tokens.delete(key);
|
|
60
60
|
}
|
|
61
61
|
}
|
|
62
62
|
}
|
package/src/TokenBlacklist.ts
CHANGED
|
@@ -18,17 +18,17 @@ export interface BlacklistDriver {
|
|
|
18
18
|
|
|
19
19
|
/** In-memory blacklist for development. */
|
|
20
20
|
export class MemoryBlacklistDriver implements BlacklistDriver {
|
|
21
|
-
|
|
21
|
+
#entries: Map<string, number> = new Map();
|
|
22
22
|
|
|
23
23
|
async add(jti: string, expiresAt: number): Promise<void> {
|
|
24
|
-
this
|
|
24
|
+
this.#entries.set(jti, expiresAt);
|
|
25
25
|
}
|
|
26
26
|
|
|
27
27
|
async has(jti: string): Promise<boolean> {
|
|
28
|
-
const expiresAt = this
|
|
28
|
+
const expiresAt = this.#entries.get(jti);
|
|
29
29
|
if (expiresAt === undefined) return false;
|
|
30
30
|
if (expiresAt < Date.now()) {
|
|
31
|
-
this
|
|
31
|
+
this.#entries.delete(jti);
|
|
32
32
|
return false;
|
|
33
33
|
}
|
|
34
34
|
return true;
|
|
@@ -36,8 +36,8 @@ export class MemoryBlacklistDriver implements BlacklistDriver {
|
|
|
36
36
|
|
|
37
37
|
async cleanup(): Promise<void> {
|
|
38
38
|
const now = Date.now();
|
|
39
|
-
for (const [jti, exp] of this
|
|
40
|
-
if (exp < now) this
|
|
39
|
+
for (const [jti, exp] of this.#entries) {
|
|
40
|
+
if (exp < now) this.#entries.delete(jti);
|
|
41
41
|
}
|
|
42
42
|
}
|
|
43
43
|
}
|
package/src/augmentations.ts
CHANGED
|
@@ -15,6 +15,12 @@ export class AuthorizationResponse {
|
|
|
15
15
|
/** i18n binding set via {@link t} (Adonis `AuthorizationResponse.t`). */
|
|
16
16
|
translation?: { identifier: string; data?: Record<string, unknown> };
|
|
17
17
|
|
|
18
|
+
/**
|
|
19
|
+
* Private because a response is only ever built through allow() / deny(), so the pair stays consistent.
|
|
20
|
+
*
|
|
21
|
+
* `private` and not `#`: a private CONSTRUCTOR has no native form. It is the
|
|
22
|
+
* one place the keyword expresses something `#` cannot.
|
|
23
|
+
*/
|
|
18
24
|
private constructor(authorized: boolean, message?: string, status?: number) {
|
|
19
25
|
this.authorized = authorized;
|
|
20
26
|
this.message = message;
|
|
@@ -15,11 +15,11 @@ import { type RightsStore, type Scope, scopeKey } from "./types.js";
|
|
|
15
15
|
|
|
16
16
|
export class MemoryRightsStore implements RightsStore {
|
|
17
17
|
/** scopeKey → role → permissions */
|
|
18
|
-
|
|
18
|
+
readonly #roleDefs = new Map<string, Map<string, Set<string>>>();
|
|
19
19
|
/** scopeKey → userId → roles */
|
|
20
|
-
|
|
20
|
+
readonly #userRoleMap = new Map<string, Map<string, Set<string>>>();
|
|
21
21
|
/** scopeKey → userId → directly granted permissions */
|
|
22
|
-
|
|
22
|
+
readonly #userGrantMap = new Map<string, Map<string, Set<string>>>();
|
|
23
23
|
|
|
24
24
|
// — read contract —
|
|
25
25
|
|
|
@@ -27,15 +27,15 @@ export class MemoryRightsStore implements RightsStore {
|
|
|
27
27
|
role: string,
|
|
28
28
|
scope: Scope,
|
|
29
29
|
): Promise<readonly string[]> {
|
|
30
|
-
return snapshot(this
|
|
30
|
+
return snapshot(this.#roleDefs.get(scopeKey(scope))?.get(role));
|
|
31
31
|
}
|
|
32
32
|
|
|
33
33
|
async userRoles(userId: string, scope: Scope): Promise<readonly string[]> {
|
|
34
|
-
return snapshot(this
|
|
34
|
+
return snapshot(this.#userRoleMap.get(scopeKey(scope))?.get(userId));
|
|
35
35
|
}
|
|
36
36
|
|
|
37
37
|
async userGrants(userId: string, scope: Scope): Promise<readonly string[]> {
|
|
38
|
-
return snapshot(this
|
|
38
|
+
return snapshot(this.#userGrantMap.get(scopeKey(scope))?.get(userId));
|
|
39
39
|
}
|
|
40
40
|
|
|
41
41
|
// — seeding (in-memory driver only; not part of RightsStore) —
|
|
@@ -45,24 +45,24 @@ export class MemoryRightsStore implements RightsStore {
|
|
|
45
45
|
permissions: readonly string[],
|
|
46
46
|
scope: Scope = "global",
|
|
47
47
|
): this {
|
|
48
|
-
const set = bucket(this
|
|
48
|
+
const set = bucket(this.#roleDefs, scopeKey(scope), role);
|
|
49
49
|
set.clear();
|
|
50
50
|
for (const perm of permissions) set.add(perm);
|
|
51
51
|
return this;
|
|
52
52
|
}
|
|
53
53
|
|
|
54
54
|
assignRole(userId: string, role: string, scope: Scope = "global"): this {
|
|
55
|
-
bucket(this
|
|
55
|
+
bucket(this.#userRoleMap, scopeKey(scope), userId).add(role);
|
|
56
56
|
return this;
|
|
57
57
|
}
|
|
58
58
|
|
|
59
59
|
grant(userId: string, permission: string, scope: Scope = "global"): this {
|
|
60
|
-
bucket(this
|
|
60
|
+
bucket(this.#userGrantMap, scopeKey(scope), userId).add(permission);
|
|
61
61
|
return this;
|
|
62
62
|
}
|
|
63
63
|
|
|
64
64
|
revoke(userId: string, permission: string, scope: Scope = "global"): this {
|
|
65
|
-
this
|
|
65
|
+
this.#userGrantMap.get(scopeKey(scope))?.get(userId)?.delete(permission);
|
|
66
66
|
return this;
|
|
67
67
|
}
|
|
68
68
|
}
|