axiam-sdk 1.0.0-alpha2 → 1.0.0-alpha9
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 +33 -3
- package/dist/{authzCore-CV-Td-V1.d.cts → authzCore-B7GSd3-t.d.cts} +18 -1
- package/dist/{authzCore-xwmCivHH.d.ts → authzCore-CcTdIf78.d.ts} +18 -1
- package/dist/{client-CAeQw1a-.d.cts → client-BxskJdoj.d.cts} +16 -0
- package/dist/{client-BPg9kfKV.d.ts → client-DYRT_ZCn.d.ts} +16 -0
- package/dist/grpc/index.d.cts +6 -2
- package/dist/grpc/index.d.ts +6 -2
- package/dist/grpc/index.js +57 -10
- package/dist/grpc/index.js.map +1 -1
- package/dist/grpc/index.mjs +57 -10
- package/dist/grpc/index.mjs.map +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +61 -7
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +61 -7
- package/dist/index.mjs.map +1 -1
- package/dist/{jwks-CX-nhD6A.d.cts → jwks-B8dPy2c6.d.cts} +7 -0
- package/dist/{jwks-CX-nhD6A.d.ts → jwks-B8dPy2c6.d.ts} +7 -0
- package/dist/middleware/index.d.cts +17 -7
- package/dist/middleware/index.d.ts +17 -7
- package/dist/middleware/index.js.map +1 -1
- package/dist/middleware/index.mjs.map +1 -1
- package/dist/nestjs/index.d.cts +2 -2
- package/dist/nestjs/index.d.ts +2 -2
- package/dist/nestjs/index.js.map +1 -1
- package/dist/nestjs/index.mjs.map +1 -1
- package/dist/node/index.d.cts +7 -3
- package/dist/node/index.d.ts +7 -3
- package/dist/node/index.js +40 -7
- package/dist/node/index.js.map +1 -1
- package/dist/node/index.mjs +40 -7
- package/dist/node/index.mjs.map +1 -1
- package/dist/rest/index.d.cts +1 -1
- package/dist/rest/index.d.ts +1 -1
- package/dist/rest/index.js +61 -7
- package/dist/rest/index.js.map +1 -1
- package/dist/rest/index.mjs +61 -7
- package/dist/rest/index.mjs.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -17,7 +17,7 @@ Official TypeScript/JavaScript client SDK for [AXIAM](https://github.com/ilpanic
|
|
|
17
17
|
|
|
18
18
|
## Contract conformance
|
|
19
19
|
|
|
20
|
-
This SDK conforms to CONTRACT.md §1–§11.
|
|
20
|
+
This SDK conforms to CONTRACT.md §1–§11 (including §6.1 mTLS client certificates).
|
|
21
21
|
|
|
22
22
|
See [`CONTRACT.md`](./CONTRACT.md) for the full cross-language behavioral contract.
|
|
23
23
|
|
|
@@ -63,6 +63,34 @@ const client = new AxiamClient({
|
|
|
63
63
|
});
|
|
64
64
|
```
|
|
65
65
|
|
|
66
|
+
### mTLS / client certificates (Node only)
|
|
67
|
+
|
|
68
|
+
For IoT devices and service accounts authenticated by **mutual TLS** (CONTRACT.md §6.1),
|
|
69
|
+
pass a PEM client-certificate chain and its PEM private key. The identity is presented on
|
|
70
|
+
**both** the REST and gRPC transports of the same client. Presenting a client certificate
|
|
71
|
+
**never** relaxes server verification — strict TLS stays on.
|
|
72
|
+
|
|
73
|
+
```typescript
|
|
74
|
+
import { readFileSync } from 'node:fs';
|
|
75
|
+
import { AxiamClient } from 'axiam-sdk';
|
|
76
|
+
|
|
77
|
+
const client = new AxiamClient({
|
|
78
|
+
baseUrl: 'https://iam.example.com',
|
|
79
|
+
tenantSlug: 'acme',
|
|
80
|
+
clientCert: readFileSync('device.crt', 'utf8'), // PEM certificate chain
|
|
81
|
+
clientKey: readFileSync('device.key', 'utf8'), // PEM private key (PKCS#8 or PKCS#1)
|
|
82
|
+
// customCa: readFileSync('ca.crt', 'utf8'), // optional server-trust CA (§6)
|
|
83
|
+
});
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
- `clientCert` and `clientKey` are **all-or-nothing** — providing exactly one throws at
|
|
87
|
+
construction, and each is validated to be PEM-shaped (as `customCa` is).
|
|
88
|
+
- The private key is secret material: it is passed straight to the Node TLS stack and is
|
|
89
|
+
never retained on a public property, logged, or serialized (CONTRACT.md §7).
|
|
90
|
+
- **Node only.** Browsers cannot present a client certificate from JavaScript, so the
|
|
91
|
+
browser build validates the PEM shape then ignores `clientCert`/`clientKey` — exactly as
|
|
92
|
+
it already ignores `customCa`.
|
|
93
|
+
|
|
66
94
|
## Usage per persona
|
|
67
95
|
|
|
68
96
|
### Browser — login + authz (`axiam-sdk` / `axiam-sdk/rest`)
|
|
@@ -311,8 +339,10 @@ try {
|
|
|
311
339
|
- Token-carrying values are wrapped in `Sensitive<T>` — `toString()`/`toJSON()`/
|
|
312
340
|
`util.inspect` all redact to `[SENSITIVE]`; the raw value is only reachable via an
|
|
313
341
|
explicit accessor (CONTRACT.md §7).
|
|
314
|
-
- Strict TLS verification is always on; the only escape hatch is the
|
|
315
|
-
`customCa` option for self-signed development environments (CONTRACT.md §6).
|
|
342
|
+
- Strict TLS verification is always on; the only server-trust escape hatch is the
|
|
343
|
+
constructor's `customCa` option for self-signed development environments (CONTRACT.md §6).
|
|
344
|
+
- Optional mutual TLS (mTLS): a PEM `clientCert`/`clientKey` client identity (Node only) is
|
|
345
|
+
presented on both REST and gRPC without ever relaxing server verification (CONTRACT.md §6.1).
|
|
316
346
|
- AMQP messages are HMAC-SHA256 verified before your handler ever sees them; verification
|
|
317
347
|
failures are nacked without requeue (CONTRACT.md §8).
|
|
318
348
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { A as AccessCheck, a as AccessDecision } from './types-BVkMoqLU.cjs';
|
|
2
|
-
import { V as Verifier } from './jwks-
|
|
2
|
+
import { V as Verifier } from './jwks-B8dPy2c6.cjs';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* Minimal session shape the middleware needs: a JWKS verifier (D-11) and the
|
|
@@ -9,13 +9,18 @@ import { V as Verifier } from './jwks-CX-nhD6A.cjs';
|
|
|
9
9
|
* DIFFERENT tenant in the same org.
|
|
10
10
|
*/
|
|
11
11
|
interface VerifiableSession {
|
|
12
|
+
/** Local JWKS verifier (D-11) — validates the token's EdDSA signature against the org-wide cached JWKS, offline on a cache hit. */
|
|
12
13
|
jwksVerifier: Verifier;
|
|
14
|
+
/** The tenant this resource server is configured for (CR-03); a validly-signed token minted for a different tenant in the same org is rejected. */
|
|
13
15
|
tenantHeaderValue: string;
|
|
14
16
|
}
|
|
15
17
|
/** Authenticated identity injected as req.axiamUser / request.axiamUser (§10). */
|
|
16
18
|
interface AxiamIdentity {
|
|
19
|
+
/** The authenticated end user's id (the token's `sub` claim). */
|
|
17
20
|
userId: string;
|
|
21
|
+
/** The tenant the verified token was minted for (the token's `tenant_id` claim). */
|
|
18
22
|
tenantId: string;
|
|
23
|
+
/** Roles derived from the token's space-separated `scope` claim (§10). */
|
|
19
24
|
roles: string[];
|
|
20
25
|
}
|
|
21
26
|
/**
|
|
@@ -37,6 +42,7 @@ declare function authenticateRequest(session: VerifiableSession, token: string):
|
|
|
37
42
|
* itself, so this module pulls in no axios/grpc dependency.
|
|
38
43
|
*/
|
|
39
44
|
interface AuthzChecker {
|
|
45
|
+
/** Issue a single access check for the authenticated end user (`subjectId`, §11.2.2). Satisfied structurally by `AxiamClient.checkAccess`. */
|
|
40
46
|
checkAccess(check: AccessCheck): Promise<AccessDecision>;
|
|
41
47
|
}
|
|
42
48
|
/**
|
|
@@ -48,11 +54,14 @@ interface AuthzChecker {
|
|
|
48
54
|
* not per-request, when it is absent.
|
|
49
55
|
*/
|
|
50
56
|
interface AuthzVerifiableSession extends VerifiableSession {
|
|
57
|
+
/** Authz transport required by `requireAccess`/`requireAccessHook` (validated by {@link assertAuthzClient}); unused by `requireAuth`/`requireRole`. */
|
|
51
58
|
authzClient?: AuthzChecker;
|
|
52
59
|
}
|
|
53
60
|
/** Marker produced by {@link fromParam} — resolve the resource id from a named path/route parameter. */
|
|
54
61
|
interface ResourceParamRef {
|
|
62
|
+
/** Discriminant marking the path/route-parameter resolution strategy (§11.2.3.b). */
|
|
55
63
|
readonly kind: 'param';
|
|
64
|
+
/** The path/route parameter name the resource id is read from. */
|
|
56
65
|
readonly name: string;
|
|
57
66
|
}
|
|
58
67
|
/**
|
|
@@ -92,6 +101,7 @@ interface RequireAccessOptions {
|
|
|
92
101
|
}
|
|
93
102
|
/** Minimal logger seam for the §11.2.8 debug-only denial/error log (mirrors `amqp/consumer.ts`'s `ConsumeLogger`). */
|
|
94
103
|
interface AuthzLogger {
|
|
104
|
+
/** Emit a debug-only denial/error record (§11.2.8) — receives `action`/`resourceId` context, never the token. */
|
|
95
105
|
debug(event: string, message: string, context?: Record<string, unknown>): void;
|
|
96
106
|
}
|
|
97
107
|
/**
|
|
@@ -103,17 +113,24 @@ interface AuthzLogger {
|
|
|
103
113
|
declare function assertAuthzClient(session: AuthzVerifiableSession): AuthzChecker;
|
|
104
114
|
/** Standardized JSON error body shape (§10/§11 — `{ error, message }`). */
|
|
105
115
|
interface ErrorBody {
|
|
116
|
+
/** Stable machine-readable error code (e.g. `authentication_failed`, `authorization_denied`). */
|
|
106
117
|
error: string;
|
|
118
|
+
/** Human-readable explanation; never contains token material. */
|
|
107
119
|
message: string;
|
|
108
120
|
}
|
|
109
121
|
/** The outcome of an `evaluateAccess` call — one arm per §11.2.5's error-mapping table (the 401/400 arms are handled by callers before this is ever invoked). */
|
|
110
122
|
type CheckOutcome = {
|
|
123
|
+
/** The check passed — the caller proceeds to the handler. */
|
|
111
124
|
kind: 'allowed';
|
|
112
125
|
} | {
|
|
126
|
+
/** The check was evaluated and denied (`allowed: false` or a server 403) → HTTP 403. */
|
|
113
127
|
kind: 'denied';
|
|
128
|
+
/** Denial message surfaced in the 403 body. */
|
|
114
129
|
message: string;
|
|
115
130
|
} | {
|
|
131
|
+
/** The authz transport failed — fail-closed → HTTP 503, never an allow. */
|
|
116
132
|
kind: 'unavailable';
|
|
133
|
+
/** Failure message surfaced in the 503 body. */
|
|
117
134
|
message: string;
|
|
118
135
|
};
|
|
119
136
|
/**
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { A as AccessCheck, a as AccessDecision } from './types-BVkMoqLU.js';
|
|
2
|
-
import { V as Verifier } from './jwks-
|
|
2
|
+
import { V as Verifier } from './jwks-B8dPy2c6.js';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* Minimal session shape the middleware needs: a JWKS verifier (D-11) and the
|
|
@@ -9,13 +9,18 @@ import { V as Verifier } from './jwks-CX-nhD6A.js';
|
|
|
9
9
|
* DIFFERENT tenant in the same org.
|
|
10
10
|
*/
|
|
11
11
|
interface VerifiableSession {
|
|
12
|
+
/** Local JWKS verifier (D-11) — validates the token's EdDSA signature against the org-wide cached JWKS, offline on a cache hit. */
|
|
12
13
|
jwksVerifier: Verifier;
|
|
14
|
+
/** The tenant this resource server is configured for (CR-03); a validly-signed token minted for a different tenant in the same org is rejected. */
|
|
13
15
|
tenantHeaderValue: string;
|
|
14
16
|
}
|
|
15
17
|
/** Authenticated identity injected as req.axiamUser / request.axiamUser (§10). */
|
|
16
18
|
interface AxiamIdentity {
|
|
19
|
+
/** The authenticated end user's id (the token's `sub` claim). */
|
|
17
20
|
userId: string;
|
|
21
|
+
/** The tenant the verified token was minted for (the token's `tenant_id` claim). */
|
|
18
22
|
tenantId: string;
|
|
23
|
+
/** Roles derived from the token's space-separated `scope` claim (§10). */
|
|
19
24
|
roles: string[];
|
|
20
25
|
}
|
|
21
26
|
/**
|
|
@@ -37,6 +42,7 @@ declare function authenticateRequest(session: VerifiableSession, token: string):
|
|
|
37
42
|
* itself, so this module pulls in no axios/grpc dependency.
|
|
38
43
|
*/
|
|
39
44
|
interface AuthzChecker {
|
|
45
|
+
/** Issue a single access check for the authenticated end user (`subjectId`, §11.2.2). Satisfied structurally by `AxiamClient.checkAccess`. */
|
|
40
46
|
checkAccess(check: AccessCheck): Promise<AccessDecision>;
|
|
41
47
|
}
|
|
42
48
|
/**
|
|
@@ -48,11 +54,14 @@ interface AuthzChecker {
|
|
|
48
54
|
* not per-request, when it is absent.
|
|
49
55
|
*/
|
|
50
56
|
interface AuthzVerifiableSession extends VerifiableSession {
|
|
57
|
+
/** Authz transport required by `requireAccess`/`requireAccessHook` (validated by {@link assertAuthzClient}); unused by `requireAuth`/`requireRole`. */
|
|
51
58
|
authzClient?: AuthzChecker;
|
|
52
59
|
}
|
|
53
60
|
/** Marker produced by {@link fromParam} — resolve the resource id from a named path/route parameter. */
|
|
54
61
|
interface ResourceParamRef {
|
|
62
|
+
/** Discriminant marking the path/route-parameter resolution strategy (§11.2.3.b). */
|
|
55
63
|
readonly kind: 'param';
|
|
64
|
+
/** The path/route parameter name the resource id is read from. */
|
|
56
65
|
readonly name: string;
|
|
57
66
|
}
|
|
58
67
|
/**
|
|
@@ -92,6 +101,7 @@ interface RequireAccessOptions {
|
|
|
92
101
|
}
|
|
93
102
|
/** Minimal logger seam for the §11.2.8 debug-only denial/error log (mirrors `amqp/consumer.ts`'s `ConsumeLogger`). */
|
|
94
103
|
interface AuthzLogger {
|
|
104
|
+
/** Emit a debug-only denial/error record (§11.2.8) — receives `action`/`resourceId` context, never the token. */
|
|
95
105
|
debug(event: string, message: string, context?: Record<string, unknown>): void;
|
|
96
106
|
}
|
|
97
107
|
/**
|
|
@@ -103,17 +113,24 @@ interface AuthzLogger {
|
|
|
103
113
|
declare function assertAuthzClient(session: AuthzVerifiableSession): AuthzChecker;
|
|
104
114
|
/** Standardized JSON error body shape (§10/§11 — `{ error, message }`). */
|
|
105
115
|
interface ErrorBody {
|
|
116
|
+
/** Stable machine-readable error code (e.g. `authentication_failed`, `authorization_denied`). */
|
|
106
117
|
error: string;
|
|
118
|
+
/** Human-readable explanation; never contains token material. */
|
|
107
119
|
message: string;
|
|
108
120
|
}
|
|
109
121
|
/** The outcome of an `evaluateAccess` call — one arm per §11.2.5's error-mapping table (the 401/400 arms are handled by callers before this is ever invoked). */
|
|
110
122
|
type CheckOutcome = {
|
|
123
|
+
/** The check passed — the caller proceeds to the handler. */
|
|
111
124
|
kind: 'allowed';
|
|
112
125
|
} | {
|
|
126
|
+
/** The check was evaluated and denied (`allowed: false` or a server 403) → HTTP 403. */
|
|
113
127
|
kind: 'denied';
|
|
128
|
+
/** Denial message surfaced in the 403 body. */
|
|
114
129
|
message: string;
|
|
115
130
|
} | {
|
|
131
|
+
/** The authz transport failed — fail-closed → HTTP 503, never an allow. */
|
|
116
132
|
kind: 'unavailable';
|
|
133
|
+
/** Failure message surfaced in the 503 body. */
|
|
117
134
|
message: string;
|
|
118
135
|
};
|
|
119
136
|
/**
|
|
@@ -23,6 +23,22 @@ interface AxiamClientOptions {
|
|
|
23
23
|
tenantId?: string;
|
|
24
24
|
/** PEM-encoded custom CA certificate, for self-signed/dev environments (§6). */
|
|
25
25
|
customCa?: string;
|
|
26
|
+
/**
|
|
27
|
+
* PEM-encoded client-certificate chain for mutual TLS (§6.1). Presented to
|
|
28
|
+
* the server to authenticate an IoT device / service account. MUST be
|
|
29
|
+
* provided together with {@link AxiamClientOptions.clientKey}. Node only —
|
|
30
|
+
* ignored in the browser (browsers cannot present a client certificate from
|
|
31
|
+
* JS). Presenting a client certificate NEVER relaxes server verification.
|
|
32
|
+
*/
|
|
33
|
+
clientCert?: string;
|
|
34
|
+
/**
|
|
35
|
+
* PEM-encoded private key (PKCS#8 or PKCS#1) matching {@link
|
|
36
|
+
* AxiamClientOptions.clientCert} (§6.1). Secret material: it is passed
|
|
37
|
+
* straight to the Node TLS stack and is never retained on a public property,
|
|
38
|
+
* logged, or serialized (§7). MUST be provided together with `clientCert`.
|
|
39
|
+
* Node only — ignored in the browser.
|
|
40
|
+
*/
|
|
41
|
+
clientKey?: string;
|
|
26
42
|
/** Connection timeout in milliseconds. Defaults to DEFAULT_CONNECT_TIMEOUT_MS. */
|
|
27
43
|
connectTimeoutMs?: number;
|
|
28
44
|
/** Request timeout in milliseconds. Defaults to DEFAULT_REQUEST_TIMEOUT_MS. */
|
|
@@ -23,6 +23,22 @@ interface AxiamClientOptions {
|
|
|
23
23
|
tenantId?: string;
|
|
24
24
|
/** PEM-encoded custom CA certificate, for self-signed/dev environments (§6). */
|
|
25
25
|
customCa?: string;
|
|
26
|
+
/**
|
|
27
|
+
* PEM-encoded client-certificate chain for mutual TLS (§6.1). Presented to
|
|
28
|
+
* the server to authenticate an IoT device / service account. MUST be
|
|
29
|
+
* provided together with {@link AxiamClientOptions.clientKey}. Node only —
|
|
30
|
+
* ignored in the browser (browsers cannot present a client certificate from
|
|
31
|
+
* JS). Presenting a client certificate NEVER relaxes server verification.
|
|
32
|
+
*/
|
|
33
|
+
clientCert?: string;
|
|
34
|
+
/**
|
|
35
|
+
* PEM-encoded private key (PKCS#8 or PKCS#1) matching {@link
|
|
36
|
+
* AxiamClientOptions.clientCert} (§6.1). Secret material: it is passed
|
|
37
|
+
* straight to the Node TLS stack and is never retained on a public property,
|
|
38
|
+
* logged, or serialized (§7). MUST be provided together with `clientCert`.
|
|
39
|
+
* Node only — ignored in the browser.
|
|
40
|
+
*/
|
|
41
|
+
clientKey?: string;
|
|
26
42
|
/** Connection timeout in milliseconds. Defaults to DEFAULT_CONNECT_TIMEOUT_MS. */
|
|
27
43
|
connectTimeoutMs?: number;
|
|
28
44
|
/** Request timeout in milliseconds. Defaults to DEFAULT_REQUEST_TIMEOUT_MS. */
|
package/dist/grpc/index.d.cts
CHANGED
|
@@ -3,9 +3,9 @@ import { Interceptor } from '@grpc/grpc-js';
|
|
|
3
3
|
import { NodeSession } from '../node/index.cjs';
|
|
4
4
|
export { ACCESS_COOKIE, CSRF_COOKIE, REFRESH_COOKIE, TokenManager, createJar, createNodeClient, createNodeSession, extractCookieValue, wrapAxios } from '../node/index.cjs';
|
|
5
5
|
import { a as AccessDecision } from '../types-BVkMoqLU.cjs';
|
|
6
|
-
export { A as AxiamClaims, J as JWKS_PATH, V as Verifier, c as createVerifier } from '../jwks-
|
|
6
|
+
export { A as AxiamClaims, J as JWKS_PATH, V as Verifier, c as createVerifier } from '../jwks-B8dPy2c6.cjs';
|
|
7
7
|
import 'tough-cookie';
|
|
8
|
-
import '../client-
|
|
8
|
+
import '../client-BxskJdoj.cjs';
|
|
9
9
|
import 'axios';
|
|
10
10
|
import '../sensitive-CWBH_tHr.cjs';
|
|
11
11
|
|
|
@@ -95,6 +95,10 @@ declare class AuthzGrpcClient {
|
|
|
95
95
|
baseUrl: string;
|
|
96
96
|
customCa?: string;
|
|
97
97
|
allowInsecure?: boolean;
|
|
98
|
+
/** PEM client-certificate chain for mutual TLS (§6.1); pair with `clientKey`. */
|
|
99
|
+
clientCert?: string;
|
|
100
|
+
/** PEM private key for mutual TLS (§6.1); pair with `clientCert`. Secret (§7). */
|
|
101
|
+
clientKey?: string;
|
|
98
102
|
}, clientFactory?: AuthorizationServiceClientFactory);
|
|
99
103
|
/** `CheckAccess` over gRPC (SC#2 Node half). UNAUTHENTICATED triggers exactly one shared-guard refresh + one retry (§9.3). */
|
|
100
104
|
checkAccess(request: CheckAccessRequest): Promise<AccessDecision>;
|
package/dist/grpc/index.d.ts
CHANGED
|
@@ -3,9 +3,9 @@ import { Interceptor } from '@grpc/grpc-js';
|
|
|
3
3
|
import { NodeSession } from '../node/index.js';
|
|
4
4
|
export { ACCESS_COOKIE, CSRF_COOKIE, REFRESH_COOKIE, TokenManager, createJar, createNodeClient, createNodeSession, extractCookieValue, wrapAxios } from '../node/index.js';
|
|
5
5
|
import { a as AccessDecision } from '../types-BVkMoqLU.js';
|
|
6
|
-
export { A as AxiamClaims, J as JWKS_PATH, V as Verifier, c as createVerifier } from '../jwks-
|
|
6
|
+
export { A as AxiamClaims, J as JWKS_PATH, V as Verifier, c as createVerifier } from '../jwks-B8dPy2c6.js';
|
|
7
7
|
import 'tough-cookie';
|
|
8
|
-
import '../client-
|
|
8
|
+
import '../client-DYRT_ZCn.js';
|
|
9
9
|
import 'axios';
|
|
10
10
|
import '../sensitive-CWBH_tHr.js';
|
|
11
11
|
|
|
@@ -95,6 +95,10 @@ declare class AuthzGrpcClient {
|
|
|
95
95
|
baseUrl: string;
|
|
96
96
|
customCa?: string;
|
|
97
97
|
allowInsecure?: boolean;
|
|
98
|
+
/** PEM client-certificate chain for mutual TLS (§6.1); pair with `clientKey`. */
|
|
99
|
+
clientCert?: string;
|
|
100
|
+
/** PEM private key for mutual TLS (§6.1); pair with `clientCert`. Secret (§7). */
|
|
101
|
+
clientKey?: string;
|
|
98
102
|
}, clientFactory?: AuthorizationServiceClientFactory);
|
|
99
103
|
/** `CheckAccess` over gRPC (SC#2 Node half). UNAUTHENTICATED triggers exactly one shared-guard refresh + one retry (§9.3). */
|
|
100
104
|
checkAccess(request: CheckAccessRequest): Promise<AccessDecision>;
|
package/dist/grpc/index.js
CHANGED
|
@@ -215,6 +215,31 @@ createRefreshGuard();
|
|
|
215
215
|
|
|
216
216
|
// src/core/config.ts
|
|
217
217
|
var DEFAULT_REQUEST_TIMEOUT_MS = 3e4;
|
|
218
|
+
var CERT_PEM_MARKER = "-----BEGIN CERTIFICATE-----";
|
|
219
|
+
var PRIVATE_KEY_PEM_RE = /-----BEGIN (?:[A-Z0-9]+ )*PRIVATE KEY-----/;
|
|
220
|
+
function resolveClientIdentity(options) {
|
|
221
|
+
const hasCert = options.clientCert !== void 0;
|
|
222
|
+
const hasKey = options.clientKey !== void 0;
|
|
223
|
+
if (hasCert !== hasKey) {
|
|
224
|
+
throw new Error(
|
|
225
|
+
"clientCert and clientKey must be provided together for mutual TLS (one was given without the other) (CONTRACT.md \xA76.1)."
|
|
226
|
+
);
|
|
227
|
+
}
|
|
228
|
+
if (!hasCert || !hasKey) {
|
|
229
|
+
return void 0;
|
|
230
|
+
}
|
|
231
|
+
if (!options.clientCert.includes(CERT_PEM_MARKER)) {
|
|
232
|
+
throw new Error(
|
|
233
|
+
'clientCert must be a PEM-encoded certificate chain (expected to contain "-----BEGIN CERTIFICATE-----") (CONTRACT.md \xA76.1).'
|
|
234
|
+
);
|
|
235
|
+
}
|
|
236
|
+
if (!PRIVATE_KEY_PEM_RE.test(options.clientKey)) {
|
|
237
|
+
throw new Error(
|
|
238
|
+
'clientKey must be a PEM-encoded private key (expected to contain "-----BEGIN PRIVATE KEY-----" or "-----BEGIN RSA PRIVATE KEY-----") (CONTRACT.md \xA76.1).'
|
|
239
|
+
);
|
|
240
|
+
}
|
|
241
|
+
return { cert: options.clientCert, key: new Sensitive(options.clientKey) };
|
|
242
|
+
}
|
|
218
243
|
|
|
219
244
|
// src/grpc/callWithRefresh.ts
|
|
220
245
|
function isGrpcServiceError(err) {
|
|
@@ -268,7 +293,7 @@ function promisifyUnary(call, request) {
|
|
|
268
293
|
});
|
|
269
294
|
});
|
|
270
295
|
}
|
|
271
|
-
function buildCredentials(baseUrl, customCa, allowInsecure) {
|
|
296
|
+
function buildCredentials(baseUrl, customCa, allowInsecure, identity) {
|
|
272
297
|
const isSecure = baseUrl.startsWith("https://") || baseUrl.startsWith("grpcs://");
|
|
273
298
|
if (!isSecure) {
|
|
274
299
|
if (!allowInsecure) {
|
|
@@ -281,8 +306,16 @@ function buildCredentials(baseUrl, customCa, allowInsecure) {
|
|
|
281
306
|
);
|
|
282
307
|
return grpc2__namespace.ChannelCredentials.createInsecure();
|
|
283
308
|
}
|
|
309
|
+
const rootCerts = customCa ? Buffer.from(customCa, "utf8") : null;
|
|
310
|
+
if (identity) {
|
|
311
|
+
return grpc2__namespace.ChannelCredentials.createSsl(
|
|
312
|
+
rootCerts,
|
|
313
|
+
Buffer.from(identity.key.expose(), "utf8"),
|
|
314
|
+
Buffer.from(identity.cert, "utf8")
|
|
315
|
+
);
|
|
316
|
+
}
|
|
284
317
|
if (customCa) {
|
|
285
|
-
return grpc2__namespace.ChannelCredentials.createSsl(
|
|
318
|
+
return grpc2__namespace.ChannelCredentials.createSsl(rootCerts);
|
|
286
319
|
}
|
|
287
320
|
return grpc2__namespace.ChannelCredentials.createSsl();
|
|
288
321
|
}
|
|
@@ -331,7 +364,13 @@ var AuthzGrpcClient = class {
|
|
|
331
364
|
#inner;
|
|
332
365
|
constructor(session, options, clientFactory = buildAuthorizationServiceClient) {
|
|
333
366
|
this.#session = session;
|
|
334
|
-
const
|
|
367
|
+
const identity = resolveClientIdentity(options);
|
|
368
|
+
const credentials = buildCredentials(
|
|
369
|
+
options.baseUrl,
|
|
370
|
+
options.customCa,
|
|
371
|
+
options.allowInsecure ?? false,
|
|
372
|
+
identity
|
|
373
|
+
);
|
|
335
374
|
this.#inner = clientFactory(options.baseUrl, credentials, [authInterceptor(session)]);
|
|
336
375
|
}
|
|
337
376
|
/** `CheckAccess` over gRPC (SC#2 Node half). UNAUTHENTICATED triggers exactly one shared-guard refresh + one retry (§9.3). */
|
|
@@ -357,7 +396,7 @@ var AuthzGrpcClient = class {
|
|
|
357
396
|
this.#inner.close();
|
|
358
397
|
}
|
|
359
398
|
};
|
|
360
|
-
var PEM_MARKER =
|
|
399
|
+
var PEM_MARKER = CERT_PEM_MARKER;
|
|
361
400
|
var SharedSession = class {
|
|
362
401
|
/** The underlying axios instance this session's requests are issued through, pre-configured with `baseUrl`, credential forwarding, and (Node) an optional custom-CA `httpsAgent`. */
|
|
363
402
|
axios;
|
|
@@ -419,11 +458,12 @@ function resolveTenantHeaderValue(options) {
|
|
|
419
458
|
"AxiamClient construction requires a tenant: provide either tenantSlug or tenantId (CONTRACT.md \xA75)."
|
|
420
459
|
);
|
|
421
460
|
}
|
|
422
|
-
function maybeBuildHttpsAgent(customCa) {
|
|
461
|
+
function maybeBuildHttpsAgent(customCa, identity) {
|
|
423
462
|
if (!customCa) {
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
463
|
+
if (!identity) {
|
|
464
|
+
return void 0;
|
|
465
|
+
}
|
|
466
|
+
} else if (!customCa.includes(PEM_MARKER)) {
|
|
427
467
|
throw new Error(
|
|
428
468
|
'customCa must be a PEM-encoded certificate (expected to contain "-----BEGIN CERTIFICATE-----") (CONTRACT.md \xA76).'
|
|
429
469
|
);
|
|
@@ -432,7 +472,11 @@ function maybeBuildHttpsAgent(customCa) {
|
|
|
432
472
|
return void 0;
|
|
433
473
|
}
|
|
434
474
|
const https = __require("https");
|
|
435
|
-
return new https.Agent({
|
|
475
|
+
return new https.Agent({
|
|
476
|
+
...customCa ? { ca: customCa } : {},
|
|
477
|
+
// rejectUnauthorized is intentionally left at its secure default (true).
|
|
478
|
+
...identity ? { cert: identity.cert, key: identity.key.expose() } : {}
|
|
479
|
+
});
|
|
436
480
|
}
|
|
437
481
|
function createSession(options) {
|
|
438
482
|
const tenantHeaderValue = resolveTenantHeaderValue(options);
|
|
@@ -441,7 +485,8 @@ function createSession(options) {
|
|
|
441
485
|
'customCa must be a PEM-encoded certificate (expected to contain "-----BEGIN CERTIFICATE-----") (CONTRACT.md \xA76).'
|
|
442
486
|
);
|
|
443
487
|
}
|
|
444
|
-
const
|
|
488
|
+
const clientIdentity = resolveClientIdentity(options);
|
|
489
|
+
const httpsAgent = maybeBuildHttpsAgent(options.customCa, clientIdentity);
|
|
445
490
|
const axiosInstance = axios__default.default.create({
|
|
446
491
|
baseURL: options.baseUrl,
|
|
447
492
|
withCredentials: true,
|
|
@@ -838,7 +883,9 @@ function createVerifier(baseUrl) {
|
|
|
838
883
|
|
|
839
884
|
// src/node/session.ts
|
|
840
885
|
var NodeSession = class extends SharedSession {
|
|
886
|
+
/** Manages the access/refresh token pair backing this session. */
|
|
841
887
|
tokenManager;
|
|
888
|
+
/** Local JWKS verifier for validating access tokens without a server round-trip. */
|
|
842
889
|
jwksVerifier;
|
|
843
890
|
#jar;
|
|
844
891
|
constructor(options, base, tokenManager, jwksVerifier, jar) {
|