@kurdel/auth 0.1.0-beta.4 → 0.1.0-beta.6
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/README.md +28 -24
- package/lib/domain/auth-context.d.ts +16 -1
- package/lib/domain/auth-event-sink-provider.d.ts +10 -0
- package/lib/domain/auth-event.d.ts +34 -3
- package/lib/domain/auth-event.js +8 -1
- package/lib/domain/auth-event.js.map +1 -1
- package/lib/domain/auth-strategy-provider.d.ts +17 -0
- package/lib/domain/auth-strategy.d.ts +17 -7
- package/lib/domain/authorization-policy-composition.d.ts +20 -3
- package/lib/domain/authorization-policy-composition.js +24 -3
- package/lib/domain/authorization-policy-composition.js.map +1 -1
- package/lib/domain/authorization-policy-provider.d.ts +17 -0
- package/lib/domain/authorization-policy.d.ts +39 -3
- package/lib/domain/authorization-policy.js +8 -2
- package/lib/domain/authorization-policy.js.map +1 -1
- package/lib/domain/permission.d.ts +12 -2
- package/lib/domain/permission.js +16 -3
- package/lib/domain/permission.js.map +1 -1
- package/lib/infra/in-memory/in-memory-api-key-repository.d.ts +11 -1
- package/lib/infra/in-memory/in-memory-api-key-repository.js +11 -1
- package/lib/infra/in-memory/in-memory-api-key-repository.js.map +1 -1
- package/lib/infra/in-memory/in-memory-auth-user-repository.d.ts +11 -1
- package/lib/infra/in-memory/in-memory-auth-user-repository.js +11 -1
- package/lib/infra/in-memory/in-memory-auth-user-repository.js.map +1 -1
- package/lib/infra/in-memory/in-memory-jwt-repository.d.ts +5 -1
- package/lib/infra/in-memory/in-memory-jwt-repository.js +5 -1
- package/lib/infra/in-memory/in-memory-jwt-repository.js.map +1 -1
- package/lib/password/password-authentication-service.d.ts +29 -0
- package/lib/password/password-authentication-service.js +31 -1
- package/lib/password/password-authentication-service.js.map +1 -1
- package/lib/password/password-hasher.d.ts +18 -0
- package/lib/password/scrypt-password-hasher.d.ts +46 -1
- package/lib/password/scrypt-password-hasher.js +33 -1
- package/lib/password/scrypt-password-hasher.js.map +1 -1
- package/lib/repositories/api-key/api-key-repository.d.ts +22 -12
- package/lib/repositories/api-key/api-key-usage-recorder.d.ts +12 -1
- package/lib/repositories/jwt/jwt-repository.d.ts +7 -1
- package/lib/repositories/jwt/jwt-session-repository.d.ts +27 -3
- package/lib/repositories/password/password-credential-repository.d.ts +25 -1
- package/lib/repositories/user/auth-user-repository.d.ts +16 -4
- package/lib/runtime/auth-module.d.ts +32 -28
- package/lib/runtime/auth-module.js +26 -12
- package/lib/runtime/auth-module.js.map +1 -1
- package/lib/runtime/auth-strategy-registry.d.ts +24 -7
- package/lib/runtime/auth-strategy-registry.js +24 -7
- package/lib/runtime/auth-strategy-registry.js.map +1 -1
- package/lib/runtime/authorization-policy-registry.d.ts +35 -1
- package/lib/runtime/authorization-policy-registry.js +35 -1
- package/lib/runtime/authorization-policy-registry.js.map +1 -1
- package/lib/runtime/create-auth-middleware.d.ts +32 -0
- package/lib/runtime/create-auth-middleware.js +41 -2
- package/lib/runtime/create-auth-middleware.js.map +1 -1
- package/lib/strategies/api-key/api-key-strategy-provider.d.ts +18 -0
- package/lib/strategies/api-key/api-key-strategy-provider.js +30 -0
- package/lib/strategies/api-key/api-key-strategy-provider.js.map +1 -0
- package/lib/strategies/api-key/api-key-strategy.d.ts +39 -1
- package/lib/strategies/api-key/api-key-strategy.js +34 -1
- package/lib/strategies/api-key/api-key-strategy.js.map +1 -1
- package/lib/strategies/api-key/index.d.ts +1 -0
- package/lib/strategies/api-key/index.js +1 -0
- package/lib/strategies/api-key/index.js.map +1 -1
- package/lib/strategies/jwt/index.d.ts +1 -0
- package/lib/strategies/jwt/index.js +1 -0
- package/lib/strategies/jwt/index.js.map +1 -1
- package/lib/strategies/jwt/jwt-service.d.ts +61 -10
- package/lib/strategies/jwt/jwt-service.js +38 -9
- package/lib/strategies/jwt/jwt-service.js.map +1 -1
- package/lib/strategies/jwt/jwt-strategy-provider.d.ts +18 -0
- package/lib/strategies/jwt/jwt-strategy-provider.js +27 -0
- package/lib/strategies/jwt/jwt-strategy-provider.js.map +1 -0
- package/lib/strategies/jwt/jwt-strategy.d.ts +43 -4
- package/lib/strategies/jwt/jwt-strategy.js +26 -2
- package/lib/strategies/jwt/jwt-strategy.js.map +1 -1
- package/package.json +4 -4
|
@@ -1,30 +1,47 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* ## AuthStrategyRegistry
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
4
|
+
* Stores authentication strategies by name.
|
|
5
|
+
*
|
|
6
|
+
* Responsibilities:
|
|
7
|
+
* - register authentication strategies during application startup
|
|
8
|
+
* - resolve strategies by name during request processing
|
|
9
|
+
* - allow strategies to be replaced or removed if required
|
|
10
|
+
*
|
|
11
|
+
* Guarantees:
|
|
12
|
+
* - at most one strategy exists for a given name
|
|
13
|
+
* - registering an existing name replaces the previous strategy
|
|
14
|
+
*
|
|
15
|
+
* Non-responsibilities:
|
|
16
|
+
* - strategy execution
|
|
17
|
+
* - authentication orchestration
|
|
18
|
+
* - request handling
|
|
6
19
|
*/
|
|
7
20
|
export class AuthStrategyRegistry {
|
|
8
21
|
constructor() {
|
|
9
22
|
this.strategies = new Map();
|
|
10
23
|
}
|
|
11
24
|
/**
|
|
12
|
-
* Registers
|
|
25
|
+
* Registers or replaces an authentication strategy.
|
|
13
26
|
*
|
|
14
|
-
* @param name
|
|
15
|
-
* @param strategy
|
|
27
|
+
* @param name Strategy identifier.
|
|
28
|
+
* @param strategy Authentication strategy implementation.
|
|
16
29
|
*/
|
|
17
30
|
register(name, strategy) {
|
|
18
31
|
this.strategies.set(name, strategy);
|
|
19
32
|
}
|
|
20
33
|
/**
|
|
21
|
-
* Returns
|
|
34
|
+
* Returns the strategy registered under the specified name.
|
|
35
|
+
*
|
|
36
|
+
* @param name Strategy identifier.
|
|
22
37
|
*/
|
|
23
38
|
get(name) {
|
|
24
39
|
return this.strategies.get(name);
|
|
25
40
|
}
|
|
26
41
|
/**
|
|
27
|
-
* Removes
|
|
42
|
+
* Removes the strategy associated with the specified name.
|
|
43
|
+
*
|
|
44
|
+
* @param name Strategy identifier.
|
|
28
45
|
*/
|
|
29
46
|
unregister(name) {
|
|
30
47
|
this.strategies.delete(name);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"auth-strategy-registry.js","sourceRoot":"","sources":["../../src/runtime/auth-strategy-registry.ts"],"names":[],"mappings":"AAEA
|
|
1
|
+
{"version":3,"file":"auth-strategy-registry.js","sourceRoot":"","sources":["../../src/runtime/auth-strategy-registry.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,OAAO,oBAAoB;IAAjC;QACmB,eAAU,GAAG,IAAI,GAAG,EAAwB,CAAC;IA6BhE,CAAC;IA3BC;;;;;OAKG;IACH,QAAQ,CAAC,IAAY,EAAE,QAAsB;QAC3C,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC;IACtC,CAAC;IAED;;;;OAIG;IACH,GAAG,CAAC,IAAY;QACd,OAAO,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;IACnC,CAAC;IAED;;;;OAIG;IACH,UAAU,CAAC,IAAY;QACrB,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;IAC/B,CAAC;CACF"}
|
|
@@ -1,8 +1,42 @@
|
|
|
1
1
|
import type { AuthorizationPolicy } from '../domain/index.js';
|
|
2
|
-
/**
|
|
2
|
+
/**
|
|
3
|
+
* ## AuthorizationPolicyRegistry
|
|
4
|
+
*
|
|
5
|
+
* Stores authorization policies by name.
|
|
6
|
+
*
|
|
7
|
+
* Responsibilities:
|
|
8
|
+
* - register authorization policies during application startup
|
|
9
|
+
* - resolve policies by name during request processing
|
|
10
|
+
* - allow policies to be replaced or removed if required
|
|
11
|
+
*
|
|
12
|
+
* Guarantees:
|
|
13
|
+
* - at most one policy exists for a given name
|
|
14
|
+
* - registering an existing name replaces the previous policy
|
|
15
|
+
*
|
|
16
|
+
* Non-responsibilities:
|
|
17
|
+
* - policy evaluation
|
|
18
|
+
* - authentication
|
|
19
|
+
* - request handling
|
|
20
|
+
*/
|
|
3
21
|
export declare class AuthorizationPolicyRegistry {
|
|
4
22
|
private readonly policies;
|
|
23
|
+
/**
|
|
24
|
+
* Registers or replaces an authorization policy.
|
|
25
|
+
*
|
|
26
|
+
* @param name Policy identifier.
|
|
27
|
+
* @param policy Authorization policy implementation.
|
|
28
|
+
*/
|
|
5
29
|
register(name: string, policy: AuthorizationPolicy): void;
|
|
30
|
+
/**
|
|
31
|
+
* Returns the policy registered under the specified name.
|
|
32
|
+
*
|
|
33
|
+
* @param name Policy identifier.
|
|
34
|
+
*/
|
|
6
35
|
get(name: string): AuthorizationPolicy | undefined;
|
|
36
|
+
/**
|
|
37
|
+
* Removes the policy associated with the specified name.
|
|
38
|
+
*
|
|
39
|
+
* @param name Policy identifier.
|
|
40
|
+
*/
|
|
7
41
|
unregister(name: string): void;
|
|
8
42
|
}
|
|
@@ -1,14 +1,48 @@
|
|
|
1
|
-
/**
|
|
1
|
+
/**
|
|
2
|
+
* ## AuthorizationPolicyRegistry
|
|
3
|
+
*
|
|
4
|
+
* Stores authorization policies by name.
|
|
5
|
+
*
|
|
6
|
+
* Responsibilities:
|
|
7
|
+
* - register authorization policies during application startup
|
|
8
|
+
* - resolve policies by name during request processing
|
|
9
|
+
* - allow policies to be replaced or removed if required
|
|
10
|
+
*
|
|
11
|
+
* Guarantees:
|
|
12
|
+
* - at most one policy exists for a given name
|
|
13
|
+
* - registering an existing name replaces the previous policy
|
|
14
|
+
*
|
|
15
|
+
* Non-responsibilities:
|
|
16
|
+
* - policy evaluation
|
|
17
|
+
* - authentication
|
|
18
|
+
* - request handling
|
|
19
|
+
*/
|
|
2
20
|
export class AuthorizationPolicyRegistry {
|
|
3
21
|
constructor() {
|
|
4
22
|
this.policies = new Map();
|
|
5
23
|
}
|
|
24
|
+
/**
|
|
25
|
+
* Registers or replaces an authorization policy.
|
|
26
|
+
*
|
|
27
|
+
* @param name Policy identifier.
|
|
28
|
+
* @param policy Authorization policy implementation.
|
|
29
|
+
*/
|
|
6
30
|
register(name, policy) {
|
|
7
31
|
this.policies.set(name, policy);
|
|
8
32
|
}
|
|
33
|
+
/**
|
|
34
|
+
* Returns the policy registered under the specified name.
|
|
35
|
+
*
|
|
36
|
+
* @param name Policy identifier.
|
|
37
|
+
*/
|
|
9
38
|
get(name) {
|
|
10
39
|
return this.policies.get(name);
|
|
11
40
|
}
|
|
41
|
+
/**
|
|
42
|
+
* Removes the policy associated with the specified name.
|
|
43
|
+
*
|
|
44
|
+
* @param name Policy identifier.
|
|
45
|
+
*/
|
|
12
46
|
unregister(name) {
|
|
13
47
|
this.policies.delete(name);
|
|
14
48
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"authorization-policy-registry.js","sourceRoot":"","sources":["../../src/runtime/authorization-policy-registry.ts"],"names":[],"mappings":"AAEA
|
|
1
|
+
{"version":3,"file":"authorization-policy-registry.js","sourceRoot":"","sources":["../../src/runtime/authorization-policy-registry.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,OAAO,2BAA2B;IAAxC;QACmB,aAAQ,GAAG,IAAI,GAAG,EAA+B,CAAC;IA6BrE,CAAC;IA3BC;;;;;OAKG;IACH,QAAQ,CAAC,IAAY,EAAE,MAA2B;QAChD,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;IAClC,CAAC;IAED;;;;OAIG;IACH,GAAG,CAAC,IAAY;QACd,OAAO,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;IACjC,CAAC;IAED;;;;OAIG;IACH,UAAU,CAAC,IAAY;QACrB,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;IAC7B,CAAC;CACF"}
|
|
@@ -2,4 +2,36 @@ import type { Middleware } from '@kurdel/core/http';
|
|
|
2
2
|
import { type AuthEventSink } from '../domain/index.js';
|
|
3
3
|
import type { AuthStrategyRegistry } from './auth-strategy-registry.js';
|
|
4
4
|
import { AuthorizationPolicyRegistry } from './authorization-policy-registry.js';
|
|
5
|
+
/**
|
|
6
|
+
* ## createAuthMiddleware
|
|
7
|
+
*
|
|
8
|
+
* Creates the authentication and authorization middleware.
|
|
9
|
+
*
|
|
10
|
+
* Responsibilities:
|
|
11
|
+
* - authenticate incoming requests
|
|
12
|
+
* - populate `HttpContext.auth` and `HttpContext.user`
|
|
13
|
+
* - enforce route role requirements
|
|
14
|
+
* - evaluate configured authorization policies
|
|
15
|
+
* - emit sanitized authentication lifecycle events
|
|
16
|
+
*
|
|
17
|
+
* Guarantees:
|
|
18
|
+
* - authentication executes before authorization
|
|
19
|
+
* - route handlers execute only after successful authorization
|
|
20
|
+
* - authentication events are emitted in execution order
|
|
21
|
+
* - authorization policies execute sequentially
|
|
22
|
+
*
|
|
23
|
+
* Non-responsibilities:
|
|
24
|
+
* - credential persistence
|
|
25
|
+
* - user management
|
|
26
|
+
* - session management
|
|
27
|
+
*
|
|
28
|
+
* Pipeline:
|
|
29
|
+
*
|
|
30
|
+
* 1. Skip public routes.
|
|
31
|
+
* 2. Authenticate using the configured strategy.
|
|
32
|
+
* 3. Populate the authentication context.
|
|
33
|
+
* 4. Validate required roles.
|
|
34
|
+
* 5. Evaluate authorization policies.
|
|
35
|
+
* 6. Continue the middleware pipeline.
|
|
36
|
+
*/
|
|
5
37
|
export declare function createAuthMiddleware(registry: AuthStrategyRegistry, policies?: AuthorizationPolicyRegistry, events?: AuthEventSink, now?: () => Date): Middleware;
|
|
@@ -1,5 +1,37 @@
|
|
|
1
1
|
import { authorizationDecision, NoopAuthEventSink, } from '../domain/index.js';
|
|
2
2
|
import { AuthorizationPolicyRegistry } from './authorization-policy-registry.js';
|
|
3
|
+
/**
|
|
4
|
+
* ## createAuthMiddleware
|
|
5
|
+
*
|
|
6
|
+
* Creates the authentication and authorization middleware.
|
|
7
|
+
*
|
|
8
|
+
* Responsibilities:
|
|
9
|
+
* - authenticate incoming requests
|
|
10
|
+
* - populate `HttpContext.auth` and `HttpContext.user`
|
|
11
|
+
* - enforce route role requirements
|
|
12
|
+
* - evaluate configured authorization policies
|
|
13
|
+
* - emit sanitized authentication lifecycle events
|
|
14
|
+
*
|
|
15
|
+
* Guarantees:
|
|
16
|
+
* - authentication executes before authorization
|
|
17
|
+
* - route handlers execute only after successful authorization
|
|
18
|
+
* - authentication events are emitted in execution order
|
|
19
|
+
* - authorization policies execute sequentially
|
|
20
|
+
*
|
|
21
|
+
* Non-responsibilities:
|
|
22
|
+
* - credential persistence
|
|
23
|
+
* - user management
|
|
24
|
+
* - session management
|
|
25
|
+
*
|
|
26
|
+
* Pipeline:
|
|
27
|
+
*
|
|
28
|
+
* 1. Skip public routes.
|
|
29
|
+
* 2. Authenticate using the configured strategy.
|
|
30
|
+
* 3. Populate the authentication context.
|
|
31
|
+
* 4. Validate required roles.
|
|
32
|
+
* 5. Evaluate authorization policies.
|
|
33
|
+
* 6. Continue the middleware pipeline.
|
|
34
|
+
*/
|
|
3
35
|
export function createAuthMiddleware(registry, policies = new AuthorizationPolicyRegistry(), events = new NoopAuthEventSink(), now = () => new Date()) {
|
|
4
36
|
return async (ctx, next) => {
|
|
5
37
|
const meta = ctx.route?.auth;
|
|
@@ -8,7 +40,9 @@ export function createAuthMiddleware(registry, policies = new AuthorizationPolic
|
|
|
8
40
|
return next();
|
|
9
41
|
}
|
|
10
42
|
const { strategy, roles, policies: requiredPolicies } = meta;
|
|
11
|
-
//
|
|
43
|
+
// ---------------------------------------------------------------------
|
|
44
|
+
// 1. Authentication
|
|
45
|
+
// ---------------------------------------------------------------------
|
|
12
46
|
let auth;
|
|
13
47
|
if (strategy) {
|
|
14
48
|
const strat = registry.get(strategy);
|
|
@@ -39,7 +73,9 @@ export function createAuthMiddleware(registry, policies = new AuthorizationPolic
|
|
|
39
73
|
...(auth.credential ? { credential: auth.credential } : {}),
|
|
40
74
|
});
|
|
41
75
|
}
|
|
42
|
-
//
|
|
76
|
+
// ---------------------------------------------------------------------
|
|
77
|
+
// 2. Role authorization
|
|
78
|
+
// ---------------------------------------------------------------------
|
|
43
79
|
if (roles && roles.length > 0) {
|
|
44
80
|
const ok = auth && Array.isArray(auth.user.roles)
|
|
45
81
|
? roles.some(r => auth.user.roles.includes(r))
|
|
@@ -55,6 +91,9 @@ export function createAuthMiddleware(registry, policies = new AuthorizationPolic
|
|
|
55
91
|
return ctx.json(403, { error: 'Forbidden' });
|
|
56
92
|
}
|
|
57
93
|
}
|
|
94
|
+
// ---------------------------------------------------------------------
|
|
95
|
+
// 3. Policy authorization
|
|
96
|
+
// ---------------------------------------------------------------------
|
|
58
97
|
if (requiredPolicies && requiredPolicies.length > 0) {
|
|
59
98
|
if (!auth) {
|
|
60
99
|
await events.report({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"create-auth-middleware.js","sourceRoot":"","sources":["../../src/runtime/create-auth-middleware.ts"],"names":[],"mappings":"AACA,OAAO,EACL,qBAAqB,EACrB,iBAAiB,GAGlB,MAAM,qBAAqB,CAAC;AAG7B,OAAO,EAAE,2BAA2B,EAAE,MAAM,oCAAoC,CAAC;AAEjF,MAAM,UAAU,oBAAoB,CAClC,QAA8B,EAC9B,WAAwC,IAAI,2BAA2B,EAAE,EACzE,SAAwB,IAAI,iBAAiB,EAAE,EAC/C,MAAkB,GAAG,EAAE,CAAC,IAAI,IAAI,EAAE;IAElC,OAAO,KAAK,EAAE,GAAG,EAAE,IAAI,EAAE,EAAE;QACzB,MAAM,IAAI,GAAG,GAAG,CAAC,KAAK,EAAE,IAAI,CAAC;QAC7B,IAAI,CAAC,IAAI,IAAI,IAAI,CAAC,MAAM,EAAE,CAAC;YACzB,eAAe;YACf,OAAO,IAAI,EAAE,CAAC;QAChB,CAAC;QAED,MAAM,EAAE,QAAQ,EAA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,CAAC,CAAC,CAAC;gBAC1E,IAAI,CAAC,QAAQ,CAAC,OAAO,EAAE,CAAC;oBACtB,MAAM,MAAM,CAAC,MAAM,CAAC;wBAClB,IAAI,EAAE,sBAAsB;wBAC5B,UAAU,EAAE,GAAG,EAAE;wBACjB,QAAQ,EAAE,IAAI,CAAC,QAAQ;wBACvB,MAAM,EAAE,IAAI,CAAC,IAAI,CAAC,EAAE;wBACpB,GAAG,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC,EAAE,UAAU,EAAE,IAAI,CAAC,UAAU,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;wBAC3D,MAAM,EAAE,iBAAiB;wBACzB,MAAM,EAAE,IAAI;wBACZ,GAAG,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,cAAc,EAAE,QAAQ,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;qBAChE,CAAC,CAAC;oBACH,OAAO,GAAG,CAAC,IAAI,CAAC,GAAG,EAAE,EAAE,KAAK,EAAE,WAAW,EAAE,CAAC,CAAC;gBAC/C,CAAC;YACH,CAAC;QACH,CAAC;QAED,OAAO,IAAI,EAAE,CAAC;IAChB,CAAC,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { AuthStrategyProvider } from '../../domain/auth-strategy-provider.js';
|
|
2
|
+
import type { ApiKeyUsageRecorder } from '../../repositories/api-key/api-key-usage-recorder.js';
|
|
3
|
+
/** Declarative options for the built-in API-key strategy provider. */
|
|
4
|
+
export interface ApiKeyStrategyProviderOptions {
|
|
5
|
+
/** Request header containing the API key. @default "x-api-key" */
|
|
6
|
+
header?: string;
|
|
7
|
+
/** Enables usage recording or supplies a custom recorder. */
|
|
8
|
+
usage?: boolean | ApiKeyUsageRecorder;
|
|
9
|
+
/** Injectable clock for deterministic expiration behavior. */
|
|
10
|
+
now?: () => Date;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Creates a DI-backed API-key authentication strategy provider.
|
|
14
|
+
*
|
|
15
|
+
* Credential and user repositories are resolved from the application
|
|
16
|
+
* container. Set `usage` to `true` to resolve the registered usage recorder.
|
|
17
|
+
*/
|
|
18
|
+
export declare function apiKeyStrategy(options?: ApiKeyStrategyProviderOptions): AuthStrategyProvider;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { AUTH_TOKENS } from '../../tokens.js';
|
|
2
|
+
import { ApiKeyStrategy } from './api-key-strategy.js';
|
|
3
|
+
/**
|
|
4
|
+
* Creates a DI-backed API-key authentication strategy provider.
|
|
5
|
+
*
|
|
6
|
+
* Credential and user repositories are resolved from the application
|
|
7
|
+
* container. Set `usage` to `true` to resolve the registered usage recorder.
|
|
8
|
+
*/
|
|
9
|
+
export function apiKeyStrategy(options = {}) {
|
|
10
|
+
return {
|
|
11
|
+
name: 'api-key',
|
|
12
|
+
useFactory(container) {
|
|
13
|
+
const { usage, ...strategyOptions } = options;
|
|
14
|
+
return new ApiKeyStrategy({
|
|
15
|
+
header: strategyOptions.header ?? 'x-api-key',
|
|
16
|
+
credentials: container.get(AUTH_TOKENS.ApiKeyRepository),
|
|
17
|
+
users: container.get(AUTH_TOKENS.UserRepository),
|
|
18
|
+
...(usage
|
|
19
|
+
? {
|
|
20
|
+
usage: usage === true
|
|
21
|
+
? container.get(AUTH_TOKENS.ApiKeyUsageRecorder)
|
|
22
|
+
: usage,
|
|
23
|
+
}
|
|
24
|
+
: {}),
|
|
25
|
+
...(strategyOptions.now ? { now: strategyOptions.now } : {}),
|
|
26
|
+
});
|
|
27
|
+
},
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
//# sourceMappingURL=api-key-strategy-provider.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api-key-strategy-provider.js","sourceRoot":"","sources":["../../../src/strategies/api-key/api-key-strategy-provider.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAC9C,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAYvD;;;;;GAKG;AACH,MAAM,UAAU,cAAc,CAC5B,UAAyC,EAAE;IAE3C,OAAO;QACL,IAAI,EAAE,SAAS;QACf,UAAU,CAAC,SAAoB;YAC7B,MAAM,EAAE,KAAK,EAAE,GAAG,eAAe,EAAE,GAAG,OAAO,CAAC;YAC9C,OAAO,IAAI,cAAc,CAAC;gBACxB,MAAM,EAAE,eAAe,CAAC,MAAM,IAAI,WAAW;gBAC7C,WAAW,EAAE,SAAS,CAAC,GAAG,CAAC,WAAW,CAAC,gBAAgB,CAAC;gBACxD,KAAK,EAAE,SAAS,CAAC,GAAG,CAAC,WAAW,CAAC,cAAc,CAAC;gBAChD,GAAG,CAAC,KAAK;oBACP,CAAC,CAAC;wBACE,KAAK,EAAE,KAAK,KAAK,IAAI;4BACnB,CAAC,CAAC,SAAS,CAAC,GAAG,CAAC,WAAW,CAAC,mBAAmB,CAAC;4BAChD,CAAC,CAAC,KAAK;qBACV;oBACH,CAAC,CAAC,EAAE,CAAC;gBACP,GAAG,CAAC,eAAe,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,GAAG,EAAE,eAAe,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;aAC7D,CAAC,CAAC;QACL,CAAC;KACF,CAAC;AACJ,CAAC"}
|
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
import type { HttpRequest } from '@kurdel/common';
|
|
2
2
|
import type { AuthenticationResult, AuthStrategy } from '../../domain/index.js';
|
|
3
3
|
import type { ApiKeyRepository, ApiKeyUsageRecorder, AuthUserRepository } from '../../repositories/index.js';
|
|
4
|
+
/**
|
|
5
|
+
* ## ApiKeyStrategyOptions
|
|
6
|
+
*
|
|
7
|
+
* Configures API-key authentication.
|
|
8
|
+
*/
|
|
4
9
|
export interface ApiKeyStrategyOptions {
|
|
5
10
|
/** Name of the request header containing the API key. */
|
|
6
11
|
header: string;
|
|
@@ -13,10 +18,43 @@ export interface ApiKeyStrategyOptions {
|
|
|
13
18
|
/** Injectable clock keeps expiration behavior deterministic in tests. */
|
|
14
19
|
now?: () => Date;
|
|
15
20
|
}
|
|
16
|
-
/**
|
|
21
|
+
/**
|
|
22
|
+
* ## ApiKeyStrategy
|
|
23
|
+
*
|
|
24
|
+
* Authenticates requests using opaque API keys.
|
|
25
|
+
*
|
|
26
|
+
* Responsibilities:
|
|
27
|
+
* - resolve API-key credentials
|
|
28
|
+
* - validate revocation and expiration
|
|
29
|
+
* - resolve the current authenticated user
|
|
30
|
+
* - optionally record successful credential usage
|
|
31
|
+
*
|
|
32
|
+
* Guarantees:
|
|
33
|
+
* - revoked credentials never authenticate
|
|
34
|
+
* - expired credentials never authenticate
|
|
35
|
+
* - inactive or missing users never authenticate
|
|
36
|
+
* - raw API keys are never exposed outside the strategy
|
|
37
|
+
*
|
|
38
|
+
* Non-responsibilities:
|
|
39
|
+
* - API-key persistence
|
|
40
|
+
* - user management
|
|
41
|
+
* - authorization policy evaluation
|
|
42
|
+
*/
|
|
17
43
|
export declare class ApiKeyStrategy implements AuthStrategy {
|
|
18
44
|
private readonly options;
|
|
19
45
|
constructor(options: ApiKeyStrategyOptions);
|
|
46
|
+
/**
|
|
47
|
+
* Authenticates a request using the configured API-key header.
|
|
48
|
+
*
|
|
49
|
+
* Returns `null` when the credential is missing, invalid, revoked,
|
|
50
|
+
* expired, or its associated user cannot be authenticated.
|
|
51
|
+
*/
|
|
20
52
|
authenticate(req: HttpRequest): Promise<AuthenticationResult | null>;
|
|
53
|
+
/**
|
|
54
|
+
* Returns the current time.
|
|
55
|
+
*
|
|
56
|
+
* Uses the injected clock when provided to keep authentication
|
|
57
|
+
* deterministic in tests.
|
|
58
|
+
*/
|
|
21
59
|
private now;
|
|
22
60
|
}
|
|
@@ -1,8 +1,35 @@
|
|
|
1
|
-
/**
|
|
1
|
+
/**
|
|
2
|
+
* ## ApiKeyStrategy
|
|
3
|
+
*
|
|
4
|
+
* Authenticates requests using opaque API keys.
|
|
5
|
+
*
|
|
6
|
+
* Responsibilities:
|
|
7
|
+
* - resolve API-key credentials
|
|
8
|
+
* - validate revocation and expiration
|
|
9
|
+
* - resolve the current authenticated user
|
|
10
|
+
* - optionally record successful credential usage
|
|
11
|
+
*
|
|
12
|
+
* Guarantees:
|
|
13
|
+
* - revoked credentials never authenticate
|
|
14
|
+
* - expired credentials never authenticate
|
|
15
|
+
* - inactive or missing users never authenticate
|
|
16
|
+
* - raw API keys are never exposed outside the strategy
|
|
17
|
+
*
|
|
18
|
+
* Non-responsibilities:
|
|
19
|
+
* - API-key persistence
|
|
20
|
+
* - user management
|
|
21
|
+
* - authorization policy evaluation
|
|
22
|
+
*/
|
|
2
23
|
export class ApiKeyStrategy {
|
|
3
24
|
constructor(options) {
|
|
4
25
|
this.options = options;
|
|
5
26
|
}
|
|
27
|
+
/**
|
|
28
|
+
* Authenticates a request using the configured API-key header.
|
|
29
|
+
*
|
|
30
|
+
* Returns `null` when the credential is missing, invalid, revoked,
|
|
31
|
+
* expired, or its associated user cannot be authenticated.
|
|
32
|
+
*/
|
|
6
33
|
async authenticate(req) {
|
|
7
34
|
const raw = req.headers?.[this.options.header.toLowerCase()];
|
|
8
35
|
const key = Array.isArray(raw) ? raw[0] : raw;
|
|
@@ -29,6 +56,12 @@ export class ApiKeyStrategy {
|
|
|
29
56
|
},
|
|
30
57
|
};
|
|
31
58
|
}
|
|
59
|
+
/**
|
|
60
|
+
* Returns the current time.
|
|
61
|
+
*
|
|
62
|
+
* Uses the injected clock when provided to keep authentication
|
|
63
|
+
* deterministic in tests.
|
|
64
|
+
*/
|
|
32
65
|
now() {
|
|
33
66
|
return this.options.now?.() ?? new Date();
|
|
34
67
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"api-key-strategy.js","sourceRoot":"","sources":["../../../src/strategies/api-key/api-key-strategy.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"api-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AE,eAAe,CAAC,CAAC;QACxE,CAAC;QAED,OAAO;YACL,IAAI;YACJ,UAAU,EAAE;gBACV,IAAI,EAAE,SAAS;gBACf,GAAG,CAAC,UAAU,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,EAAE,EAAE,UAAU,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;aAChD;SACF,CAAC;IACJ,CAAC;IAED;;;;;OAKG;IACK,GAAG;QACT,OAAO,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,IAAI,IAAI,IAAI,EAAE,CAAC;IAC5C,CAAC;CACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/strategies/api-key/index.ts"],"names":[],"mappings":"AAAA,cAAc,uBAAuB,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/strategies/api-key/index.ts"],"names":[],"mappings":"AAAA,cAAc,uBAAuB,CAAC;AACtC,cAAc,gCAAgC,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/strategies/jwt/index.ts"],"names":[],"mappings":"AAAA,cAAc,kBAAkB,CAAC;AACjC,cAAc,mBAAmB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/strategies/jwt/index.ts"],"names":[],"mappings":"AAAA,cAAc,kBAAkB,CAAC;AACjC,cAAc,mBAAmB,CAAC;AAClC,cAAc,4BAA4B,CAAC"}
|
|
@@ -1,48 +1,99 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* ## JwtPayload
|
|
3
|
-
*
|
|
3
|
+
*
|
|
4
|
+
* Standard JWT claims together with application-defined claims.
|
|
5
|
+
*
|
|
6
|
+
* The payload is intentionally extensible to support application-specific
|
|
7
|
+
* authentication metadata.
|
|
4
8
|
*/
|
|
5
9
|
export interface JwtPayload {
|
|
10
|
+
/** Subject (`sub`) identifying the authenticated principal. */
|
|
6
11
|
sub: string | number;
|
|
12
|
+
/** Roles embedded into the signed token. */
|
|
7
13
|
roles: string[];
|
|
14
|
+
/** Issued-at time (`iat`), expressed as Unix time in seconds. */
|
|
8
15
|
iat?: number;
|
|
16
|
+
/** Expiration time (`exp`), expressed as Unix time in seconds. */
|
|
9
17
|
exp?: number;
|
|
18
|
+
/** Not-before time (`nbf`), expressed as Unix time in seconds. */
|
|
10
19
|
nbf?: number;
|
|
20
|
+
/** Expected token issuer (`iss`). */
|
|
11
21
|
iss?: string;
|
|
22
|
+
/** Intended token audience (`aud`). */
|
|
12
23
|
aud?: string;
|
|
24
|
+
/** Additional application-defined claims. */
|
|
13
25
|
[key: string]: unknown;
|
|
14
26
|
}
|
|
15
27
|
/**
|
|
16
28
|
* ## JwtServiceOptions
|
|
17
|
-
*
|
|
29
|
+
*
|
|
30
|
+
* Configures JWT signing and verification.
|
|
18
31
|
*/
|
|
19
32
|
export interface JwtServiceOptions {
|
|
33
|
+
/** Secret used for HS256 signing. */
|
|
20
34
|
secret: string;
|
|
35
|
+
/** Expected issuer claim. */
|
|
21
36
|
issuer?: string;
|
|
37
|
+
/** Expected audience claim. */
|
|
22
38
|
audience?: string;
|
|
39
|
+
/**
|
|
40
|
+
* Default token lifetime in seconds.
|
|
41
|
+
*
|
|
42
|
+
* When omitted, generated tokens do not receive an `exp` claim.
|
|
43
|
+
*/
|
|
23
44
|
expiresIn?: number;
|
|
24
45
|
}
|
|
25
46
|
/**
|
|
26
47
|
* ## JwtService
|
|
27
48
|
*
|
|
28
|
-
*
|
|
29
|
-
*
|
|
49
|
+
* Signs and verifies JSON Web Tokens using the HS256 algorithm.
|
|
50
|
+
*
|
|
51
|
+
* Responsibilities:
|
|
52
|
+
* - create signed JWT tokens
|
|
53
|
+
* - verify token integrity and registered claims
|
|
54
|
+
* - decode JWT payloads without verification when explicitly requested
|
|
55
|
+
*
|
|
56
|
+
* Guarantees:
|
|
57
|
+
* - every generated token is signed with the configured secret
|
|
58
|
+
* - verification validates the signature before returning claims
|
|
59
|
+
* - configured issuer, audience, and lifetime constraints are enforced
|
|
60
|
+
*
|
|
61
|
+
* Non-responsibilities:
|
|
62
|
+
* - user authentication
|
|
63
|
+
* - authorization
|
|
64
|
+
* - session persistence
|
|
65
|
+
* - key rotation
|
|
30
66
|
*/
|
|
31
67
|
export declare class JwtService {
|
|
32
68
|
private readonly opts;
|
|
33
69
|
constructor(opts: JwtServiceOptions);
|
|
34
70
|
/**
|
|
35
|
-
*
|
|
71
|
+
* Creates and signs a JWT.
|
|
72
|
+
*
|
|
73
|
+
* Standard claims (`iat`, `exp`, `iss`, `aud`) are populated
|
|
74
|
+
* automatically from the configured options.
|
|
36
75
|
*/
|
|
37
76
|
sign(payload: Omit<JwtPayload, 'iat' | 'exp'>): string;
|
|
38
77
|
/**
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
78
|
+
* Decodes a JWT payload without verifying its signature.
|
|
79
|
+
*
|
|
80
|
+
* The returned payload must be treated as untrusted until
|
|
81
|
+
* {@link verify} succeeds.
|
|
82
|
+
*/
|
|
42
83
|
decode(token: string): JwtPayload | null;
|
|
43
84
|
/**
|
|
44
|
-
* Verifies
|
|
45
|
-
*
|
|
85
|
+
* Verifies a JWT and returns its decoded payload.
|
|
86
|
+
*
|
|
87
|
+
* Validation includes:
|
|
88
|
+
* - signature
|
|
89
|
+
* - expiration (`exp`)
|
|
90
|
+
* - not-before (`nbf`)
|
|
91
|
+
* - issuer (`iss`) when configured
|
|
92
|
+
* - audience (`aud`) when configured
|
|
93
|
+
*
|
|
94
|
+
* @throws Error
|
|
95
|
+
* If the token is malformed, has an invalid signature,
|
|
96
|
+
* or violates any configured validation constraint.
|
|
46
97
|
*/
|
|
47
98
|
verify(token: string): JwtPayload;
|
|
48
99
|
private b64;
|