@degenerate/endpoints 0.1.7 → 0.2.0
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/cors/authority/jwt/build-validate-jwt-for-audience.d.ts +41 -0
- package/dist/cors/authority/jwt/build-validate-jwt-for-audience.d.ts.map +1 -0
- package/dist/cors/authority/jwt/build-validate-jwt-for-audience.js +75 -0
- package/dist/cors/authority/jwt/validate-jwt-authorities.d.ts +5 -13
- package/dist/cors/authority/jwt/validate-jwt-authorities.d.ts.map +1 -1
- package/dist/cors/authority/jwt/validate-jwt-authorities.js +7 -27
- package/dist/cors/authority/jwt/validate-jwt-endpoints.d.ts +5 -13
- package/dist/cors/authority/jwt/validate-jwt-endpoints.d.ts.map +1 -1
- package/dist/cors/authority/jwt/validate-jwt-endpoints.js +7 -27
- package/dist/cors/authority/jwt/validate-jwt-events.d.ts +5 -13
- package/dist/cors/authority/jwt/validate-jwt-events.d.ts.map +1 -1
- package/dist/cors/authority/jwt/validate-jwt-events.js +7 -27
- package/dist/cors/authority/jwt/validate-jwt-functions.d.ts +5 -13
- package/dist/cors/authority/jwt/validate-jwt-functions.d.ts.map +1 -1
- package/dist/cors/authority/jwt/validate-jwt-functions.js +7 -27
- package/dist/cors/authority/jwt/validate-jwt-rules.d.ts +5 -13
- package/dist/cors/authority/jwt/validate-jwt-rules.d.ts.map +1 -1
- package/dist/cors/authority/jwt/validate-jwt-rules.js +7 -27
- package/dist/cors/authority/jwt/validate-jwt-share-data.d.ts +5 -13
- package/dist/cors/authority/jwt/validate-jwt-share-data.d.ts.map +1 -1
- package/dist/cors/authority/jwt/validate-jwt-share-data.js +7 -27
- package/dist/cors/endpoints/helpers/validate-incoming-request-data.d.ts.map +1 -1
- package/dist/cors/endpoints/helpers/validate-incoming-request-data.js +1 -1
- package/dist/cors/index.d.ts +1 -0
- package/dist/cors/index.d.ts.map +1 -1
- package/dist/cors/index.js +1 -0
- package/dist/examples/express-server/app.d.ts +20 -2
- package/dist/examples/express-server/app.d.ts.map +1 -1
- package/dist/examples/express-server/app.js +34 -21
- package/dist/examples/express-server/authenticate-realtime.d.ts +27 -0
- package/dist/examples/express-server/authenticate-realtime.d.ts.map +1 -0
- package/dist/examples/express-server/authenticate-realtime.js +23 -0
- package/dist/examples/express-server/server.d.ts +32 -1
- package/dist/examples/express-server/server.d.ts.map +1 -1
- package/dist/examples/express-server/server.js +61 -7
- package/dist/routes/events/v1.routes.d.ts.map +1 -1
- package/dist/routes/events/v1.routes.js +5 -3
- package/dist/routes/rules/v1/rule-set.routes.js +3 -3
- package/dist/routes/share-data.routes.d.ts.map +1 -1
- package/dist/routes/share-data.routes.js +17 -59
- package/dist/routes/sharedata/v1.routes.d.ts.map +1 -1
- package/dist/routes/sharedata/v1.routes.js +182 -9
- package/package.json +28 -15
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { RequestHandler } from 'express';
|
|
2
|
+
import { AuthorizationAudience } from '@degenerate/generic';
|
|
3
|
+
/**
|
|
4
|
+
* Returns an Express middleware that cryptographically verifies the request's
|
|
5
|
+
* Bearer JWT against the registered authority for the supplied audience.
|
|
6
|
+
*
|
|
7
|
+
* Verification flow mirrors `createShareDataAuthenticate` in
|
|
8
|
+
* `@degenerate/realtime/server/authorities-bridge.ts` — the HTTP and WS auth
|
|
9
|
+
* paths use the same primitives, so a token issued for one audience verifies
|
|
10
|
+
* consistently across both transports.
|
|
11
|
+
*
|
|
12
|
+
* Steps:
|
|
13
|
+
* 1. Read `req.app.get('authorizedAuthorities')` — host application must
|
|
14
|
+
* have registered an {@link AuthorizedAuthorities} instance at app
|
|
15
|
+
* construction time (see `createApp` in the example express server).
|
|
16
|
+
* 2. Extract the Bearer token from the `Authorization` header. Missing
|
|
17
|
+
* header or wrong scheme → `RequestNotAuthorizedError`.
|
|
18
|
+
* 3. Peek the token's `iss` claim via `determineIssuerFromBearerToken`
|
|
19
|
+
* (no signature check yet — just enough to know which key to look up).
|
|
20
|
+
* 4. Look up the issuer's verification key for the supplied audience. No
|
|
21
|
+
* registered key → `RequestNotAuthorizedError` (issuer is unknown to
|
|
22
|
+
* this server, regardless of whether the signature would otherwise be
|
|
23
|
+
* valid).
|
|
24
|
+
* 5. Run `decodeBearerToken` — verifies signature, issuer match, and
|
|
25
|
+
* payload schema (`verifyTokenPayload` enforces audience/sub/iat/nbf/exp
|
|
26
|
+
* formatting). Failure → `RequestNotAuthorizedError`.
|
|
27
|
+
* 6. Defense-in-depth: re-check `payload.aud === audience`. `decodeBearerToken`
|
|
28
|
+
* validates the payload schema but does not assert audience matches the
|
|
29
|
+
* route's expectation — without this, a token issued for the EVENTS
|
|
30
|
+
* audience could be used on a SHAREDATA route.
|
|
31
|
+
* 7. Attach the decoded payload to `req.auth` and call `next()`.
|
|
32
|
+
*
|
|
33
|
+
* Failure mode is uniform: every reject throws `RequestNotAuthorizedError`.
|
|
34
|
+
* Pre-verification rejects (missing/empty/wrong-scheme Authorization header,
|
|
35
|
+
* unregistered authorities) carry a specific message; token-verification
|
|
36
|
+
* failures are deliberately normalized to "Bearer token verification failed"
|
|
37
|
+
* so callers can't probe which check failed. The existing
|
|
38
|
+
* `unauthorizedHandler` error middleware turns these into 403 responses.
|
|
39
|
+
*/
|
|
40
|
+
export declare const buildValidateJWTForAudience: (audience: AuthorizationAudience) => RequestHandler;
|
|
41
|
+
//# sourceMappingURL=build-validate-jwt-for-audience.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"build-validate-jwt-for-audience.d.ts","sourceRoot":"","sources":["../../../../src/cors/authority/jwt/build-validate-jwt-for-audience.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AACzC,OAAO,EACH,qBAAqB,EAKxB,MAAM,qBAAqB,CAAC;AAE7B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoCG;AACH,eAAO,MAAM,2BAA2B,GACpC,UAAU,qBAAqB,KAChC,cA0CF,CAAC"}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.buildValidateJWTForAudience = void 0;
|
|
4
|
+
const generic_1 = require("@degenerate/generic");
|
|
5
|
+
/**
|
|
6
|
+
* Returns an Express middleware that cryptographically verifies the request's
|
|
7
|
+
* Bearer JWT against the registered authority for the supplied audience.
|
|
8
|
+
*
|
|
9
|
+
* Verification flow mirrors `createShareDataAuthenticate` in
|
|
10
|
+
* `@degenerate/realtime/server/authorities-bridge.ts` — the HTTP and WS auth
|
|
11
|
+
* paths use the same primitives, so a token issued for one audience verifies
|
|
12
|
+
* consistently across both transports.
|
|
13
|
+
*
|
|
14
|
+
* Steps:
|
|
15
|
+
* 1. Read `req.app.get('authorizedAuthorities')` — host application must
|
|
16
|
+
* have registered an {@link AuthorizedAuthorities} instance at app
|
|
17
|
+
* construction time (see `createApp` in the example express server).
|
|
18
|
+
* 2. Extract the Bearer token from the `Authorization` header. Missing
|
|
19
|
+
* header or wrong scheme → `RequestNotAuthorizedError`.
|
|
20
|
+
* 3. Peek the token's `iss` claim via `determineIssuerFromBearerToken`
|
|
21
|
+
* (no signature check yet — just enough to know which key to look up).
|
|
22
|
+
* 4. Look up the issuer's verification key for the supplied audience. No
|
|
23
|
+
* registered key → `RequestNotAuthorizedError` (issuer is unknown to
|
|
24
|
+
* this server, regardless of whether the signature would otherwise be
|
|
25
|
+
* valid).
|
|
26
|
+
* 5. Run `decodeBearerToken` — verifies signature, issuer match, and
|
|
27
|
+
* payload schema (`verifyTokenPayload` enforces audience/sub/iat/nbf/exp
|
|
28
|
+
* formatting). Failure → `RequestNotAuthorizedError`.
|
|
29
|
+
* 6. Defense-in-depth: re-check `payload.aud === audience`. `decodeBearerToken`
|
|
30
|
+
* validates the payload schema but does not assert audience matches the
|
|
31
|
+
* route's expectation — without this, a token issued for the EVENTS
|
|
32
|
+
* audience could be used on a SHAREDATA route.
|
|
33
|
+
* 7. Attach the decoded payload to `req.auth` and call `next()`.
|
|
34
|
+
*
|
|
35
|
+
* Failure mode is uniform: every reject throws `RequestNotAuthorizedError`.
|
|
36
|
+
* Pre-verification rejects (missing/empty/wrong-scheme Authorization header,
|
|
37
|
+
* unregistered authorities) carry a specific message; token-verification
|
|
38
|
+
* failures are deliberately normalized to "Bearer token verification failed"
|
|
39
|
+
* so callers can't probe which check failed. The existing
|
|
40
|
+
* `unauthorizedHandler` error middleware turns these into 403 responses.
|
|
41
|
+
*/
|
|
42
|
+
const buildValidateJWTForAudience = (audience) => {
|
|
43
|
+
return (req, _res, next) => {
|
|
44
|
+
const authorities = req.app.get('authorizedAuthorities');
|
|
45
|
+
if (!authorities) {
|
|
46
|
+
throw new generic_1.RequestNotAuthorizedError('authorizedAuthorities is not registered on the app — see createApp()');
|
|
47
|
+
}
|
|
48
|
+
const authHeader = req.headers.authorization;
|
|
49
|
+
if (typeof authHeader !== 'string' || !authHeader.startsWith('Bearer ')) {
|
|
50
|
+
throw new generic_1.RequestNotAuthorizedError('Missing or malformed Authorization header (expected "Bearer <token>")');
|
|
51
|
+
}
|
|
52
|
+
const token = authHeader.slice('Bearer '.length).trim();
|
|
53
|
+
if (!token) {
|
|
54
|
+
throw new generic_1.RequestNotAuthorizedError('Bearer token is empty');
|
|
55
|
+
}
|
|
56
|
+
let payload;
|
|
57
|
+
try {
|
|
58
|
+
// All four verification steps (issuer peek → key lookup →
|
|
59
|
+
// signature/payload verify → audience defense-in-depth) are
|
|
60
|
+
// centralized in @degenerate/generic so the HTTP and WS
|
|
61
|
+
// transports can't drift on which checks they run.
|
|
62
|
+
payload = (0, generic_1.verifyJwtBearerTokenForAudience)(token, authorities, audience);
|
|
63
|
+
}
|
|
64
|
+
catch {
|
|
65
|
+
// Normalize every failure mode to one Express-friendly error.
|
|
66
|
+
// The underlying helper throws specific error classes; we
|
|
67
|
+
// collapse them so the existing unauthorized-handler chain
|
|
68
|
+
// turns them all into a 403.
|
|
69
|
+
throw new generic_1.RequestNotAuthorizedError('Bearer token verification failed');
|
|
70
|
+
}
|
|
71
|
+
req.auth = payload;
|
|
72
|
+
next();
|
|
73
|
+
};
|
|
74
|
+
};
|
|
75
|
+
exports.buildValidateJWTForAudience = buildValidateJWTForAudience;
|
|
@@ -1,16 +1,8 @@
|
|
|
1
|
-
import { Request, Response, NextFunction } from 'express';
|
|
2
1
|
/**
|
|
3
|
-
*
|
|
4
|
-
* for the
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
* if this is successful.
|
|
8
|
-
*
|
|
9
|
-
* @param req the incoming request
|
|
10
|
-
* @param res the response object
|
|
11
|
-
* @param next CORS next function
|
|
12
|
-
*
|
|
13
|
-
* @returns the next step if the validation succeeds or a unauthorized or disallowed response.
|
|
2
|
+
* Express middleware that cryptographically verifies the request's Bearer
|
|
3
|
+
* JWT for the AUTHORITIES audience. Thin wrapper around
|
|
4
|
+
* {@link buildValidateJWTForAudience}; behavior, failure modes, and the
|
|
5
|
+
* `req.auth` attachment are documented on that helper.
|
|
14
6
|
*/
|
|
15
|
-
export declare
|
|
7
|
+
export declare const validateJWTAuthorities: import("express").RequestHandler<import("express-serve-static-core").ParamsDictionary, any, any, import("qs").ParsedQs, Record<string, any>>;
|
|
16
8
|
//# sourceMappingURL=validate-jwt-authorities.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validate-jwt-authorities.d.ts","sourceRoot":"","sources":["../../../../src/cors/authority/jwt/validate-jwt-authorities.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"validate-jwt-authorities.d.ts","sourceRoot":"","sources":["../../../../src/cors/authority/jwt/validate-jwt-authorities.ts"],"names":[],"mappings":"AAGA;;;;;GAKG;AACH,eAAO,MAAM,sBAAsB,8IAElC,CAAC"}
|
|
@@ -1,32 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
3
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
exports.validateJWTAuthorities =
|
|
3
|
+
exports.validateJWTAuthorities = void 0;
|
|
5
4
|
const generic_1 = require("@degenerate/generic");
|
|
6
|
-
const
|
|
5
|
+
const build_validate_jwt_for_audience_1 = require("./build-validate-jwt-for-audience");
|
|
7
6
|
/**
|
|
8
|
-
*
|
|
9
|
-
* for the
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
* if this is successful.
|
|
13
|
-
*
|
|
14
|
-
* @param req the incoming request
|
|
15
|
-
* @param res the response object
|
|
16
|
-
* @param next CORS next function
|
|
17
|
-
*
|
|
18
|
-
* @returns the next step if the validation succeeds or a unauthorized or disallowed response.
|
|
7
|
+
* Express middleware that cryptographically verifies the request's Bearer
|
|
8
|
+
* JWT for the AUTHORITIES audience. Thin wrapper around
|
|
9
|
+
* {@link buildValidateJWTForAudience}; behavior, failure modes, and the
|
|
10
|
+
* `req.auth` attachment are documented on that helper.
|
|
19
11
|
*/
|
|
20
|
-
|
|
21
|
-
// get audience from the request
|
|
22
|
-
const audience = (0, get_set_audiences_1.getAudienceAuthority)(req);
|
|
23
|
-
if (!audience) {
|
|
24
|
-
throw new generic_1.RequestNotAuthorizedError('No audience found in the request');
|
|
25
|
-
}
|
|
26
|
-
if (audience !== generic_1.AuthorizationAudience.AUTHORITIES) {
|
|
27
|
-
throw new generic_1.RequestNotAuthorizedError('the audience included is not for authorities');
|
|
28
|
-
}
|
|
29
|
-
// check if an Authority is present.
|
|
30
|
-
next();
|
|
31
|
-
return;
|
|
32
|
-
}
|
|
12
|
+
exports.validateJWTAuthorities = (0, build_validate_jwt_for_audience_1.buildValidateJWTForAudience)(generic_1.AuthorizationAudience.AUTHORITIES);
|
|
@@ -1,16 +1,8 @@
|
|
|
1
|
-
import { Request, Response, NextFunction } from 'express';
|
|
2
1
|
/**
|
|
3
|
-
*
|
|
4
|
-
* for the
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
* if this is successful.
|
|
8
|
-
*
|
|
9
|
-
* @param req the incoming request
|
|
10
|
-
* @param res the response object
|
|
11
|
-
* @param next CORS next function
|
|
12
|
-
*
|
|
13
|
-
* @returns the next step if the validation succeeds or a unauthorized or disallowed response.
|
|
2
|
+
* Express middleware that cryptographically verifies the request's Bearer
|
|
3
|
+
* JWT for the ENDPOINTS audience. Thin wrapper around
|
|
4
|
+
* {@link buildValidateJWTForAudience}; behavior, failure modes, and the
|
|
5
|
+
* `req.auth` attachment are documented on that helper.
|
|
14
6
|
*/
|
|
15
|
-
export declare
|
|
7
|
+
export declare const validateJWTEndpoints: import("express").RequestHandler<import("express-serve-static-core").ParamsDictionary, any, any, import("qs").ParsedQs, Record<string, any>>;
|
|
16
8
|
//# sourceMappingURL=validate-jwt-endpoints.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validate-jwt-endpoints.d.ts","sourceRoot":"","sources":["../../../../src/cors/authority/jwt/validate-jwt-endpoints.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"validate-jwt-endpoints.d.ts","sourceRoot":"","sources":["../../../../src/cors/authority/jwt/validate-jwt-endpoints.ts"],"names":[],"mappings":"AAGA;;;;;GAKG;AACH,eAAO,MAAM,oBAAoB,8IAEhC,CAAC"}
|
|
@@ -1,32 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
3
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
exports.validateJWTEndpoints =
|
|
3
|
+
exports.validateJWTEndpoints = void 0;
|
|
5
4
|
const generic_1 = require("@degenerate/generic");
|
|
6
|
-
const
|
|
5
|
+
const build_validate_jwt_for_audience_1 = require("./build-validate-jwt-for-audience");
|
|
7
6
|
/**
|
|
8
|
-
*
|
|
9
|
-
* for the
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
* if this is successful.
|
|
13
|
-
*
|
|
14
|
-
* @param req the incoming request
|
|
15
|
-
* @param res the response object
|
|
16
|
-
* @param next CORS next function
|
|
17
|
-
*
|
|
18
|
-
* @returns the next step if the validation succeeds or a unauthorized or disallowed response.
|
|
7
|
+
* Express middleware that cryptographically verifies the request's Bearer
|
|
8
|
+
* JWT for the ENDPOINTS audience. Thin wrapper around
|
|
9
|
+
* {@link buildValidateJWTForAudience}; behavior, failure modes, and the
|
|
10
|
+
* `req.auth` attachment are documented on that helper.
|
|
19
11
|
*/
|
|
20
|
-
|
|
21
|
-
// get audience from the request
|
|
22
|
-
const audience = (0, get_set_audiences_1.getAudienceAuthority)(req);
|
|
23
|
-
if (!audience) {
|
|
24
|
-
throw new generic_1.RequestNotAuthorizedError('No audience found in the request');
|
|
25
|
-
}
|
|
26
|
-
if (audience !== generic_1.AuthorizationAudience.ENDPOINTS) {
|
|
27
|
-
throw new generic_1.RequestNotAuthorizedError('the audience included is not for endpoints');
|
|
28
|
-
}
|
|
29
|
-
// check if an Authority is present.
|
|
30
|
-
next();
|
|
31
|
-
return;
|
|
32
|
-
}
|
|
12
|
+
exports.validateJWTEndpoints = (0, build_validate_jwt_for_audience_1.buildValidateJWTForAudience)(generic_1.AuthorizationAudience.ENDPOINTS);
|
|
@@ -1,16 +1,8 @@
|
|
|
1
|
-
import { Request, Response, NextFunction } from 'express';
|
|
2
1
|
/**
|
|
3
|
-
*
|
|
4
|
-
* for the
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
* if this is successful.
|
|
8
|
-
*
|
|
9
|
-
* @param req the incoming request
|
|
10
|
-
* @param res the response object
|
|
11
|
-
* @param next CORS next function
|
|
12
|
-
*
|
|
13
|
-
* @returns the next step if the validation succeeds or a unauthorized or disallowed response.
|
|
2
|
+
* Express middleware that cryptographically verifies the request's Bearer
|
|
3
|
+
* JWT for the EVENTS audience. Thin wrapper around
|
|
4
|
+
* {@link buildValidateJWTForAudience}; behavior, failure modes, and the
|
|
5
|
+
* `req.auth` attachment are documented on that helper.
|
|
14
6
|
*/
|
|
15
|
-
export declare
|
|
7
|
+
export declare const validateJWTEvents: import("express").RequestHandler<import("express-serve-static-core").ParamsDictionary, any, any, import("qs").ParsedQs, Record<string, any>>;
|
|
16
8
|
//# sourceMappingURL=validate-jwt-events.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validate-jwt-events.d.ts","sourceRoot":"","sources":["../../../../src/cors/authority/jwt/validate-jwt-events.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"validate-jwt-events.d.ts","sourceRoot":"","sources":["../../../../src/cors/authority/jwt/validate-jwt-events.ts"],"names":[],"mappings":"AAGA;;;;;GAKG;AACH,eAAO,MAAM,iBAAiB,8IAE7B,CAAC"}
|
|
@@ -1,32 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
3
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
exports.validateJWTEvents =
|
|
3
|
+
exports.validateJWTEvents = void 0;
|
|
5
4
|
const generic_1 = require("@degenerate/generic");
|
|
6
|
-
const
|
|
5
|
+
const build_validate_jwt_for_audience_1 = require("./build-validate-jwt-for-audience");
|
|
7
6
|
/**
|
|
8
|
-
*
|
|
9
|
-
* for the
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
* if this is successful.
|
|
13
|
-
*
|
|
14
|
-
* @param req the incoming request
|
|
15
|
-
* @param res the response object
|
|
16
|
-
* @param next CORS next function
|
|
17
|
-
*
|
|
18
|
-
* @returns the next step if the validation succeeds or a unauthorized or disallowed response.
|
|
7
|
+
* Express middleware that cryptographically verifies the request's Bearer
|
|
8
|
+
* JWT for the EVENTS audience. Thin wrapper around
|
|
9
|
+
* {@link buildValidateJWTForAudience}; behavior, failure modes, and the
|
|
10
|
+
* `req.auth` attachment are documented on that helper.
|
|
19
11
|
*/
|
|
20
|
-
|
|
21
|
-
// get audience from the request
|
|
22
|
-
const audience = (0, get_set_audiences_1.getAudienceAuthority)(req);
|
|
23
|
-
if (!audience) {
|
|
24
|
-
throw new generic_1.RequestNotAuthorizedError('No audience found in the request');
|
|
25
|
-
}
|
|
26
|
-
if (audience !== generic_1.AuthorizationAudience.EVENTS) {
|
|
27
|
-
throw new generic_1.RequestNotAuthorizedError('the audience included is not for events');
|
|
28
|
-
}
|
|
29
|
-
// check if an Authority is present.
|
|
30
|
-
next();
|
|
31
|
-
return;
|
|
32
|
-
}
|
|
12
|
+
exports.validateJWTEvents = (0, build_validate_jwt_for_audience_1.buildValidateJWTForAudience)(generic_1.AuthorizationAudience.EVENTS);
|
|
@@ -1,16 +1,8 @@
|
|
|
1
|
-
import { Request, Response, NextFunction } from 'express';
|
|
2
1
|
/**
|
|
3
|
-
*
|
|
4
|
-
* for the
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
* if this is successful.
|
|
8
|
-
*
|
|
9
|
-
* @param req the incoming request
|
|
10
|
-
* @param res the response object
|
|
11
|
-
* @param next CORS next function
|
|
12
|
-
*
|
|
13
|
-
* @returns the next step if the validation succeeds or a unauthorized or disallowed response.
|
|
2
|
+
* Express middleware that cryptographically verifies the request's Bearer
|
|
3
|
+
* JWT for the FUNCTIONS audience. Thin wrapper around
|
|
4
|
+
* {@link buildValidateJWTForAudience}; behavior, failure modes, and the
|
|
5
|
+
* `req.auth` attachment are documented on that helper.
|
|
14
6
|
*/
|
|
15
|
-
export declare
|
|
7
|
+
export declare const validateJWTFunctions: import("express").RequestHandler<import("express-serve-static-core").ParamsDictionary, any, any, import("qs").ParsedQs, Record<string, any>>;
|
|
16
8
|
//# sourceMappingURL=validate-jwt-functions.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validate-jwt-functions.d.ts","sourceRoot":"","sources":["../../../../src/cors/authority/jwt/validate-jwt-functions.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"validate-jwt-functions.d.ts","sourceRoot":"","sources":["../../../../src/cors/authority/jwt/validate-jwt-functions.ts"],"names":[],"mappings":"AAGA;;;;;GAKG;AACH,eAAO,MAAM,oBAAoB,8IAEhC,CAAC"}
|
|
@@ -1,32 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
3
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
exports.validateJWTFunctions =
|
|
3
|
+
exports.validateJWTFunctions = void 0;
|
|
5
4
|
const generic_1 = require("@degenerate/generic");
|
|
6
|
-
const
|
|
5
|
+
const build_validate_jwt_for_audience_1 = require("./build-validate-jwt-for-audience");
|
|
7
6
|
/**
|
|
8
|
-
*
|
|
9
|
-
* for the
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
* if this is successful.
|
|
13
|
-
*
|
|
14
|
-
* @param req the incoming request
|
|
15
|
-
* @param res the response object
|
|
16
|
-
* @param next CORS next function
|
|
17
|
-
*
|
|
18
|
-
* @returns the next step if the validation succeeds or a unauthorized or disallowed response.
|
|
7
|
+
* Express middleware that cryptographically verifies the request's Bearer
|
|
8
|
+
* JWT for the FUNCTIONS audience. Thin wrapper around
|
|
9
|
+
* {@link buildValidateJWTForAudience}; behavior, failure modes, and the
|
|
10
|
+
* `req.auth` attachment are documented on that helper.
|
|
19
11
|
*/
|
|
20
|
-
|
|
21
|
-
// get audience from the request
|
|
22
|
-
const audience = (0, get_set_audiences_1.getAudienceAuthority)(req);
|
|
23
|
-
if (!audience) {
|
|
24
|
-
throw new generic_1.RequestNotAuthorizedError('No audience found in the request');
|
|
25
|
-
}
|
|
26
|
-
if (audience !== generic_1.AuthorizationAudience.FUNCTIONS) {
|
|
27
|
-
throw new generic_1.RequestNotAuthorizedError('the audience included is not for functions');
|
|
28
|
-
}
|
|
29
|
-
// check if an Authority is present.
|
|
30
|
-
next();
|
|
31
|
-
return;
|
|
32
|
-
}
|
|
12
|
+
exports.validateJWTFunctions = (0, build_validate_jwt_for_audience_1.buildValidateJWTForAudience)(generic_1.AuthorizationAudience.FUNCTIONS);
|
|
@@ -1,16 +1,8 @@
|
|
|
1
|
-
import { Request, Response, NextFunction } from 'express';
|
|
2
1
|
/**
|
|
3
|
-
*
|
|
4
|
-
* for the
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
* if this is successful.
|
|
8
|
-
*
|
|
9
|
-
* @param req the incoming request
|
|
10
|
-
* @param res the response object
|
|
11
|
-
* @param next CORS next function
|
|
12
|
-
*
|
|
13
|
-
* @returns the next step if the validation succeeds or a unauthorized or disallowed response.
|
|
2
|
+
* Express middleware that cryptographically verifies the request's Bearer
|
|
3
|
+
* JWT for the RULES audience. Thin wrapper around
|
|
4
|
+
* {@link buildValidateJWTForAudience}; behavior, failure modes, and the
|
|
5
|
+
* `req.auth` attachment are documented on that helper.
|
|
14
6
|
*/
|
|
15
|
-
export declare
|
|
7
|
+
export declare const validateJWTRules: import("express").RequestHandler<import("express-serve-static-core").ParamsDictionary, any, any, import("qs").ParsedQs, Record<string, any>>;
|
|
16
8
|
//# sourceMappingURL=validate-jwt-rules.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validate-jwt-rules.d.ts","sourceRoot":"","sources":["../../../../src/cors/authority/jwt/validate-jwt-rules.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"validate-jwt-rules.d.ts","sourceRoot":"","sources":["../../../../src/cors/authority/jwt/validate-jwt-rules.ts"],"names":[],"mappings":"AAGA;;;;;GAKG;AACH,eAAO,MAAM,gBAAgB,8IAE5B,CAAC"}
|
|
@@ -1,32 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
3
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
exports.validateJWTRules =
|
|
3
|
+
exports.validateJWTRules = void 0;
|
|
5
4
|
const generic_1 = require("@degenerate/generic");
|
|
6
|
-
const
|
|
5
|
+
const build_validate_jwt_for_audience_1 = require("./build-validate-jwt-for-audience");
|
|
7
6
|
/**
|
|
8
|
-
*
|
|
9
|
-
* for the
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
* if this is successful.
|
|
13
|
-
*
|
|
14
|
-
* @param req the incoming request
|
|
15
|
-
* @param res the response object
|
|
16
|
-
* @param next CORS next function
|
|
17
|
-
*
|
|
18
|
-
* @returns the next step if the validation succeeds or a unauthorized or disallowed response.
|
|
7
|
+
* Express middleware that cryptographically verifies the request's Bearer
|
|
8
|
+
* JWT for the RULES audience. Thin wrapper around
|
|
9
|
+
* {@link buildValidateJWTForAudience}; behavior, failure modes, and the
|
|
10
|
+
* `req.auth` attachment are documented on that helper.
|
|
19
11
|
*/
|
|
20
|
-
|
|
21
|
-
// get audience from the request
|
|
22
|
-
const audience = (0, get_set_audiences_1.getAudienceAuthority)(req);
|
|
23
|
-
if (!audience) {
|
|
24
|
-
throw new generic_1.RequestNotAuthorizedError('No audience found in the request');
|
|
25
|
-
}
|
|
26
|
-
if (audience !== generic_1.AuthorizationAudience.RULES) {
|
|
27
|
-
throw new generic_1.RequestNotAuthorizedError('the audience included is not for rules');
|
|
28
|
-
}
|
|
29
|
-
// check if an Authority is present.
|
|
30
|
-
next();
|
|
31
|
-
return;
|
|
32
|
-
}
|
|
12
|
+
exports.validateJWTRules = (0, build_validate_jwt_for_audience_1.buildValidateJWTForAudience)(generic_1.AuthorizationAudience.RULES);
|
|
@@ -1,16 +1,8 @@
|
|
|
1
|
-
import { Request, Response, NextFunction } from 'express';
|
|
2
1
|
/**
|
|
3
|
-
*
|
|
4
|
-
* for the
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
* if this is successful.
|
|
8
|
-
*
|
|
9
|
-
* @param req the incoming request
|
|
10
|
-
* @param res the response object
|
|
11
|
-
* @param next CORS next function
|
|
12
|
-
*
|
|
13
|
-
* @returns the next step if the validation succeeds or a unauthorized or disallowed response.
|
|
2
|
+
* Express middleware that cryptographically verifies the request's Bearer
|
|
3
|
+
* JWT for the SHAREDATA audience. Thin wrapper around
|
|
4
|
+
* {@link buildValidateJWTForAudience}; behavior, failure modes, and the
|
|
5
|
+
* `req.auth` attachment are documented on that helper.
|
|
14
6
|
*/
|
|
15
|
-
export declare
|
|
7
|
+
export declare const validateJWTShareData: import("express").RequestHandler<import("express-serve-static-core").ParamsDictionary, any, any, import("qs").ParsedQs, Record<string, any>>;
|
|
16
8
|
//# sourceMappingURL=validate-jwt-share-data.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validate-jwt-share-data.d.ts","sourceRoot":"","sources":["../../../../src/cors/authority/jwt/validate-jwt-share-data.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"validate-jwt-share-data.d.ts","sourceRoot":"","sources":["../../../../src/cors/authority/jwt/validate-jwt-share-data.ts"],"names":[],"mappings":"AAGA;;;;;GAKG;AACH,eAAO,MAAM,oBAAoB,8IAEhC,CAAC"}
|
|
@@ -1,32 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
3
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
exports.validateJWTShareData =
|
|
3
|
+
exports.validateJWTShareData = void 0;
|
|
5
4
|
const generic_1 = require("@degenerate/generic");
|
|
6
|
-
const
|
|
5
|
+
const build_validate_jwt_for_audience_1 = require("./build-validate-jwt-for-audience");
|
|
7
6
|
/**
|
|
8
|
-
*
|
|
9
|
-
* for the
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
* if this is successful.
|
|
13
|
-
*
|
|
14
|
-
* @param req the incoming request
|
|
15
|
-
* @param res the response object
|
|
16
|
-
* @param next CORS next function
|
|
17
|
-
*
|
|
18
|
-
* @returns the next step if the validation succeeds or a unauthorized or disallowed response.
|
|
7
|
+
* Express middleware that cryptographically verifies the request's Bearer
|
|
8
|
+
* JWT for the SHAREDATA audience. Thin wrapper around
|
|
9
|
+
* {@link buildValidateJWTForAudience}; behavior, failure modes, and the
|
|
10
|
+
* `req.auth` attachment are documented on that helper.
|
|
19
11
|
*/
|
|
20
|
-
|
|
21
|
-
// get audience from the request
|
|
22
|
-
const audience = (0, get_set_audiences_1.getAudienceAuthority)(req);
|
|
23
|
-
if (!audience) {
|
|
24
|
-
throw new generic_1.RequestNotAuthorizedError('No audience found in the request');
|
|
25
|
-
}
|
|
26
|
-
if (audience !== generic_1.AuthorizationAudience.SHAREDATA) {
|
|
27
|
-
throw new generic_1.RequestNotAuthorizedError('the audience included is not for share data');
|
|
28
|
-
}
|
|
29
|
-
// check if an Authority is present.
|
|
30
|
-
next();
|
|
31
|
-
return;
|
|
32
|
-
}
|
|
12
|
+
exports.validateJWTShareData = (0, build_validate_jwt_for_audience_1.buildValidateJWTForAudience)(generic_1.AuthorizationAudience.SHAREDATA);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validate-incoming-request-data.d.ts","sourceRoot":"","sources":["../../../../src/cors/endpoints/helpers/validate-incoming-request-data.ts"],"names":[],"mappings":"AAAA,OAAO,EAAY,SAAS,EAAE,MAAM,KAAK,CAAC;AAC1C,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAG1D;;;;;GAKG;AACH,wBAAgB,2BAA2B,CAAC,CAAC,SAAS,SAAS,CAAC,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC,
|
|
1
|
+
{"version":3,"file":"validate-incoming-request-data.d.ts","sourceRoot":"","sources":["../../../../src/cors/endpoints/helpers/validate-incoming-request-data.ts"],"names":[],"mappings":"AAAA,OAAO,EAAY,SAAS,EAAE,MAAM,KAAK,CAAC;AAC1C,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAG1D;;;;;GAKG;AACH,wBAAgB,2BAA2B,CAAC,CAAC,SAAS,SAAS,CAAC,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC,IACvE,KAAK,OAAO,EAAE,KAAK,QAAQ,EAAE,MAAM,YAAY,UAa1D"}
|
|
@@ -33,5 +33,5 @@ function validateIncomingRequestData(schema) {
|
|
|
33
33
|
* @returns an array of formatted error messages
|
|
34
34
|
*/
|
|
35
35
|
function formatZodErrors(error) {
|
|
36
|
-
return error.
|
|
36
|
+
return error.issues.map((issue) => `${issue.path.join('.')} is ${issue.message}`);
|
|
37
37
|
}
|
package/dist/cors/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export * from './authority/audience/get-set-audiences';
|
|
2
|
+
export * from './authority/jwt/build-validate-jwt-for-audience';
|
|
2
3
|
export * from './authority/jwt/validate-jwt-authorities';
|
|
3
4
|
export * from './authority/jwt/validate-jwt-endpoints';
|
|
4
5
|
export * from './authority/jwt/validate-jwt-events';
|
package/dist/cors/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/cors/index.ts"],"names":[],"mappings":"AAAA,cAAc,wCAAwC,CAAC;AACvD,cAAc,0CAA0C,CAAC;AACzD,cAAc,wCAAwC,CAAC;AACvD,cAAc,qCAAqC,CAAC;AACpD,cAAc,wCAAwC,CAAC;AACvD,cAAc,oCAAoC,CAAC;AACnD,cAAc,yCAAyC,CAAC;AAGxD,cAAc,oDAAoD,CAAC;AAEnE,cAAc,2CAA2C,CAAC;AAI1D,cAAc,4BAA4B,CAAC;AAC3C,cAAc,8BAA8B,CAAC;AAC7C,cAAc,+BAA+B,CAAC;AAI9C,cAAc,+BAA+B,CAAC;AAC9C,cAAc,2BAA2B,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/cors/index.ts"],"names":[],"mappings":"AAAA,cAAc,wCAAwC,CAAC;AACvD,cAAc,iDAAiD,CAAC;AAChE,cAAc,0CAA0C,CAAC;AACzD,cAAc,wCAAwC,CAAC;AACvD,cAAc,qCAAqC,CAAC;AACpD,cAAc,wCAAwC,CAAC;AACvD,cAAc,oCAAoC,CAAC;AACnD,cAAc,yCAAyC,CAAC;AAGxD,cAAc,oDAAoD,CAAC;AAEnE,cAAc,2CAA2C,CAAC;AAI1D,cAAc,4BAA4B,CAAC;AAC3C,cAAc,8BAA8B,CAAC;AAC7C,cAAc,+BAA+B,CAAC;AAI9C,cAAc,+BAA+B,CAAC;AAC9C,cAAc,2BAA2B,CAAC"}
|
package/dist/cors/index.js
CHANGED
|
@@ -15,6 +15,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
__exportStar(require("./authority/audience/get-set-audiences"), exports);
|
|
18
|
+
__exportStar(require("./authority/jwt/build-validate-jwt-for-audience"), exports);
|
|
18
19
|
__exportStar(require("./authority/jwt/validate-jwt-authorities"), exports);
|
|
19
20
|
__exportStar(require("./authority/jwt/validate-jwt-endpoints"), exports);
|
|
20
21
|
__exportStar(require("./authority/jwt/validate-jwt-events"), exports);
|
|
@@ -1,3 +1,21 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import express, { type Express } from 'express';
|
|
2
|
+
import { AuthorizedAuthorities } from '@degenerate/generic';
|
|
3
|
+
import { ShareDataManager } from '@degenerate/sharedata';
|
|
4
|
+
export interface CreateAppResult {
|
|
5
|
+
app: Express;
|
|
6
|
+
authorizedAuthorities: AuthorizedAuthorities;
|
|
7
|
+
shareDataManager: ShareDataManager;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Builds a fresh Express app with all SAFE routes wired in. Returns the app
|
|
11
|
+
* along with the shared `ShareDataManager` instance — handed back so callers
|
|
12
|
+
* (e.g. `createSafeServer` for realtime attachment) can subscribe to its
|
|
13
|
+
* events without reaching into `app.locals`.
|
|
14
|
+
*
|
|
15
|
+
* Route handlers access the manager via `req.app.get('shareDataManager')`,
|
|
16
|
+
* matching the existing `authorizedAuthorities` pattern.
|
|
17
|
+
*/
|
|
18
|
+
export declare function createApp(): CreateAppResult;
|
|
19
|
+
declare const _default: express.Express;
|
|
20
|
+
export default _default;
|
|
3
21
|
//# sourceMappingURL=app.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"app.d.ts","sourceRoot":"","sources":["../../../src/examples/express-server/app.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"app.d.ts","sourceRoot":"","sources":["../../../src/examples/express-server/app.ts"],"names":[],"mappings":"AAAA,OAAO,OAAO,EAAE,EAAE,KAAK,OAAO,EAAE,MAAM,SAAS,CAAC;AAChD,OAAO,EAAE,qBAAqB,EAAE,MAAM,qBAAqB,CAAC;AAC5D,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAWzD,MAAM,WAAW,eAAe;IAC5B,GAAG,EAAE,OAAO,CAAC;IACb,qBAAqB,EAAE,qBAAqB,CAAC;IAC7C,gBAAgB,EAAE,gBAAgB,CAAC;CACtC;AAED;;;;;;;;GAQG;AACH,wBAAgB,SAAS,IAAI,eAAe,CAqB3C;;AAKD,wBAAmC"}
|