node-server-engine 1.1.6 → 1.1.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.env.example +0 -38
- package/.nycrc +9 -3
- package/README.md +2 -3
- package/dist/const/tokenIssuer.d.ts +2 -4
- package/dist/const/tokenIssuer.js +0 -1
- package/dist/const/tokenIssuer.js.map +1 -1
- package/dist/entities/Endpoint/Endpoint.types.d.ts +2 -19
- package/dist/entities/Endpoint/Endpoint.types.js +1 -8
- package/dist/entities/Endpoint/Endpoint.types.js.map +1 -1
- package/dist/middleware/index.d.ts +0 -1
- package/dist/middleware/index.js +0 -11
- package/dist/middleware/index.js.map +1 -1
- package/dist/utils/index.d.ts +0 -1
- package/dist/utils/index.js +0 -11
- package/dist/utils/index.js.map +1 -1
- package/dist/utils/jwt/jwt.d.ts +0 -1
- package/dist/utils/jwt/jwt.js +2 -23
- package/dist/utils/jwt/jwt.js.map +1 -1
- package/dist/utils/report/report.js +1 -2
- package/dist/utils/report/report.js.map +1 -1
- package/package.json +8 -7
- package/src/const/tokenIssuer.ts +1 -3
- package/src/entities/Endpoint/Endpoint.test.ts +0 -89
- package/src/entities/Endpoint/Endpoint.types.ts +3 -30
- package/src/entities/KeySet/KeySet.test.ts +1 -1
- package/src/middleware/index.ts +0 -1
- package/src/utils/index.ts +0 -1
- package/src/utils/jwt/jwt.test.ts +0 -13
- package/src/utils/jwt/jwt.ts +2 -25
- package/src/utils/report/report.ts +1 -2
- package/test/env.ts +0 -5
- package/test/hooks.ts +0 -2
- package/dist/middleware/authAdmin/authAdmin.d.ts +0 -4
- package/dist/middleware/authAdmin/authAdmin.js +0 -105
- package/dist/middleware/authAdmin/authAdmin.js.map +0 -1
- package/dist/middleware/authAdmin/authAdmin.types.d.ts +0 -16
- package/dist/middleware/authAdmin/authAdmin.types.js +0 -2
- package/dist/middleware/authAdmin/authAdmin.types.js.map +0 -1
- package/dist/middleware/authAdmin/index.d.ts +0 -2
- package/dist/middleware/authAdmin/index.js +0 -28
- package/dist/middleware/authAdmin/index.js.map +0 -1
- package/dist/utils/getDynamicLink/getDynamicLink.d.ts +0 -3
- package/dist/utils/getDynamicLink/getDynamicLink.js +0 -28
- package/dist/utils/getDynamicLink/getDynamicLink.js.map +0 -1
- package/dist/utils/getDynamicLink/getDynamicLink.types.d.ts +0 -10
- package/dist/utils/getDynamicLink/getDynamicLink.types.js +0 -2
- package/dist/utils/getDynamicLink/getDynamicLink.types.js.map +0 -1
- package/dist/utils/getDynamicLink/getDynamicLink.validate.d.ts +0 -2
- package/dist/utils/getDynamicLink/getDynamicLink.validate.js +0 -14
- package/dist/utils/getDynamicLink/getDynamicLink.validate.js.map +0 -1
- package/dist/utils/getDynamicLink/index.d.ts +0 -2
- package/dist/utils/getDynamicLink/index.js +0 -28
- package/dist/utils/getDynamicLink/index.js.map +0 -1
- package/src/middleware/authAdmin/authAdmin.test.ts +0 -199
- package/src/middleware/authAdmin/authAdmin.ts +0 -114
- package/src/middleware/authAdmin/authAdmin.types.ts +0 -19
- package/src/middleware/authAdmin/index.ts +0 -2
- package/src/utils/getDynamicLink/getDynamicLink.test.ts +0 -51
- package/src/utils/getDynamicLink/getDynamicLink.ts +0 -28
- package/src/utils/getDynamicLink/getDynamicLink.types.ts +0 -11
- package/src/utils/getDynamicLink/getDynamicLink.validate.ts +0 -6
- package/src/utils/getDynamicLink/index.ts +0 -2
package/.env.example
CHANGED
|
@@ -52,32 +52,6 @@ TLS_REQUEST_CA=
|
|
|
52
52
|
# Comma separated string
|
|
53
53
|
ALLOWED_CLIENT_HOSTS=
|
|
54
54
|
|
|
55
|
-
################
|
|
56
|
-
# User Service #
|
|
57
|
-
################
|
|
58
|
-
|
|
59
|
-
# URL where the user service is located
|
|
60
|
-
USER_SERVICE_URL=
|
|
61
|
-
|
|
62
|
-
# Path where the user service requests are made (default: /graph)
|
|
63
|
-
USER_SERVICE_PATH=
|
|
64
|
-
|
|
65
|
-
# Attributes of the users to fetch
|
|
66
|
-
# Comma separated list of attributes to fetch from the user Service
|
|
67
|
-
USER_FETCHED_ATTRIBUTES=id,regId,bbId
|
|
68
|
-
|
|
69
|
-
# Attributes of the connections to fetch
|
|
70
|
-
# Comma separated list of attributes to fetch from the user Service
|
|
71
|
-
IDENTITY_FETCHED_ATTRIBUTES=id,userId
|
|
72
|
-
|
|
73
|
-
# Attributes of the connections to fetch
|
|
74
|
-
# Comma separated list of attributes to fetch from the user Service
|
|
75
|
-
CONNECTION_FETCHED_ATTRIBUTES=id,ownerId,otherUserId
|
|
76
|
-
|
|
77
|
-
# Cache expiration
|
|
78
|
-
# Time in seconds before cache expiration (Default: 3600)
|
|
79
|
-
USER_SERVICE_CACHE_EXPIRATION=
|
|
80
|
-
|
|
81
55
|
########################
|
|
82
56
|
# Token Authentication #
|
|
83
57
|
########################
|
|
@@ -85,15 +59,9 @@ USER_SERVICE_CACHE_EXPIRATION=
|
|
|
85
59
|
# Audience requirement of the current service
|
|
86
60
|
ACCESS_TOKEN_AUDIENCE=
|
|
87
61
|
|
|
88
|
-
# Admin Api Audience requirement of the current service
|
|
89
|
-
ADMIN_API_ACCESS_TOKEN_AUDIENCE=
|
|
90
|
-
|
|
91
62
|
# URL of the authorization service, serves as an issuer requirement
|
|
92
63
|
AUTH_SERVICE_URL=
|
|
93
64
|
|
|
94
|
-
# URL of the Admin api, serves as an issuer requirement
|
|
95
|
-
ADMIN_API_PUBLIC_URL=
|
|
96
|
-
|
|
97
65
|
PRIVATE_KEY_PATH=
|
|
98
66
|
|
|
99
67
|
#########
|
|
@@ -150,9 +118,6 @@ PUBSUB_UPDATE_SUBSCRIPTION=
|
|
|
150
118
|
HASH_SECRET=
|
|
151
119
|
HASH_SALT=
|
|
152
120
|
|
|
153
|
-
#Base URL of the links service.
|
|
154
|
-
LINKS_SERVICE_URL=
|
|
155
|
-
|
|
156
121
|
#Base URL of the email service.
|
|
157
122
|
EMAIL_SERVICE_URL=
|
|
158
123
|
|
|
@@ -189,6 +154,3 @@ DB_MIGRATIONS_DIR=
|
|
|
189
154
|
|
|
190
155
|
# Default message Audience
|
|
191
156
|
DEFAULT_MESSAGE_AUDIENCE=
|
|
192
|
-
|
|
193
|
-
# Admin api public key path
|
|
194
|
-
ADMIN_API_ECDSA_PUBLIC_KEY=
|
package/.nycrc
CHANGED
|
@@ -11,8 +11,14 @@
|
|
|
11
11
|
"src/index.js"
|
|
12
12
|
],
|
|
13
13
|
"skip-full": true,
|
|
14
|
-
"sourceMap":
|
|
15
|
-
"instrument":
|
|
14
|
+
"sourceMap": true,
|
|
15
|
+
"instrument": true,
|
|
16
16
|
"require": ["@babel/register"],
|
|
17
|
-
"
|
|
17
|
+
"reporter": ["text", "html", "lcov"],
|
|
18
|
+
"lines": 85,
|
|
19
|
+
"branches": 80,
|
|
20
|
+
"functions": 85,
|
|
21
|
+
"statements": 85,
|
|
22
|
+
"report-dir": "./.test-coverage",
|
|
23
|
+
"temp-dir": "./.nyc_output"
|
|
18
24
|
}
|
package/README.md
CHANGED
|
@@ -197,8 +197,7 @@ The server engine exposes an enumeration for auth types.
|
|
|
197
197
|
| AuthType.JWT | A valid JSON Web Token is required as Bearer token. To be valid it must be properly signed by auth0, and its payload must match with what is set as environment variables.<br>The user's ID is added to `req.user`. | |
|
|
198
198
|
| AuthType.TLS | Authenticate through mutual TLS. CA and an optional list of white listed host names should be set in the environment variables. | **whitelist** [Array<String>]: List of certificate Common Name or Alt Name that are permitted to make requests to this endpoint. |
|
|
199
199
|
| AuthType.HMAC | Authenticate with a signature in the payload.<br>**This authentication is deprecated and should be avoided** | **secret** [String]: Overrides the secret used for signatures set in environment variables<br>**isGithub** [Boolean]: The request is a Github webhook and therefore uses their signature system and not the default one. |
|
|
200
|
-
| AuthType.STATIC | A valid shared Bearer token is required. Shared token is stored in env variable (STATIC_TOKEN) |
|
|
201
|
-
| AuthType.ADMIN | A valid JSON Web Token is required as Bearer token. To be valid it must be properly signed by admin api, and its payload must match with what is set as environment variables.<br>The user's email and permission is added to `req.user`. | **permission** [String]: Endpoint permission required for admin user |
|
|
200
|
+
| AuthType.STATIC | A valid shared Bearer token is required. Shared token is stored in env variable (STATIC_TOKEN) |
|
|
202
201
|
|
|
203
202
|
<!-- markdownlint-enable MD033 -->
|
|
204
203
|
|
|
@@ -524,7 +523,7 @@ These options are common to each of the error classes described below.
|
|
|
524
523
|
| -------- | ----------------------------------------------------------------------------------------------------------------------- | ------------------------------------- | ------------------------------ |
|
|
525
524
|
| message | A message logged on the backend only | "Could not find user in the DB" | **required** |
|
|
526
525
|
| severity | The level at which this error should be logged | [Severity](#severity).WARNING | [Severity](#severity).CRITICAL |
|
|
527
|
-
| data | Some data related to the error that will be logged on the backend. This should help to undetrstand the runtime context. | {userId: 'xf563ugh0'
|
|
526
|
+
| data | Some data related to the error that will be logged on the backend. This should help to undetrstand the runtime context. | {userId: 'xf563ugh0'} | |
|
|
528
527
|
| error | An error object, when this is a wrapper around an existing error object | |
|
|
529
528
|
|
|
530
529
|
#### Severity
|
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
/** Enum to identify access tokens JWT issuers */
|
|
2
2
|
export declare enum TokenIssuer {
|
|
3
3
|
/** For tokens issued by the auth service */
|
|
4
|
-
AUTH_SERVICE = 0
|
|
5
|
-
/** For tokens issued by the admin API */
|
|
6
|
-
ADMIN_API = 1
|
|
4
|
+
AUTH_SERVICE = 0
|
|
7
5
|
}
|
|
8
|
-
export declare const TOKEN_ISSUERS: (string | TokenIssuer)[];
|
|
6
|
+
export declare const TOKEN_ISSUERS: (string | TokenIssuer.AUTH_SERVICE)[];
|
|
@@ -7,7 +7,6 @@ exports.TokenIssuer = exports.TOKEN_ISSUERS = void 0;
|
|
|
7
7
|
/** Enum to identify access tokens JWT issuers */
|
|
8
8
|
let TokenIssuer = exports.TokenIssuer = /*#__PURE__*/function (TokenIssuer) {
|
|
9
9
|
TokenIssuer[TokenIssuer["AUTH_SERVICE"] = 0] = "AUTH_SERVICE";
|
|
10
|
-
TokenIssuer[TokenIssuer["ADMIN_API"] = 1] = "ADMIN_API";
|
|
11
10
|
return TokenIssuer;
|
|
12
11
|
}({});
|
|
13
12
|
const TOKEN_ISSUERS = exports.TOKEN_ISSUERS = Object.values(TokenIssuer);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tokenIssuer.js","names":["TokenIssuer","exports","TOKEN_ISSUERS","Object","values"],"sources":["../../src/const/tokenIssuer.ts"],"sourcesContent":["/** Enum to identify access tokens JWT issuers */\nexport enum TokenIssuer {\n /** For tokens issued by the auth service */\n AUTH_SERVICE
|
|
1
|
+
{"version":3,"file":"tokenIssuer.js","names":["TokenIssuer","exports","TOKEN_ISSUERS","Object","values"],"sources":["../../src/const/tokenIssuer.ts"],"sourcesContent":["/** Enum to identify access tokens JWT issuers */\nexport enum TokenIssuer {\n /** For tokens issued by the auth service */\n AUTH_SERVICE\n}\n\nexport const TOKEN_ISSUERS = Object.values(TokenIssuer);\n"],"mappings":";;;;;;AAAA;AAAA,IACYA,WAAW,GAAAC,OAAA,CAAAD,WAAA,0BAAXA,WAAW;EAAXA,WAAW,CAAXA,WAAW;EAAA,OAAXA,WAAW;AAAA;AAKhB,MAAME,aAAa,GAAAD,OAAA,CAAAC,aAAA,GAAGC,MAAM,CAACC,MAAM,CAACJ,WAAW,CAAC","ignoreList":[]}
|
|
@@ -2,7 +2,7 @@ import { ErrorRequestHandler, Request, Response, NextFunction, RequestHandler }
|
|
|
2
2
|
import { ParamsDictionary } from 'express-serve-static-core';
|
|
3
3
|
import { Schema } from 'express-validator';
|
|
4
4
|
import { ParsedQs } from 'qs';
|
|
5
|
-
import { authJwt, authHmac, authTls, authStatic,
|
|
5
|
+
import { authJwt, authHmac, authTls, authStatic, FileUploaderConfig } from '../../middleware';
|
|
6
6
|
export declare enum EndpointMethod {
|
|
7
7
|
GET = "get",
|
|
8
8
|
POST = "post",
|
|
@@ -18,17 +18,11 @@ export declare enum EndpointAuthType {
|
|
|
18
18
|
JWT = "jwt",
|
|
19
19
|
TLS = "tls",
|
|
20
20
|
HMAC = "hmac",
|
|
21
|
-
STATIC = "static"
|
|
22
|
-
ADMIN = "admin"
|
|
21
|
+
STATIC = "static"
|
|
23
22
|
}
|
|
24
23
|
export declare const EndpointAuthTypes: EndpointAuthType[];
|
|
25
24
|
export type Middleware<T extends EndpointAuthType> = (request: EndpointRequestType[T], response: Response, next: NextFunction) => unknown | Promise<unknown>;
|
|
26
25
|
export type MiddlewareChainElement<T extends EndpointAuthType> = Array<Middleware<T>> | Middleware<T> | any;
|
|
27
|
-
/** Auth related parameters used with Admin authentication */
|
|
28
|
-
interface EndpointAuthAdminParams {
|
|
29
|
-
/** [Admin] User permission required to use this endpoint */
|
|
30
|
-
permission: string;
|
|
31
|
-
}
|
|
32
26
|
/** Auth related parameters used with HMAC authentication */
|
|
33
27
|
interface EndpointAuthHmacParams {
|
|
34
28
|
/** [HMAC] Secret used for signature */
|
|
@@ -53,8 +47,6 @@ interface EndpointAuthSpecificParams {
|
|
|
53
47
|
[EndpointAuthType.HMAC]: EndpointAuthHmacParams;
|
|
54
48
|
/** Auth parameters for static authentication */
|
|
55
49
|
[EndpointAuthType.STATIC]: any;
|
|
56
|
-
/** Auth parameters for admin token authentication */
|
|
57
|
-
[EndpointAuthType.ADMIN]: EndpointAuthAdminParams;
|
|
58
50
|
}
|
|
59
51
|
export type EndpointAuthParams<T extends EndpointAuthType> = EndpointAuthSpecificParams[T] & {
|
|
60
52
|
/** This will allow the business logic to run event if the authentication fails */
|
|
@@ -72,8 +64,6 @@ export declare const EndpointAuthHandlers: {
|
|
|
72
64
|
hmac: typeof authHmac;
|
|
73
65
|
/** Auth handler for static authentication */
|
|
74
66
|
static: typeof authStatic;
|
|
75
|
-
/** Auth handler for admin token authentication */
|
|
76
|
-
admin: typeof authAdmin;
|
|
77
67
|
};
|
|
78
68
|
export type EndpointHandler<T extends EndpointAuthType> = (request: EndpointRequestType[T], response: Response) => void | Promise<void>;
|
|
79
69
|
/** Endpoint initialization options */
|
|
@@ -109,11 +99,6 @@ export interface TlsRequest<P = ParamsDictionary, ResBody = any, ReqBody = any,
|
|
|
109
99
|
/** Host names provided by the mTLS authenticated client */
|
|
110
100
|
hosts: Array<string>;
|
|
111
101
|
}
|
|
112
|
-
/** Request type when using HMAC authentication */
|
|
113
|
-
export interface AdminRequest<P = ParamsDictionary, ResBody = any, ReqBody = any, ReqQuery = ParsedQs, Locals extends Record<string, any> = Record<string, any>> extends Request<P, ResBody, ReqBody, ReqQuery, Locals> {
|
|
114
|
-
/** User that identified using a JWT */
|
|
115
|
-
admin: RequestAdminProps;
|
|
116
|
-
}
|
|
117
102
|
/** Mapping of request types in endpoints based on auth type used */
|
|
118
103
|
export interface EndpointRequestType {
|
|
119
104
|
/** Request type for no authentication */
|
|
@@ -126,8 +111,6 @@ export interface EndpointRequestType {
|
|
|
126
111
|
[EndpointAuthType.HMAC]: Request;
|
|
127
112
|
/** Auth handler for static authentication */
|
|
128
113
|
[EndpointAuthType.STATIC]: Request;
|
|
129
|
-
/** Auth handler for admin token authentication */
|
|
130
|
-
[EndpointAuthType.ADMIN]: AdminRequest;
|
|
131
114
|
}
|
|
132
115
|
export type SafeMiddleWareChain = Array<RequestHandler | ErrorRequestHandler | SafeMiddleWareChain>;
|
|
133
116
|
export {};
|
|
@@ -23,13 +23,10 @@ let EndpointAuthType = exports.EndpointAuthType = /*#__PURE__*/function (Endpoin
|
|
|
23
23
|
EndpointAuthType["TLS"] = "tls";
|
|
24
24
|
EndpointAuthType["HMAC"] = "hmac";
|
|
25
25
|
EndpointAuthType["STATIC"] = "static";
|
|
26
|
-
EndpointAuthType["ADMIN"] = "admin";
|
|
27
26
|
return EndpointAuthType;
|
|
28
27
|
}({});
|
|
29
28
|
const EndpointAuthTypes = exports.EndpointAuthTypes = Object.values(EndpointAuthType);
|
|
30
29
|
|
|
31
|
-
/** Auth related parameters used with Admin authentication */
|
|
32
|
-
|
|
33
30
|
/** Auth related parameters used with HMAC authentication */
|
|
34
31
|
|
|
35
32
|
/** Auth related parameters used with mTLS authentication */
|
|
@@ -46,9 +43,7 @@ const EndpointAuthHandlers = exports.EndpointAuthHandlers = {
|
|
|
46
43
|
/** Auth handler for HMAC authentication */
|
|
47
44
|
[EndpointAuthType.HMAC]: _middleware.authHmac,
|
|
48
45
|
/** Auth handler for static authentication */
|
|
49
|
-
[EndpointAuthType.STATIC]: _middleware.authStatic
|
|
50
|
-
/** Auth handler for admin token authentication */
|
|
51
|
-
[EndpointAuthType.ADMIN]: _middleware.authAdmin
|
|
46
|
+
[EndpointAuthType.STATIC]: _middleware.authStatic
|
|
52
47
|
};
|
|
53
48
|
|
|
54
49
|
/** Endpoint initialization options */
|
|
@@ -57,7 +52,5 @@ const EndpointAuthHandlers = exports.EndpointAuthHandlers = {
|
|
|
57
52
|
|
|
58
53
|
/** Request type when using mTLS authentication */
|
|
59
54
|
|
|
60
|
-
/** Request type when using HMAC authentication */
|
|
61
|
-
|
|
62
55
|
/** Mapping of request types in endpoints based on auth type used */
|
|
63
56
|
//# sourceMappingURL=Endpoint.types.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Endpoint.types.js","names":["_middleware","require","EndpointMethod","exports","EndpointMethods","Object","values","EndpointAuthType","EndpointAuthTypes","EndpointAuthHandlers","NONE","undefined","JWT","authJwt","TLS","authTls","HMAC","authHmac","STATIC","authStatic"
|
|
1
|
+
{"version":3,"file":"Endpoint.types.js","names":["_middleware","require","EndpointMethod","exports","EndpointMethods","Object","values","EndpointAuthType","EndpointAuthTypes","EndpointAuthHandlers","NONE","undefined","JWT","authJwt","TLS","authTls","HMAC","authHmac","STATIC","authStatic"],"sources":["../../../src/entities/Endpoint/Endpoint.types.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-explicit-any */\nimport {\n ErrorRequestHandler,\n Request,\n Response,\n NextFunction,\n RequestHandler\n} from 'express';\nimport { ParamsDictionary } from 'express-serve-static-core';\nimport { Schema } from 'express-validator';\nimport { ParsedQs } from 'qs';\n\nimport {\n authJwt,\n authHmac,\n authTls,\n authStatic,\n FileUploaderConfig\n} from 'middleware';\n\nexport enum EndpointMethod {\n GET = 'get',\n POST = 'post',\n PUT = 'put',\n PATCH = 'patch',\n DELETE = 'delete',\n HEAD = 'head',\n ALL = 'all'\n}\n\nexport const EndpointMethods = Object.values(EndpointMethod);\n\nexport enum EndpointAuthType {\n NONE = 'none',\n JWT = 'jwt',\n TLS = 'tls',\n HMAC = 'hmac',\n STATIC = 'static'\n}\n\nexport const EndpointAuthTypes = Object.values(EndpointAuthType);\n\nexport type Middleware<T extends EndpointAuthType> = (\n request: EndpointRequestType[T],\n response: Response,\n next: NextFunction\n) => unknown | Promise<unknown>;\n\nexport type MiddlewareChainElement<T extends EndpointAuthType> =\n | Array<Middleware<T>>\n | Middleware<T>\n | any;\n\n/** Auth related parameters used with HMAC authentication */\ninterface EndpointAuthHmacParams {\n /** [HMAC] Secret used for signature */\n secret?: string;\n /** [HMAC] For Github webhook, the standard differs slightly, so this option must be selected */\n isGithub?: boolean;\n}\n\n/** Auth related parameters used with mTLS authentication */\ninterface EndpointAuthTlsParams {\n /** [TLS] List oh hosts that are allowed to use the endpoint, this is compared to the claims in the certificate */\n whitelist?: Array<string>;\n}\n\n/** Mapping used to get auth specific parameters depending on the auth type used */\ninterface EndpointAuthSpecificParams {\n /** Auth parameters for no authentication */\n [EndpointAuthType.NONE]: any;\n /** Auth parameters for JWT authentication */\n [EndpointAuthType.JWT]: any;\n /** Auth parameters for mTLS authentication */\n [EndpointAuthType.TLS]: EndpointAuthTlsParams;\n /** Auth parameters for HMAC authentication */\n [EndpointAuthType.HMAC]: EndpointAuthHmacParams;\n /** Auth parameters for static authentication */\n [EndpointAuthType.STATIC]: any;\n}\n\nexport type EndpointAuthParams<T extends EndpointAuthType> =\n EndpointAuthSpecificParams[T] & {\n /** This will allow the business logic to run event if the authentication fails */\n acceptInvalid?: boolean;\n };\n\nexport type EndpointAuthHandler<T extends EndpointAuthType> = (\n options?: EndpointAuthParams<T>\n) => (\n request: Request,\n response: Response,\n next: NextFunction\n) => void | Promise<void>;\n\nexport const EndpointAuthHandlers = {\n /** Auth handler for no authentication */\n [EndpointAuthType.NONE]: undefined,\n /** Auth handler for JWT authentication */\n [EndpointAuthType.JWT]: authJwt,\n /** Auth handler for mTLS authentication */\n [EndpointAuthType.TLS]: authTls,\n /** Auth handler for HMAC authentication */\n [EndpointAuthType.HMAC]: authHmac,\n /** Auth handler for static authentication */\n [EndpointAuthType.STATIC]: authStatic\n};\n\nexport type EndpointHandler<T extends EndpointAuthType> = (\n request: EndpointRequestType[T],\n response: Response\n) => void | Promise<void>;\n\n/** Endpoint initialization options */\nexport interface EndpointOptions<T extends EndpointAuthType> {\n /** Path at which the endpoint is reachable */\n path: string;\n /** HTTP method of the endpoint */\n method: EndpointMethod;\n /** Function handling the endpoint's business logic */\n handler: EndpointHandler<T>;\n /** Validation schema that the request must pass before reaching the handler */\n validator: Schema;\n /** Authentication system required by this endpoint */\n authType: T;\n /** Authentication related options for this endpoint */\n authParams?: EndpointAuthParams<T>;\n /** @deprecated Setting to upload a file through this endpoint */\n file?: FileUploaderConfig;\n /** Settings to upload files through this endpoint (this will automatically switch the expected request to be a multipart) */\n files?: Array<FileUploaderConfig>;\n /** Express request handlers that should run on this endpoint before the business logic, they will run after the global middleware */\n middleware?: MiddlewareChainElement<T>;\n /** Express error handlers that should be registered for this endpoint. they will run before the global error handler */\n errorMiddleware?: ErrorRequestHandler | Array<ErrorRequestHandler>;\n}\n\n/** Request type when using JWT authentication */\nexport interface JwtRequest<\n P = ParamsDictionary,\n ResBody = any,\n ReqBody = any,\n ReqQuery = ParsedQs,\n Locals extends Record<string, any> = Record<string, any>\n> extends Request<P, ResBody, ReqBody, ReqQuery, Locals> {\n /** User that identified using a JWT */\n user: Record<string, any> | any;\n}\n\n/** Request type when using mTLS authentication */\nexport interface TlsRequest<\n P = ParamsDictionary,\n ResBody = any,\n ReqBody = any,\n ReqQuery = ParsedQs,\n Locals extends Record<string, any> = Record<string, any>\n> extends Request<P, ResBody, ReqBody, ReqQuery, Locals> {\n /** Host names provided by the mTLS authenticated client */\n hosts: Array<string>;\n}\n\n/** Mapping of request types in endpoints based on auth type used */\nexport interface EndpointRequestType {\n /** Request type for no authentication */\n [EndpointAuthType.NONE]: Request;\n /** Request type when using JWT authentication */\n [EndpointAuthType.JWT]: JwtRequest;\n /** Request type when using mTLS authentication */\n [EndpointAuthType.TLS]: TlsRequest;\n /** Request type when using HMAC authentication */\n [EndpointAuthType.HMAC]: Request;\n /** Auth handler for static authentication */\n [EndpointAuthType.STATIC]: Request;\n}\n\nexport type SafeMiddleWareChain = Array<\n RequestHandler | ErrorRequestHandler | SafeMiddleWareChain\n>;\n"],"mappings":";;;;;;AAYA,IAAAA,WAAA,GAAAC,OAAA;AAZA;AAAA,IAoBYC,cAAc,GAAAC,OAAA,CAAAD,cAAA,0BAAdA,cAAc;EAAdA,cAAc;EAAdA,cAAc;EAAdA,cAAc;EAAdA,cAAc;EAAdA,cAAc;EAAdA,cAAc;EAAdA,cAAc;EAAA,OAAdA,cAAc;AAAA;AAUnB,MAAME,eAAe,GAAAD,OAAA,CAAAC,eAAA,GAAGC,MAAM,CAACC,MAAM,CAACJ,cAAc,CAAC;AAAC,IAEjDK,gBAAgB,GAAAJ,OAAA,CAAAI,gBAAA,0BAAhBA,gBAAgB;EAAhBA,gBAAgB;EAAhBA,gBAAgB;EAAhBA,gBAAgB;EAAhBA,gBAAgB;EAAhBA,gBAAgB;EAAA,OAAhBA,gBAAgB;AAAA;AAQrB,MAAMC,iBAAiB,GAAAL,OAAA,CAAAK,iBAAA,GAAGH,MAAM,CAACC,MAAM,CAACC,gBAAgB,CAAC;;AAahE;;AAQA;;AAMA;;AA4BO,MAAME,oBAAoB,GAAAN,OAAA,CAAAM,oBAAA,GAAG;EAClC;EACA,CAACF,gBAAgB,CAACG,IAAI,GAAGC,SAAS;EAClC;EACA,CAACJ,gBAAgB,CAACK,GAAG,GAAGC,mBAAO;EAC/B;EACA,CAACN,gBAAgB,CAACO,GAAG,GAAGC,mBAAO;EAC/B;EACA,CAACR,gBAAgB,CAACS,IAAI,GAAGC,oBAAQ;EACjC;EACA,CAACV,gBAAgB,CAACW,MAAM,GAAGC;AAC7B,CAAC;;AAOD;;AAwBA;;AAYA;;AAYA","ignoreList":[]}
|
package/dist/middleware/index.js
CHANGED
|
@@ -157,17 +157,6 @@ Object.keys(_version).forEach(function (key) {
|
|
|
157
157
|
}
|
|
158
158
|
});
|
|
159
159
|
});
|
|
160
|
-
var _authAdmin = require("./authAdmin");
|
|
161
|
-
Object.keys(_authAdmin).forEach(function (key) {
|
|
162
|
-
if (key === "default" || key === "__esModule") return;
|
|
163
|
-
if (key in exports && exports[key] === _authAdmin[key]) return;
|
|
164
|
-
Object.defineProperty(exports, key, {
|
|
165
|
-
enumerable: true,
|
|
166
|
-
get: function () {
|
|
167
|
-
return _authAdmin[key];
|
|
168
|
-
}
|
|
169
|
-
});
|
|
170
|
-
});
|
|
171
160
|
var _geminiFileUploader = require("./geminiFileUploader");
|
|
172
161
|
Object.keys(_geminiFileUploader).forEach(function (key) {
|
|
173
162
|
if (key === "default" || key === "__esModule") return;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["_error","require","Object","keys","forEach","key","exports","defineProperty","enumerable","get","_healthCheck","_validate","_fourOhFour","_authJwt","_authHmac","_authStatic","_swaggerDocs","_authTls","_userResolver","_fileUploader","_metrics","_requestMetrics","_version","
|
|
1
|
+
{"version":3,"file":"index.js","names":["_error","require","Object","keys","forEach","key","exports","defineProperty","enumerable","get","_healthCheck","_validate","_fourOhFour","_authJwt","_authHmac","_authStatic","_swaggerDocs","_authTls","_userResolver","_fileUploader","_metrics","_requestMetrics","_version","_geminiFileUploader","_checkPermission"],"sources":["../../src/middleware/index.ts"],"sourcesContent":["export * from './error';\nexport * from './healthCheck';\nexport * from './validate';\nexport * from './fourOhFour';\nexport * from './authJwt';\nexport * from './authHmac';\nexport * from './authStatic';\nexport * from './swaggerDocs';\nexport * from './authTls';\nexport * from './userResolver';\nexport * from './fileUploader';\nexport * from './metrics';\nexport * from './requestMetrics';\nexport * from './version';\nexport * from './geminiFileUploader';\nexport * from './checkPermission';\n"],"mappings":";;;;;AAAA,IAAAA,MAAA,GAAAC,OAAA;AAAAC,MAAA,CAAAC,IAAA,CAAAH,MAAA,EAAAI,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAA,GAAA,IAAAC,OAAA,IAAAA,OAAA,CAAAD,GAAA,MAAAL,MAAA,CAAAK,GAAA;EAAAH,MAAA,CAAAK,cAAA,CAAAD,OAAA,EAAAD,GAAA;IAAAG,UAAA;IAAAC,GAAA,WAAAA,CAAA;MAAA,OAAAT,MAAA,CAAAK,GAAA;IAAA;EAAA;AAAA;AACA,IAAAK,YAAA,GAAAT,OAAA;AAAAC,MAAA,CAAAC,IAAA,CAAAO,YAAA,EAAAN,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAA,GAAA,IAAAC,OAAA,IAAAA,OAAA,CAAAD,GAAA,MAAAK,YAAA,CAAAL,GAAA;EAAAH,MAAA,CAAAK,cAAA,CAAAD,OAAA,EAAAD,GAAA;IAAAG,UAAA;IAAAC,GAAA,WAAAA,CAAA;MAAA,OAAAC,YAAA,CAAAL,GAAA;IAAA;EAAA;AAAA;AACA,IAAAM,SAAA,GAAAV,OAAA;AAAAC,MAAA,CAAAC,IAAA,CAAAQ,SAAA,EAAAP,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAA,GAAA,IAAAC,OAAA,IAAAA,OAAA,CAAAD,GAAA,MAAAM,SAAA,CAAAN,GAAA;EAAAH,MAAA,CAAAK,cAAA,CAAAD,OAAA,EAAAD,GAAA;IAAAG,UAAA;IAAAC,GAAA,WAAAA,CAAA;MAAA,OAAAE,SAAA,CAAAN,GAAA;IAAA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AAmB,QAAA,EAAAlB,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAA,GAAA,IAAAC,OAAA,IAAAA,OAAA,CAAAD,GAAA,MAAAiB,QAAA,CAAAjB,GAAA;EAAAH,MAAA,CAAAK,cAAA,CAAAD,OAAA,EAAAD,GAAA;IAAAG,UAAA;IAAAC,GAAA,WAAAA,CAAA;MAAA,OAAAa,QAAA,CAAAjB,GAAA;IAAA;EAAA;AAAA;AACA,IAAAkB,mBAAA,GAAAtB,OAAA;AAAAC,MAAA,CAAAC,IAAA,CAAAoB,mBAAA,EAAAnB,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAA,GAAA,IAAAC,OAAA,IAAAA,OAAA,CAAAD,GAAA,MAAAkB,mBAAA,CAAAlB,GAAA;EAAAH,MAAA,CAAAK,cAAA,CAAAD,OAAA,EAAAD,GAAA;IAAAG,UAAA;IAAAC,GAAA,WAAAA,CAAA;MAAA,OAAAc,mBAAA,CAAAlB,GAAA;IAAA;EAAA;AAAA;AACA,IAAAmB,gBAAA,GAAAvB,OAAA;AAAAC,MAAA,CAAAC,IAAA,CAAAqB,gBAAA,EAAApB,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAA,GAAA,IAAAC,OAAA,IAAAA,OAAA,CAAAD,GAAA,MAAAmB,gBAAA,CAAAnB,GAAA;EAAAH,MAAA,CAAAK,cAAA,CAAAD,OAAA,EAAAD,GAAA;IAAAG,UAAA;IAAAC,GAAA,WAAAA,CAAA;MAAA,OAAAe,gBAAA,CAAAnB,GAAA;IAAA;EAAA;AAAA","ignoreList":[]}
|
package/dist/utils/index.d.ts
CHANGED
package/dist/utils/index.js
CHANGED
|
@@ -157,17 +157,6 @@ Object.keys(_sendPush).forEach(function (key) {
|
|
|
157
157
|
}
|
|
158
158
|
});
|
|
159
159
|
});
|
|
160
|
-
var _getDynamicLink = require("./getDynamicLink");
|
|
161
|
-
Object.keys(_getDynamicLink).forEach(function (key) {
|
|
162
|
-
if (key === "default" || key === "__esModule") return;
|
|
163
|
-
if (key in exports && exports[key] === _getDynamicLink[key]) return;
|
|
164
|
-
Object.defineProperty(exports, key, {
|
|
165
|
-
enumerable: true,
|
|
166
|
-
get: function () {
|
|
167
|
-
return _getDynamicLink[key];
|
|
168
|
-
}
|
|
169
|
-
});
|
|
170
|
-
});
|
|
171
160
|
var _sendEmail = require("./sendEmail");
|
|
172
161
|
Object.keys(_sendEmail).forEach(function (key) {
|
|
173
162
|
if (key === "default" || key === "__esModule") return;
|
package/dist/utils/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["_report","require","Object","keys","forEach","key","exports","defineProperty","enumerable","get","_filter","_semverCompare","_dbMigration","_checkEnvironment","_envAssert","_createSortedObject","_jwt","_hmac","_createHttpServer","_request","_tlsConfig","_tlsRequest","_sendPush","
|
|
1
|
+
{"version":3,"file":"index.js","names":["_report","require","Object","keys","forEach","key","exports","defineProperty","enumerable","get","_filter","_semverCompare","_dbMigration","_checkEnvironment","_envAssert","_createSortedObject","_jwt","_hmac","_createHttpServer","_request","_tlsConfig","_tlsRequest","_sendPush","_sendEmail","_trimPathSlash"],"sources":["../../src/utils/index.ts"],"sourcesContent":["// general\nexport * from './report';\nexport * from './filter';\nexport * from './semverCompare';\nexport * from './dbMigration';\n\n// env\nexport * from './checkEnvironment';\nexport * from './envAssert';\n\n// auth\nexport * from './createSortedObject';\nexport * from './jwt';\nexport * from './hmac';\n\n// Networking\nexport * from './createHttpServer';\nexport * from './request';\nexport * from './tlsConfig';\nexport * from './tlsRequest';\nexport * from './sendPush';\nexport * from './sendEmail';\n\n// String manipulation\nexport * from './trimPathSlash';\n"],"mappings":";;;;;AACA,IAAAA,OAAA,GAAAC,OAAA;AAAAC,MAAA,CAAAC,IAAA,CAAAH,OAAA,EAAAI,OAAA,WAAAC,GAAA;EAAA,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AA;MAAA,OAAAa,SAAA,CAAAjB,GAAA;IAAA;EAAA;AAAA;AACA,IAAAkB,UAAA,GAAAtB,OAAA;AAAAC,MAAA,CAAAC,IAAA,CAAAoB,UAAA,EAAAnB,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAA,GAAA,IAAAC,OAAA,IAAAA,OAAA,CAAAD,GAAA,MAAAkB,UAAA,CAAAlB,GAAA;EAAAH,MAAA,CAAAK,cAAA,CAAAD,OAAA,EAAAD,GAAA;IAAAG,UAAA;IAAAC,GAAA,WAAAA,CAAA;MAAA,OAAAc,UAAA,CAAAlB,GAAA;IAAA;EAAA;AAAA;AAGA,IAAAmB,cAAA,GAAAvB,OAAA;AAAAC,MAAA,CAAAC,IAAA,CAAAqB,cAAA,EAAApB,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAA,GAAA,IAAAC,OAAA,IAAAA,OAAA,CAAAD,GAAA,MAAAmB,cAAA,CAAAnB,GAAA;EAAAH,MAAA,CAAAK,cAAA,CAAAD,OAAA,EAAAD,GAAA;IAAAG,UAAA;IAAAC,GAAA,WAAAA,CAAA;MAAA,OAAAe,cAAA,CAAAnB,GAAA;IAAA;EAAA;AAAA","ignoreList":[]}
|
package/dist/utils/jwt/jwt.d.ts
CHANGED
|
@@ -2,7 +2,6 @@ import { UserTokenPayload } from './jwt.types';
|
|
|
2
2
|
import { TokenIssuer } from '../../const';
|
|
3
3
|
import { KeySet } from '../../entities/KeySet';
|
|
4
4
|
export declare let keySet: KeySet | undefined;
|
|
5
|
-
export declare let adminKeySet: KeySet | undefined;
|
|
6
5
|
/** Initiate key fetching mechanism */
|
|
7
6
|
export declare function initKeySets(): Promise<void>;
|
|
8
7
|
/** Stop fetching keys regularly */
|
package/dist/utils/jwt/jwt.js
CHANGED
|
@@ -4,7 +4,6 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
|
|
|
4
4
|
Object.defineProperty(exports, "__esModule", {
|
|
5
5
|
value: true
|
|
6
6
|
});
|
|
7
|
-
exports.adminKeySet = void 0;
|
|
8
7
|
exports.generateJwtToken = generateJwtToken;
|
|
9
8
|
exports.initKeySets = initKeySets;
|
|
10
9
|
exports.jwtVerify = jwtVerify;
|
|
@@ -20,7 +19,6 @@ var _checkEnvironment = require("../checkEnvironment");
|
|
|
20
19
|
var _envAssert = require("../envAssert");
|
|
21
20
|
var _report = require("../report");
|
|
22
21
|
let keySet = exports.keySet = void 0;
|
|
23
|
-
let adminKeySet = exports.adminKeySet = void 0;
|
|
24
22
|
const namespace = 'engine:utils:jwt';
|
|
25
23
|
|
|
26
24
|
/** Initiate key fetching mechanism */
|
|
@@ -47,22 +45,12 @@ async function initKeySets() {
|
|
|
47
45
|
});
|
|
48
46
|
}
|
|
49
47
|
const promise = [keySet.init.bind(keySet)()];
|
|
50
|
-
|
|
51
|
-
// Load the key set for the admin api
|
|
52
|
-
if (!process.env.ADMIN_API_ECDSA_PUBLIC_KEY) throw new _EngineError.EngineError({
|
|
53
|
-
message: "Admin API's authentication JWT signing public key is not defined"
|
|
54
|
-
});
|
|
55
|
-
exports.adminKeySet = adminKeySet = new _KeySet.KeySet(process.env.ADMIN_API_ECDSA_PUBLIC_KEY, {
|
|
56
|
-
pem: true
|
|
57
|
-
});
|
|
58
|
-
promise.push(adminKeySet.init.bind(adminKeySet)());
|
|
59
48
|
await Promise.all(promise);
|
|
60
49
|
}
|
|
61
50
|
|
|
62
51
|
/** Stop fetching keys regularly */
|
|
63
52
|
function shutdownKeySets() {
|
|
64
53
|
if (keySet) keySet.shutdown.bind(keySet)();
|
|
65
|
-
if (adminKeySet) adminKeySet.shutdown.bind(adminKeySet)();
|
|
66
54
|
}
|
|
67
55
|
|
|
68
56
|
/** Get the JWT public key */
|
|
@@ -73,7 +61,7 @@ function jwtGetKey(header, callback) {
|
|
|
73
61
|
return;
|
|
74
62
|
}
|
|
75
63
|
// Check that KeySet has been initialized
|
|
76
|
-
if (!keySet
|
|
64
|
+
if (!keySet) {
|
|
77
65
|
callback(new _EngineError.EngineError({
|
|
78
66
|
message: 'KeySet has not been initialized'
|
|
79
67
|
}));
|
|
@@ -134,9 +122,7 @@ async function jwtVerify(token, issuer = _const.TokenIssuer.AUTH_SERVICE) {
|
|
|
134
122
|
}
|
|
135
123
|
(0, _checkEnvironment.assertEnvironment)({
|
|
136
124
|
ACCESS_TOKEN_AUDIENCE: _envAssert.envAssert.isString(),
|
|
137
|
-
ACCESS_TOKEN_ISSUER: _envAssert.envAssert.isString()
|
|
138
|
-
ADMIN_API_ACCESS_TOKEN_AUDIENCE: _envAssert.envAssert.isString(),
|
|
139
|
-
ADMIN_ACCESS_TOKEN_ISSUER: _envAssert.envAssert.isString()
|
|
125
|
+
ACCESS_TOKEN_ISSUER: _envAssert.envAssert.isString()
|
|
140
126
|
});
|
|
141
127
|
let options;
|
|
142
128
|
switch (issuer) {
|
|
@@ -147,13 +133,6 @@ async function jwtVerify(token, issuer = _const.TokenIssuer.AUTH_SERVICE) {
|
|
|
147
133
|
algorithms
|
|
148
134
|
};
|
|
149
135
|
break;
|
|
150
|
-
case _const.TokenIssuer.ADMIN_API:
|
|
151
|
-
options = {
|
|
152
|
-
audience: [process.env.ADMIN_API_ACCESS_TOKEN_AUDIENCE],
|
|
153
|
-
issuer: [process.env.ADMIN_ACCESS_TOKEN_ISSUER],
|
|
154
|
-
algorithms
|
|
155
|
-
};
|
|
156
|
-
break;
|
|
157
136
|
default:
|
|
158
137
|
throw new _EngineError.EngineError({
|
|
159
138
|
message: `Invalid token issuer specified "${issuer}"`
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"jwt.js","names":["_jsonwebtoken","require","_fs","_interopRequireDefault","_const","_EngineError","_KeySet","_WebError","_checkEnvironment","_envAssert","_report","keySet","exports","adminKeySet","namespace","initKeySets","process","env","CHART","ECDSA_PUBLIC_KEY","EngineError","message","KeySet","file","AUTH_SERVICE_URL","internal","promise","init","bind","ADMIN_API_ECDSA_PUBLIC_KEY","pem","push","Promise","all","shutdownKeySets","shutdown","jwtGetKey","header","callback","NODE_ENV","JWT_SECRET","kid","data","reportDebug","key","getKey","error","Error","WebError","statusCode","errorCode","jwtVerify","token","issuer","TokenIssuer","AUTH_SERVICE","algorithms","assertEnvironment","envAssert","isString","ACCESS_TOKEN_AUDIENCE","ACCESS_TOKEN_ISSUER","ADMIN_API_ACCESS_TOKEN_AUDIENCE","ADMIN_ACCESS_TOKEN_ISSUER","options","audience","ADMIN_API","resolve","reject","verify","result","undefined","generateJwtToken","user","signOptions","algorithm","expiresIn","keyid","Object","keys","getKeys","privateKey","fs","readFileSync","PRIVATE_KEY_PATH","sign"],"sources":["../../../src/utils/jwt/jwt.ts"],"sourcesContent":["import {\n verify,\n JwtHeader,\n SigningKeyCallback,\n Algorithm,\n VerifyOptions,\n sign\n} from 'jsonwebtoken';\nimport fs from 'fs';\nimport path from 'path';\nimport { UserTokenPayload } from './jwt.types';\nimport { TokenIssuer } from 'const';\nimport { EngineError } from 'entities/EngineError';\nimport { KeySet } from 'entities/KeySet';\nimport { WebError } from 'entities/WebError';\nimport { assertEnvironment } from 'utils/checkEnvironment';\nimport { envAssert } from 'utils/envAssert';\nimport { reportDebug } from 'utils/report';\n\nexport let keySet: KeySet | undefined;\nexport let adminKeySet: KeySet | undefined;\n\nconst namespace = 'engine:utils:jwt';\n\n/** Initiate key fetching mechanism */\nexport async function initKeySets(): Promise<void> {\n // Create the KeySet instance\n // The auth-service fetches its key from its disk and not from a network request\n // This prevents fetch failures the first time the auth-service is started\n if (process.env.CHART === 'auth-service') {\n if (!process.env.ECDSA_PUBLIC_KEY)\n throw new EngineError({\n message: 'Environment variable \"ECDSA_PUBLIC_KEY\" is not defined'\n });\n keySet = new KeySet(process.env.ECDSA_PUBLIC_KEY, { file: true });\n } else {\n if (process.env.AUTH_SERVICE_URL)\n keySet = new KeySet(\n `${process.env.AUTH_SERVICE_URL}/.well-known/jwks.json`,\n { internal: true }\n );\n else\n keySet = new KeySet(`./keys/jwks.json`, { internal: true, file: true });\n\n if (!keySet)\n throw new EngineError({\n message:\n 'Environment variable \"AUTH_SERVICE_URL\" is not defined or JWKS not found'\n });\n }\n const promise = [keySet.init.bind(keySet)()];\n\n // Load the key set for the admin api\n if (!process.env.ADMIN_API_ECDSA_PUBLIC_KEY)\n throw new EngineError({\n message:\n \"Admin API's authentication JWT signing public key is not defined\"\n });\n adminKeySet = new KeySet(process.env.ADMIN_API_ECDSA_PUBLIC_KEY, {\n pem: true\n });\n promise.push(adminKeySet.init.bind(adminKeySet)());\n\n await Promise.all(promise);\n}\n\n/** Stop fetching keys regularly */\nexport function shutdownKeySets(): void {\n if (keySet) keySet.shutdown.bind(keySet)();\n if (adminKeySet) adminKeySet.shutdown.bind(adminKeySet)();\n}\n\n/** Get the JWT public key */\nfunction jwtGetKey(header: JwtHeader, callback: SigningKeyCallback): void {\n // In test environment we return the symmetric signature secret\n if (process.env.NODE_ENV === 'test') {\n callback(null, process.env.JWT_SECRET);\n return;\n }\n // Check that KeySet has been initialized\n if (!keySet || !adminKeySet) {\n callback(new EngineError({ message: 'KeySet has not been initialized' }));\n return;\n }\n // Check that the token has a key ID\n if (!header.kid) {\n callback(\n new EngineError({\n message:\n 'Token has not key ID in header, impossible to match with known key',\n data: header\n })\n );\n return;\n }\n\n // In test environment we use a symmetrical secret bases signature\n if (process.env.NODE_ENV === 'test') {\n callback(null, process.env.JWT_SECRET);\n return;\n }\n reportDebug({\n namespace,\n message: `Looking for key with ID \"${header.kid}\"`\n });\n // Go through each key set to check if the token's key is in one of them\n let key;\n try {\n key = keySet.getKey(header.kid);\n } catch (error: Error | null | unknown) {\n callback(error instanceof Error ? error : null);\n return;\n }\n\n if (key) {\n reportDebug({ namespace, message: `Found key with ID \"${header.kid}\"` });\n callback(null, key);\n return;\n }\n callback(\n new WebError({\n statusCode: 401,\n errorCode: 'unauthorized',\n message: 'Could not find the tokens key in any key set',\n data: { kid: header.kid }\n })\n );\n}\n\n/** Verify an user Json Web Token */\nexport async function jwtVerify(\n token: string,\n issuer: TokenIssuer = TokenIssuer.AUTH_SERVICE\n): Promise<UserTokenPayload> {\n let algorithms = ['ES256' as Algorithm];\n if (process.env.NODE_ENV === 'test') {\n assertEnvironment({ JWT_SECRET: envAssert.isString() });\n algorithms = ['HS256' as Algorithm];\n }\n assertEnvironment({\n ACCESS_TOKEN_AUDIENCE: envAssert.isString(),\n ACCESS_TOKEN_ISSUER: envAssert.isString(),\n ADMIN_API_ACCESS_TOKEN_AUDIENCE: envAssert.isString(),\n ADMIN_ACCESS_TOKEN_ISSUER: envAssert.isString()\n });\n let options: VerifyOptions | undefined;\n\n switch (issuer) {\n case TokenIssuer.AUTH_SERVICE:\n options = {\n audience: [process.env.ACCESS_TOKEN_AUDIENCE as string],\n issuer: [process.env.ACCESS_TOKEN_ISSUER as string],\n algorithms\n };\n break;\n case TokenIssuer.ADMIN_API:\n options = {\n audience: [process.env.ADMIN_API_ACCESS_TOKEN_AUDIENCE as string],\n issuer: [process.env.ADMIN_ACCESS_TOKEN_ISSUER as string],\n algorithms\n };\n break;\n default:\n throw new EngineError({\n message: `Invalid token issuer specified \"${issuer as string}\"`\n });\n }\n\n return new Promise<UserTokenPayload>((resolve, reject) => {\n verify(token, jwtGetKey, options, (error, result) => {\n if (error) {\n reject(\n new WebError({\n errorCode: 'unauthorized',\n statusCode: 401,\n message: 'Invalid token supplied',\n data: { token },\n error: error instanceof Error ? error : undefined\n })\n );\n return;\n }\n resolve(result as UserTokenPayload);\n });\n });\n}\n\nexport function generateJwtToken(user: unknown) {\n const signOptions = {\n algorithm: 'ES256' as const, // or 'ES256' as Algorithm\n expiresIn: '1h',\n issuer: process.env.ACCESS_TOKEN_ISSUER,\n audience: process.env.ACCESS_TOKEN_AUDIENCE,\n keyid: Object.keys(keySet?.getKeys() ?? {})[0]\n };\n\n const privateKey = fs.readFileSync(\n process.env.PRIVATE_KEY_PATH ?? 'keys/private-key.pem',\n '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AU,EAAE,GAAG;UACf5B,OAAO,EAAE,wBAAwB;UACjCqB,IAAI,EAAE;YAAEU;UAAM,CAAC;UACfN,KAAK,EAAEA,KAAK,YAAYC,KAAK,GAAGD,KAAK,GAAGyB;QAC1C,CAAC,CACH,CAAC;QACD;MACF;MACAJ,OAAO,CAACG,MAA0B,CAAC;IACrC,CAAC,CAAC;EACJ,CAAC,CAAC;AACJ;AAEO,SAASE,gBAAgBA,CAACC,IAAa,EAAE;EAC9C,MAAMC,WAAW,GAAG;IAClBC,SAAS,EAAE,OAAgB;IAAE;IAC7BC,SAAS,EAAE,IAAI;IACfvB,MAAM,EAAErC,OAAO,CAACC,GAAG,CAAC4C,mBAAmB;IACvCI,QAAQ,EAAEjD,OAAO,CAACC,GAAG,CAAC2C,qBAAqB;IAC3CiB,KAAK,EAAEC,MAAM,CAACC,IAAI,CAACpE,MAAM,EAAEqE,OAAO,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC;EAC/C,CAAC;EAED,MAAMC,UAAU,GAAGC,WAAE,CAACC,YAAY,CAChCnE,OAAO,CAACC,GAAG,CAACmE,gBAAgB,IAAI,sBAAsB,EACtD,MACF,CAAC;EACD,MAAMhC,KAAK,GAAG,IAAAiC,kBAAI,EAAC;IAAEZ;EAAK,CAAC,EAAEQ,UAAU,EAAEP,WAAW,CAAC;EAErD,OAAOtB,KAAK;AACd","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"jwt.js","names":["_jsonwebtoken","require","_fs","_interopRequireDefault","_const","_EngineError","_KeySet","_WebError","_checkEnvironment","_envAssert","_report","keySet","exports","namespace","initKeySets","process","env","CHART","ECDSA_PUBLIC_KEY","EngineError","message","KeySet","file","AUTH_SERVICE_URL","internal","promise","init","bind","Promise","all","shutdownKeySets","shutdown","jwtGetKey","header","callback","NODE_ENV","JWT_SECRET","kid","data","reportDebug","key","getKey","error","Error","WebError","statusCode","errorCode","jwtVerify","token","issuer","TokenIssuer","AUTH_SERVICE","algorithms","assertEnvironment","envAssert","isString","ACCESS_TOKEN_AUDIENCE","ACCESS_TOKEN_ISSUER","options","audience","resolve","reject","verify","result","undefined","generateJwtToken","user","signOptions","algorithm","expiresIn","keyid","Object","keys","getKeys","privateKey","fs","readFileSync","PRIVATE_KEY_PATH","sign"],"sources":["../../../src/utils/jwt/jwt.ts"],"sourcesContent":["import {\n verify,\n JwtHeader,\n SigningKeyCallback,\n Algorithm,\n VerifyOptions,\n sign\n} from 'jsonwebtoken';\nimport fs from 'fs';\nimport { UserTokenPayload } from './jwt.types';\nimport { TokenIssuer } from 'const';\nimport { EngineError } from 'entities/EngineError';\nimport { KeySet } from 'entities/KeySet';\nimport { WebError } from 'entities/WebError';\nimport { assertEnvironment } from 'utils/checkEnvironment';\nimport { envAssert } from 'utils/envAssert';\nimport { reportDebug } from 'utils/report';\n\nexport let keySet: KeySet | undefined;\n\nconst namespace = 'engine:utils:jwt';\n\n/** Initiate key fetching mechanism */\nexport async function initKeySets(): Promise<void> {\n // Create the KeySet instance\n // The auth-service fetches its key from its disk and not from a network request\n // This prevents fetch failures the first time the auth-service is started\n if (process.env.CHART === 'auth-service') {\n if (!process.env.ECDSA_PUBLIC_KEY)\n throw new EngineError({\n message: 'Environment variable \"ECDSA_PUBLIC_KEY\" is not defined'\n });\n keySet = new KeySet(process.env.ECDSA_PUBLIC_KEY, { file: true });\n } else {\n if (process.env.AUTH_SERVICE_URL)\n keySet = new KeySet(\n `${process.env.AUTH_SERVICE_URL}/.well-known/jwks.json`,\n { internal: true }\n );\n else\n keySet = new KeySet(`./keys/jwks.json`, { internal: true, file: true });\n\n if (!keySet)\n throw new EngineError({\n message:\n 'Environment variable \"AUTH_SERVICE_URL\" is not defined or JWKS not found'\n });\n }\n const promise = [keySet.init.bind(keySet)()];\n\n await Promise.all(promise);\n}\n\n/** Stop fetching keys regularly */\nexport function shutdownKeySets(): void {\n if (keySet) keySet.shutdown.bind(keySet)();\n}\n\n/** Get the JWT public key */\nfunction jwtGetKey(header: JwtHeader, callback: SigningKeyCallback): void {\n // In test environment we return the symmetric signature secret\n if (process.env.NODE_ENV === 'test') {\n callback(null, process.env.JWT_SECRET);\n return;\n }\n // Check that KeySet has been initialized\n if (!keySet) {\n callback(new EngineError({ message: 'KeySet has not been initialized' }));\n return;\n }\n // Check that the token has a key ID\n if (!header.kid) {\n callback(\n new EngineError({\n message:\n 'Token has not key ID in header, impossible to match with known key',\n data: header\n })\n );\n return;\n }\n\n // In test environment we use a symmetrical secret bases signature\n if (process.env.NODE_ENV === 'test') {\n callback(null, process.env.JWT_SECRET);\n return;\n }\n reportDebug({\n namespace,\n message: `Looking for key with ID \"${header.kid}\"`\n });\n // Go through each key set to check if the token's key is in one of them\n let key;\n try {\n key = keySet.getKey(header.kid);\n } catch (error: Error | null | unknown) {\n callback(error instanceof Error ? error : null);\n return;\n }\n\n if (key) {\n reportDebug({ namespace, message: `Found key with ID \"${header.kid}\"` });\n callback(null, key);\n return;\n }\n callback(\n new WebError({\n statusCode: 401,\n errorCode: 'unauthorized',\n message: 'Could not find the tokens key in any key set',\n data: { kid: header.kid }\n })\n );\n}\n\n/** Verify an user Json Web Token */\nexport async function jwtVerify(\n token: string,\n issuer: TokenIssuer = TokenIssuer.AUTH_SERVICE\n): Promise<UserTokenPayload> {\n let algorithms = ['ES256' as Algorithm];\n if (process.env.NODE_ENV === 'test') {\n assertEnvironment({ JWT_SECRET: envAssert.isString() });\n algorithms = ['HS256' as Algorithm];\n }\n assertEnvironment({\n ACCESS_TOKEN_AUDIENCE: envAssert.isString(),\n ACCESS_TOKEN_ISSUER: envAssert.isString()\n });\n let options: VerifyOptions | undefined;\n\n switch (issuer) {\n case TokenIssuer.AUTH_SERVICE:\n options = {\n audience: [process.env.ACCESS_TOKEN_AUDIENCE as string],\n issuer: [process.env.ACCESS_TOKEN_ISSUER as string],\n algorithms\n };\n break;\n default:\n throw new EngineError({\n message: `Invalid token issuer specified \"${issuer as string}\"`\n });\n }\n\n return new Promise<UserTokenPayload>((resolve, reject) => {\n verify(token, jwtGetKey, options, (error, result) => {\n if (error) {\n reject(\n new WebError({\n errorCode: 'unauthorized',\n statusCode: 401,\n message: 'Invalid token supplied',\n data: { token },\n error: error instanceof Error ? error : undefined\n })\n );\n return;\n }\n resolve(result as UserTokenPayload);\n });\n });\n}\n\nexport function generateJwtToken(user: unknown) {\n const signOptions = {\n algorithm: 'ES256' as const, // or 'ES256' as Algorithm\n expiresIn: '1h',\n issuer: process.env.ACCESS_TOKEN_ISSUER,\n audience: process.env.ACCESS_TOKEN_AUDIENCE,\n keyid: Object.keys(keySet?.getKeys() ?? {})[0]\n };\n\n const privateKey = fs.readFileSync(\n process.env.PRIVATE_KEY_PATH ?? 'keys/private-key.pem',\n 'utf8'\n );\n const token = sign({ user }, privateKey, signOptions);\n\n return token;\n}\n"],"mappings":";;;;;;;;;;;AAAA,IAAAA,aAAA,GAAAC,OAAA;AAQA,IAAAC,GAAA,GAAAC,sBAAA,CAAAF,OAAA;AAEA,IAAAG,MAAA,GAAAH,OAAA;AACA,IAAAI,YAAA,GAAAJ,OAAA;AACA,IAAAK,OAAA,GAAAL,OAAA;AACA,IAAAM,SAAA,GAAAN,OAAA;AACA,IAAAO,iBAAA,GAAAP,OAAA;AACA,IAAAQ,UAAA,GAAAR,OAAA;AACA,IAAAS,OAAA,GAAAT,OAAA;AAEO,IAAIU,MAA0B,GAAAC,OAAA,CAAAD,MAAA;AAErC,MAAME,SAAS,GAAG,kBAAkB;;AAEpC;AACO,eAAeC,WAAWA,CAAA,EAAkB;EACjD;EACA;EACA;EACA,IAAIC,OAAO,CAACC,GAAG,CAACC,KAAK,KAAK,cAAc,EAAE;IACxC,IAAI,CAACF,OAAO,CAACC,GAAG,CAACE,gBAAgB,EAC/B,MAAM,IAAIC,wBAAW,CAAC;MACpBC,OAAO,EAAE;IACX,CAAC,CAAC;IACJR,OAAA,CAAAD,MAAA,GAAAA,MAAM,GAAG,IAAIU,cAAM,CAACN,OAAO,CAACC,GAAG,CAACE,gBAA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CAACC,GAAG,CAACyC,mBAAmB;IACvCE,QAAQ,EAAE5C,OAAO,CAACC,GAAG,CAACwC,qBAAqB;IAC3Cc,KAAK,EAAEC,MAAM,CAACC,IAAI,CAAC7D,MAAM,EAAE8D,OAAO,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC;EAC/C,CAAC;EAED,MAAMC,UAAU,GAAGC,WAAE,CAACC,YAAY,CAChC7D,OAAO,CAACC,GAAG,CAAC6D,gBAAgB,IAAI,sBAAsB,EACtD,MACF,CAAC;EACD,MAAM7B,KAAK,GAAG,IAAA8B,kBAAI,EAAC;IAAEZ;EAAK,CAAC,EAAEQ,UAAU,EAAEP,WAAW,CAAC;EAErD,OAAOnB,KAAK;AACd","ignoreList":[]}
|
|
@@ -15,7 +15,6 @@ var _WebError = require("../../entities/WebError");
|
|
|
15
15
|
require("../../middleware/authHmac/authHmac.types");
|
|
16
16
|
require("../../middleware/authJwt/authJwt.types");
|
|
17
17
|
require("../../middleware/authTls/authTls.types");
|
|
18
|
-
require("../../middleware/authAdmin/authAdmin.types");
|
|
19
18
|
/** Default generic logger */
|
|
20
19
|
function reportInfo(data) {
|
|
21
20
|
return (0, _output.output)({
|
|
@@ -57,7 +56,7 @@ function reportError(error, request) {
|
|
|
57
56
|
logEntry = {
|
|
58
57
|
...logEntry,
|
|
59
58
|
context: {
|
|
60
|
-
user: request.user?.id ?? request.hosts?.join(',')
|
|
59
|
+
user: request.user?.id ?? request.hosts?.join(','),
|
|
61
60
|
httpRequest: {
|
|
62
61
|
url: request.originalUrl,
|
|
63
62
|
method: request.method,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"report.js","names":["_output","require","_const","_EngineError","_WebError","reportInfo","data","output","severity","LogSeverity","INFO","message","reportError","error","request","logEntry","Error","stack_trace","stack","ERROR","CRITICAL","EngineError","errorType","constructor","name","WebError","statusCode","undefined","errorCode","context","user","id","hosts","join","
|
|
1
|
+
{"version":3,"file":"report.js","names":["_output","require","_const","_EngineError","_WebError","reportInfo","data","output","severity","LogSeverity","INFO","message","reportError","error","request","logEntry","Error","stack_trace","stack","ERROR","CRITICAL","EngineError","errorType","constructor","name","WebError","statusCode","undefined","errorCode","context","user","id","hosts","join","httpRequest","url","originalUrl","method","referrer","header","userAgent","remoteIp","ip","responseStatusCode","NAMESPACE_SELECTORS","exports","initNamespaceSelector","process","env","DEBUG","split","map","namespace","RegExp","replace","resetNamespaceSelector","debugNamespace","reportDebug","isEngineReport","startsWith","match","some","selector","test","spaces","prefix","length","setNameSpace","globalNamespace","clearNamespace"],"sources":["../../../src/utils/report/report.ts"],"sourcesContent":["import { Request } from 'express';\nimport { output } from './output';\nimport { LogEntry, FullLogEntry } from './output.types';\nimport { DebugLogEntry, InfoLogEntry } from './report.types';\nimport { LogSeverity } from 'const';\nimport { EngineError } from 'entities/EngineError';\nimport { WebError } from 'entities/WebError';\nimport {} from 'middleware/authHmac/authHmac.types';\nimport {} from 'middleware/authJwt/authJwt.types';\nimport {} from 'middleware/authTls/authTls.types';\n\n/** Default generic logger */\nexport function reportInfo(data: InfoLogEntry | string): FullLogEntry {\n return output({\n severity: LogSeverity.INFO,\n ...(typeof data === 'string' ? { message: data } : data)\n });\n}\n\n/** Error specific logger */\nexport function reportError(\n error: unknown | Error | EngineError | WebError,\n request?: Request\n): FullLogEntry {\n let logEntry: LogEntry =\n error instanceof Error\n ? {\n message: error.message,\n stack_trace: error.stack,\n severity: LogSeverity.ERROR\n }\n : {\n message: 'An unknown error occurred',\n data: error,\n severity: LogSeverity.CRITICAL\n };\n\n if (error instanceof EngineError) {\n logEntry = {\n ...logEntry,\n severity: error.severity,\n errorType: error.constructor.name,\n data: error.data,\n '@type':\n !(error instanceof WebError) || error.statusCode >= 500\n ? 'type.googleapis.com/google.devtools.clouderrorreporting.v1beta1.ReportedErrorEvent'\n : undefined\n };\n }\n\n if (error instanceof WebError) {\n logEntry = {\n ...logEntry,\n errorCode: error.errorCode,\n statusCode: error.statusCode\n };\n }\n\n if (request) {\n logEntry = {\n ...logEntry,\n context: {\n user:\n request.user?.id ?? request.hosts?.join(','),\n httpRequest: {\n url: request.originalUrl,\n method: request.method,\n referrer: request.header('Referer'),\n userAgent: request.header('User-Agent'),\n remoteIp: request.ip,\n responseStatusCode:\n error instanceof WebError ? error.statusCode : undefined\n }\n }\n };\n }\n\n return output(logEntry);\n}\n\nexport let NAMESPACE_SELECTORS: undefined | Array<RegExp>;\n\n/** Generate the namespace selectors based on the debug variable */\nfunction initNamespaceSelector(): void {\n if (process.env.DEBUG)\n NAMESPACE_SELECTORS = process.env.DEBUG.split(',').map(\n (namespace) => new RegExp('^' + namespace.replace(/\\*/g, '.*?') + '$')\n );\n}\n\n/** Reset the namespace selectors */\nexport function resetNamespaceSelector(): void {\n NAMESPACE_SELECTORS = undefined;\n}\n\nlet debugNamespace: string | undefined;\n\n/** Log a message for debugging purpose, based on a namespace specified in an environment variable */\nexport function reportDebug(data: DebugLogEntry): FullLogEntry | undefined {\n if (!NAMESPACE_SELECTORS) initNamespaceSelector();\n let { namespace } = data;\n const isEngineReport = namespace ? namespace.startsWith('engine') : false;\n\n if (debugNamespace && !isEngineReport) {\n namespace = debugNamespace + ':' + namespace;\n }\n\n const match =\n namespace &&\n NAMESPACE_SELECTORS &&\n NAMESPACE_SELECTORS.some((selector) => selector.test(namespace));\n if (!match) return;\n\n // Generate a prefix with the right most part of the namespace\n const spaces = namespace.split(':');\n const prefix = spaces[spaces.length - 1];\n\n return output({\n severity: LogSeverity.DEBUG,\n ...data,\n message: `[${prefix}] ${data.message}`\n });\n}\n\n/** Specify a global debugging namespace */\nreportDebug.setNameSpace = function (globalNamespace: string): void {\n debugNamespace = globalNamespace;\n};\n\n/** Remove any defined global namespace */\nreportDebug.clearNamespace = function (): void {\n debugNamespace = undefined;\n};\n"],"mappings":";;;;;;;;;;AACA,IAAAA,OAAA,GAAAC,OAAA;AAGA,IAAAC,MAAA,GAAAD,OAAA;AACA,IAAAE,YAAA,GAAAF,OA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