@node-c/api-http 1.0.0-alpha8 → 1.0.0-beta0
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/common/definitions/common.constants.d.ts +1 -1
- package/dist/common/definitions/common.constants.js +1 -1
- package/dist/common/definitions/common.constants.js.map +1 -1
- package/dist/common/utils/index.d.ts +1 -0
- package/dist/{exceptionFilters → common/utils}/index.js +1 -1
- package/dist/common/utils/index.js.map +1 -0
- package/dist/common/utils/utils.checkRoutes.d.ts +1 -0
- package/dist/common/utils/utils.checkRoutes.js +27 -0
- package/dist/common/utils/utils.checkRoutes.js.map +1 -0
- package/dist/{exceptionFilters/http.exceptionFilters.httpException.js → filters/http.filtes.exception.js} +1 -1
- package/dist/filters/http.filtes.exception.js.map +1 -0
- package/dist/filters/index.d.ts +1 -0
- package/dist/filters/index.js +18 -0
- package/dist/filters/index.js.map +1 -0
- package/dist/guards/http.guards.accessControl.d.ts +2 -0
- package/dist/guards/http.guards.accessControl.js +18 -0
- package/dist/guards/http.guards.accessControl.js.map +1 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/interceptors/{http.interceptors.authorization.d.ts → http.interceptors.accessControl.d.ts} +2 -2
- package/dist/interceptors/{http.interceptors.authorization.js → http.interceptors.accessControl.js} +21 -28
- package/dist/interceptors/http.interceptors.accessControl.js.map +1 -0
- package/dist/interceptors/http.interceptors.error.d.ts +1 -1
- package/dist/interceptors/http.interceptors.error.js +8 -2
- package/dist/interceptors/http.interceptors.error.js.map +1 -1
- package/dist/interceptors/index.d.ts +1 -1
- package/dist/interceptors/index.js +1 -1
- package/dist/middlewares/http.middlewares.authorization.d.ts +14 -0
- package/dist/middlewares/{http.middlewares.authentication.js → http.middlewares.authorization.js} +71 -45
- package/dist/middlewares/http.middlewares.authorization.js.map +1 -0
- package/dist/middlewares/http.middlewares.cors.js +1 -1
- package/dist/middlewares/http.middlewares.cors.js.map +1 -1
- package/dist/middlewares/index.d.ts +1 -1
- package/dist/middlewares/index.js +1 -1
- package/dist/middlewares/index.js.map +1 -1
- package/dist/module/http.api.module.js +18 -7
- package/dist/module/http.api.module.js.map +1 -1
- package/package.json +11 -7
- package/src/common/definitions/common.constants.ts +1 -1
- package/src/common/utils/index.ts +1 -0
- package/src/common/utils/utils.checkRoutes.ts +31 -0
- package/src/{exceptionFilters/http.exceptionFilters.httpException.ts → filters/http.filtes.exception.ts} +0 -5
- package/src/filters/index.ts +1 -0
- package/src/guards/http.guards.accessControl.ts +13 -0
- package/src/index.ts +1 -1
- package/src/interceptors/http.interceptors.accessControl.ts +94 -0
- package/src/interceptors/http.interceptors.error.ts +9 -4
- package/src/interceptors/index.ts +1 -1
- package/src/middlewares/http.middlewares.authorization.ts +153 -0
- package/src/middlewares/http.middlewares.cors.ts +1 -1
- package/src/middlewares/index.ts +1 -1
- package/src/module/http.api.module.ts +20 -6
- package/dist/exceptionFilters/http.exceptionFilters.httpException.js.map +0 -1
- package/dist/exceptionFilters/index.d.ts +0 -1
- package/dist/exceptionFilters/index.js.map +0 -1
- package/dist/interceptors/http.interceptors.authorization.js.map +0 -1
- package/dist/middlewares/http.middlewares.authentication.d.ts +0 -13
- package/dist/middlewares/http.middlewares.authentication.js.map +0 -1
- package/src/exceptionFilters/index.ts +0 -1
- package/src/interceptors/http.interceptors.authorization.ts +0 -82
- package/src/middlewares/http.middlewares.authentication.ts +0 -111
- /package/dist/{exceptionFilters/http.exceptionFilters.httpException.d.ts → filters/http.filtes.exception.d.ts} +0 -0
|
@@ -18,11 +18,13 @@ var HTTPAPIModule_1;
|
|
|
18
18
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
19
19
|
exports.HTTPAPIModule = void 0;
|
|
20
20
|
const common_1 = require("@nestjs/common");
|
|
21
|
-
const core_1 = require("@
|
|
21
|
+
const core_1 = require("@nestjs/core");
|
|
22
|
+
const core_2 = require("@node-c/core");
|
|
22
23
|
const cookie_parser_1 = __importDefault(require("cookie-parser"));
|
|
23
24
|
const express_1 = __importDefault(require("express"));
|
|
25
|
+
const morgan_1 = __importDefault(require("morgan"));
|
|
24
26
|
const definitions_1 = require("../common/definitions");
|
|
25
|
-
const
|
|
27
|
+
const filters_1 = require("../filters");
|
|
26
28
|
const interceptors_1 = require("../interceptors");
|
|
27
29
|
const middlewares_1 = require("../middlewares");
|
|
28
30
|
let HTTPAPIModule = HTTPAPIModule_1 = class HTTPAPIModule {
|
|
@@ -34,8 +36,11 @@ let HTTPAPIModule = HTTPAPIModule_1 = class HTTPAPIModule {
|
|
|
34
36
|
consumer.apply(express_1.default.urlencoded({ verify: HTTPAPIModule_1.rawBodyBuffer, extended: true })).forRoutes('*');
|
|
35
37
|
consumer.apply(express_1.default.json({ verify: HTTPAPIModule_1.rawBodyBuffer })).forRoutes('*');
|
|
36
38
|
consumer.apply((0, cookie_parser_1.default)()).forRoutes('*');
|
|
39
|
+
consumer
|
|
40
|
+
.apply((0, morgan_1.default)(`[${this.moduleName}]: :method :url :status :res[content-length] - :response-time ms`))
|
|
41
|
+
.forRoutes('*');
|
|
37
42
|
consumer.apply(middlewares_1.HTTPCORSMiddleware).forRoutes('*');
|
|
38
|
-
consumer.apply(middlewares_1.
|
|
43
|
+
consumer.apply(middlewares_1.HTTPAuthorizationMiddleware).forRoutes('*');
|
|
39
44
|
}
|
|
40
45
|
static rawBodyBuffer(req, _res, buffer) {
|
|
41
46
|
if (buffer && buffer.length) {
|
|
@@ -45,18 +50,24 @@ let HTTPAPIModule = HTTPAPIModule_1 = class HTTPAPIModule {
|
|
|
45
50
|
static register(options) {
|
|
46
51
|
const { folderData, imports: additionalImports, moduleClass } = options;
|
|
47
52
|
const { atEnd: importsAtEnd, atStart: importsAtStart } = additionalImports || {};
|
|
48
|
-
const { controllers, services } = (0,
|
|
53
|
+
const { controllers, services } = (0, core_2.loadDynamicModules)(folderData);
|
|
49
54
|
return {
|
|
50
55
|
module: moduleClass,
|
|
51
56
|
imports: [...(importsAtStart || []), ...(importsAtEnd || [])],
|
|
52
57
|
providers: [
|
|
58
|
+
{
|
|
59
|
+
provide: core_1.APP_PIPE,
|
|
60
|
+
useValue: new common_1.ValidationPipe({
|
|
61
|
+
whitelist: true
|
|
62
|
+
})
|
|
63
|
+
},
|
|
53
64
|
{
|
|
54
65
|
provide: definitions_1.Constants.API_MODULE_NAME,
|
|
55
66
|
useValue: options.moduleName
|
|
56
67
|
},
|
|
57
68
|
{
|
|
58
69
|
provide: definitions_1.Constants.AUTHORIZATION_INTERCEPTOR,
|
|
59
|
-
useClass: interceptors_1.
|
|
70
|
+
useClass: interceptors_1.HTTPAccessControlInterceptor
|
|
60
71
|
},
|
|
61
72
|
{
|
|
62
73
|
provide: definitions_1.Constants.ERROR_INTERCEPTOR,
|
|
@@ -64,7 +75,7 @@ let HTTPAPIModule = HTTPAPIModule_1 = class HTTPAPIModule {
|
|
|
64
75
|
},
|
|
65
76
|
{
|
|
66
77
|
provide: definitions_1.Constants.HTTP_EXCEPTION_FILTER,
|
|
67
|
-
useClass:
|
|
78
|
+
useClass: filters_1.HttpExceptionFilter
|
|
68
79
|
},
|
|
69
80
|
...(options.providers || []),
|
|
70
81
|
...(services || [])
|
|
@@ -77,6 +88,6 @@ let HTTPAPIModule = HTTPAPIModule_1 = class HTTPAPIModule {
|
|
|
77
88
|
exports.HTTPAPIModule = HTTPAPIModule;
|
|
78
89
|
exports.HTTPAPIModule = HTTPAPIModule = HTTPAPIModule_1 = __decorate([
|
|
79
90
|
__param(1, (0, common_1.Inject)(definitions_1.Constants.API_MODULE_NAME)),
|
|
80
|
-
__metadata("design:paramtypes", [
|
|
91
|
+
__metadata("design:paramtypes", [core_2.ConfigProviderService, String])
|
|
81
92
|
], HTTPAPIModule);
|
|
82
93
|
//# sourceMappingURL=http.api.module.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"http.api.module.js","sourceRoot":"","sources":["../../src/module/http.api.module.ts"],"names":[],"mappings":";;;;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EAAE,CAAC,EAAE,GAAG,CAAC,OAAO,CAAC,WAAW,IAAI,EAAE,CAAC,CAA6C;YACjH,OAAO,EAAE,CAAC,GAAG,CAAC,QAAQ,IAAI,EAAE,CAAC,EAAE,GAAG,CAAC,OAAO,CAAC,OAAO,IAAI,EAAE,CAAC,CAAC;SAC3D,CAAC;IACJ,CAAC;CACF,CAAA;AAlEY,sCAAa;wBAAb,aAAa;IAIrB,WAAA,IAAA,eAAM,EAAC,uBAAS,CAAC,eAAe,CAAC,CAAA;qCADR,4BAAqB;GAHtC,aAAa,CAkEzB"}
|
package/package.json
CHANGED
|
@@ -1,29 +1,33 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@node-c/api-http",
|
|
3
|
-
"version": "1.0.0-
|
|
3
|
+
"version": "1.0.0-beta0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"scripts": {
|
|
7
7
|
"build": "tsc -p tsconfig.build.json",
|
|
8
|
+
"build:clean": "rm -rf dist/* && rm -f *.tsbuildinfo && npm run build",
|
|
8
9
|
"check-types": "tsc -p tsconfig.build.json --noEmit",
|
|
9
10
|
"dev": "tsc -p tsconfig.build.json --watch",
|
|
10
|
-
"
|
|
11
|
+
"lint": "eslint src",
|
|
12
|
+
"publish-package": "npm run build:clean && npm publish --access public",
|
|
11
13
|
"test": "vitest --config src/vitest.config.ts",
|
|
12
14
|
"test:coverage": "vitest --config src/vitest.config.ts --coverage"
|
|
13
15
|
},
|
|
14
16
|
"dependencies": {
|
|
15
|
-
"@nestjs/common": "^
|
|
16
|
-
"@
|
|
17
|
+
"@nestjs/common": "^11.1.16",
|
|
18
|
+
"@nestjs/platform-express": "^11.1.16",
|
|
17
19
|
"cookie-parser": "^1.4.7",
|
|
18
20
|
"express": "^4.21.2",
|
|
21
|
+
"lodash": "^4.17.21",
|
|
19
22
|
"rxjs": "^7.8.1"
|
|
20
23
|
},
|
|
21
24
|
"devDependencies": {
|
|
22
25
|
"@types/cookie-parser": "^1.4.8",
|
|
23
|
-
"@types/express": "^5.0.0"
|
|
26
|
+
"@types/express": "^5.0.0",
|
|
27
|
+
"@types/lodash": "^4.17.19"
|
|
24
28
|
},
|
|
25
29
|
"peerDependencies": {
|
|
26
|
-
"@node-c/core": "^1.0.0-
|
|
27
|
-
"@node-c/domain-iam": "^1.0.0-
|
|
30
|
+
"@node-c/core": "^1.0.0-beta0",
|
|
31
|
+
"@node-c/domain-iam": "^1.0.0-beta0"
|
|
28
32
|
}
|
|
29
33
|
}
|
|
@@ -4,7 +4,7 @@ export enum Constants {
|
|
|
4
4
|
// eslint-disable-next-line no-unused-vars
|
|
5
5
|
API_MODULE_NAME = 'API_MODULE_NAME',
|
|
6
6
|
// eslint-disable-next-line no-unused-vars
|
|
7
|
-
|
|
7
|
+
AUTHORIZATION_MIDDLEWARE_TOKEN_MANAGER_SERVICE = 'AUTHORIZATION_MIDDLEWARE_TOKEN_MANAGER_SERVICE',
|
|
8
8
|
// eslint-disable-next-line no-unused-vars
|
|
9
9
|
AUTHENTICATION_MIDDLEWARE_USERS_SERVICE = 'AUTHENTICATION_MIDDLEWARE_USERS_SERVICE',
|
|
10
10
|
// eslint-disable-next-line no-unused-vars
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './utils.checkRoutes';
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Checks whether a route exists in a list of HTTP routes. Supports ExpressJS-style route parameters, i.e. /users/item/:id.
|
|
3
|
+
* @param route (required) - The route to be checked.
|
|
4
|
+
* @param routes (required) - The array of routes to check in.
|
|
5
|
+
* @returns A boolean, which is the result of the check.
|
|
6
|
+
*/
|
|
7
|
+
export function checkRoutes(route: string, routes: string[]): boolean {
|
|
8
|
+
const splitRoute = route.split('/');
|
|
9
|
+
for (const i in routes) {
|
|
10
|
+
const item = routes[i],
|
|
11
|
+
splitItem = item.split('/');
|
|
12
|
+
if (item === '*' || route === item) {
|
|
13
|
+
return true;
|
|
14
|
+
}
|
|
15
|
+
if (item.indexOf(':') !== -1 && splitItem.length === splitRoute.length) {
|
|
16
|
+
let valid = true;
|
|
17
|
+
for (const j in splitItem) {
|
|
18
|
+
const innerItem = splitItem[j],
|
|
19
|
+
routeItem = splitRoute[j];
|
|
20
|
+
if (routeItem !== innerItem && innerItem.indexOf(':') === -1) {
|
|
21
|
+
valid = false;
|
|
22
|
+
break;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
if (valid) {
|
|
26
|
+
return true;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
return false;
|
|
31
|
+
}
|
|
@@ -8,11 +8,6 @@ export class HttpExceptionFilter implements ExceptionFilter {
|
|
|
8
8
|
const ctx = host.switchToHttp();
|
|
9
9
|
const response = ctx.getResponse<Response>();
|
|
10
10
|
const status = exception.getStatus();
|
|
11
|
-
// else if (error instanceof BadRequestException) {
|
|
12
|
-
// const { statusCode, message: errorText } = error.getResponse() as unknown
|
|
13
|
-
// status = statusCode
|
|
14
|
-
// message = errorText || message
|
|
15
|
-
// }
|
|
16
11
|
response.status(status).json({
|
|
17
12
|
statusCode: status,
|
|
18
13
|
message: exception.message
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './http.filtes.exception';
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export const AccessControlContext = (moduleName: string, resourceContext: string) => {
|
|
2
|
+
console.log(moduleName, resourceContext);
|
|
3
|
+
return (target: object, propertyKey: string): void => {
|
|
4
|
+
console.log(target, propertyKey);
|
|
5
|
+
};
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
export const AccessControlResource = (resource: string) => {
|
|
9
|
+
console.log(resource);
|
|
10
|
+
return (target: object, propertyKey: string): void => {
|
|
11
|
+
console.log(target, propertyKey);
|
|
12
|
+
};
|
|
13
|
+
};
|
package/src/index.ts
CHANGED
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import {
|
|
2
|
+
CallHandler,
|
|
3
|
+
ExecutionContext,
|
|
4
|
+
HttpException,
|
|
5
|
+
HttpStatus,
|
|
6
|
+
Inject,
|
|
7
|
+
Injectable,
|
|
8
|
+
NestInterceptor
|
|
9
|
+
} from '@nestjs/common';
|
|
10
|
+
|
|
11
|
+
import { ConfigProviderService, GenericObject, setNested } from '@node-c/core';
|
|
12
|
+
import { AuthorizationPoint, IAMAuthorizationService, IAMUserManagerUserWithPermissionsData } from '@node-c/domain-iam';
|
|
13
|
+
|
|
14
|
+
import { Observable, map } from 'rxjs';
|
|
15
|
+
|
|
16
|
+
import { Constants, RequestWithLocals } from '../common/definitions';
|
|
17
|
+
|
|
18
|
+
/*
|
|
19
|
+
* Authorization interceptor - used for role-based and fine-grained access control.
|
|
20
|
+
*/
|
|
21
|
+
@Injectable()
|
|
22
|
+
export class HTTPAccessControlInterceptor<User extends IAMUserManagerUserWithPermissionsData<unknown, unknown>>
|
|
23
|
+
implements NestInterceptor
|
|
24
|
+
{
|
|
25
|
+
constructor(
|
|
26
|
+
@Inject(Constants.API_MODULE_AUTHORIZATION_SERVICE)
|
|
27
|
+
// eslint-disable-next-line no-unused-vars
|
|
28
|
+
protected authorizationService: IAMAuthorizationService<AuthorizationPoint<unknown>>,
|
|
29
|
+
// eslint-disable-next-line no-unused-vars
|
|
30
|
+
protected configProvider: ConfigProviderService,
|
|
31
|
+
@Inject(Constants.API_MODULE_NAME)
|
|
32
|
+
// eslint-disable-next-line no-unused-vars
|
|
33
|
+
protected moduleName: string
|
|
34
|
+
) {}
|
|
35
|
+
|
|
36
|
+
async intercept(context: ExecutionContext, next: CallHandler): Promise<Observable<unknown>> {
|
|
37
|
+
const [req]: [RequestWithLocals<User>, unknown] = context.getArgs();
|
|
38
|
+
const locals = req.locals!;
|
|
39
|
+
if (!locals) {
|
|
40
|
+
throw new HttpException('Forbidden', HttpStatus.FORBIDDEN);
|
|
41
|
+
} else if (locals.isAnonymous) {
|
|
42
|
+
return next.handle();
|
|
43
|
+
}
|
|
44
|
+
const { moduleName } = this;
|
|
45
|
+
const controllerName = context.getClass().name;
|
|
46
|
+
const handlerName = context.getHandler().name;
|
|
47
|
+
const user = locals.user!; // we'll always have this, otherwise the system has not been configured properly
|
|
48
|
+
const {
|
|
49
|
+
authorizationPoints: usedAuthorizationPoints,
|
|
50
|
+
errorCode,
|
|
51
|
+
hasAccess,
|
|
52
|
+
inputDataToBeMutated
|
|
53
|
+
} = IAMAuthorizationService.checkAccess(
|
|
54
|
+
{ body: req.body, headers: req.headers, params: req.params, query: req.query },
|
|
55
|
+
user,
|
|
56
|
+
{ moduleName, resource: handlerName, resourceContext: controllerName }
|
|
57
|
+
);
|
|
58
|
+
if (!hasAccess) {
|
|
59
|
+
// TODO; restore this if it's actually needed
|
|
60
|
+
// const { endpointSecurityMode } = this.configProvider.config.api[moduleName];
|
|
61
|
+
// if (noMatchForResource && ) {
|
|
62
|
+
// }
|
|
63
|
+
// if (!endpointSecurityMode || endpointSecurityMode === EndpointSecurityMode.Strict) {
|
|
64
|
+
// console.info(
|
|
65
|
+
// `[${moduleName}][HTTPAccessControlInterceptor]: No authorization point data for handler ${controllerName}.${handlerName}.`
|
|
66
|
+
// );
|
|
67
|
+
// throw new HttpException('Forbidden', HttpStatus.FORBIDDEN);
|
|
68
|
+
// }
|
|
69
|
+
console.error(
|
|
70
|
+
`[${moduleName}][HTTPAccessControlInterceptor]: No user access to handler ${controllerName}.${handlerName} - ${errorCode}.`
|
|
71
|
+
);
|
|
72
|
+
throw new HttpException('Forbidden', HttpStatus.FORBIDDEN);
|
|
73
|
+
}
|
|
74
|
+
for (const key in inputDataToBeMutated) {
|
|
75
|
+
setNested(req, key, inputDataToBeMutated[key], { removeNestedFieldEscapeSign: true });
|
|
76
|
+
}
|
|
77
|
+
return next.handle().pipe(
|
|
78
|
+
map((data?: unknown) => {
|
|
79
|
+
if (typeof data === 'undefined' || data === null || typeof data !== 'object' || data instanceof Date) {
|
|
80
|
+
return data;
|
|
81
|
+
}
|
|
82
|
+
const actualData = data as GenericObject;
|
|
83
|
+
const { outputDataToBeMutated } = IAMAuthorizationService.processOutputData(
|
|
84
|
+
usedAuthorizationPoints,
|
|
85
|
+
actualData
|
|
86
|
+
);
|
|
87
|
+
for (const key in outputDataToBeMutated) {
|
|
88
|
+
setNested(actualData, key, outputDataToBeMutated[key]);
|
|
89
|
+
}
|
|
90
|
+
return actualData;
|
|
91
|
+
})
|
|
92
|
+
);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { CallHandler, ExecutionContext,
|
|
1
|
+
import { CallHandler, ExecutionContext, Injectable, NestInterceptor } from '@nestjs/common';
|
|
2
2
|
|
|
3
3
|
import { ApplicationError } from '@node-c/core';
|
|
4
4
|
|
|
@@ -9,11 +9,11 @@ import { ServerError } from '../common/definitions/common.errors';
|
|
|
9
9
|
|
|
10
10
|
@Injectable()
|
|
11
11
|
export class HTTPErrorInterceptor implements NestInterceptor {
|
|
12
|
-
intercept(
|
|
12
|
+
intercept(context: ExecutionContext, next: CallHandler): Observable<unknown> {
|
|
13
13
|
return next.handle().pipe(
|
|
14
14
|
catchError(error => {
|
|
15
15
|
console.error(error);
|
|
16
|
-
let message = 'An error has occurred.';
|
|
16
|
+
let message: string | string[] = 'An error has occurred.';
|
|
17
17
|
let status = 500;
|
|
18
18
|
if (error instanceof ApplicationError || error instanceof ServerError) {
|
|
19
19
|
if (error.message) {
|
|
@@ -43,7 +43,12 @@ export class HTTPErrorInterceptor implements NestInterceptor {
|
|
|
43
43
|
message = error.message;
|
|
44
44
|
}
|
|
45
45
|
}
|
|
46
|
-
|
|
46
|
+
context
|
|
47
|
+
.switchToHttp()
|
|
48
|
+
.getResponse()
|
|
49
|
+
.status(status)
|
|
50
|
+
.json({ error: message instanceof Array ? message.join('\n') : message });
|
|
51
|
+
return new Observable();
|
|
47
52
|
})
|
|
48
53
|
);
|
|
49
54
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export * from './http.interceptors.
|
|
1
|
+
export * from './http.interceptors.accessControl';
|
|
2
2
|
export * from './http.interceptors.error';
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
import { HttpException, HttpStatus, Inject, Injectable, NestMiddleware } from '@nestjs/common';
|
|
2
|
+
|
|
3
|
+
import { AppConfigAPIHTTP, ConfigProviderService } from '@node-c/core';
|
|
4
|
+
import {
|
|
5
|
+
AuthorizationPoint,
|
|
6
|
+
IAMAuthorizationService,
|
|
7
|
+
IAMTokenManagerService,
|
|
8
|
+
IAMUserManagerService,
|
|
9
|
+
IAMUserManagerUserTokenEnityFields
|
|
10
|
+
} from '@node-c/domain-iam';
|
|
11
|
+
|
|
12
|
+
import { NextFunction, Response } from 'express';
|
|
13
|
+
|
|
14
|
+
import { Constants, RequestWithLocals } from '../common/definitions';
|
|
15
|
+
import { checkRoutes } from '../common/utils';
|
|
16
|
+
|
|
17
|
+
/*
|
|
18
|
+
* Authorization middleware - used for general authorization of the HTTP resource.
|
|
19
|
+
*/
|
|
20
|
+
@Injectable()
|
|
21
|
+
export class HTTPAuthorizationMiddleware<User extends object> implements NestMiddleware {
|
|
22
|
+
constructor(
|
|
23
|
+
// eslint-disable-next-line no-unused-vars
|
|
24
|
+
protected configProvider: ConfigProviderService,
|
|
25
|
+
@Inject(Constants.API_MODULE_NAME)
|
|
26
|
+
// eslint-disable-next-line no-unused-vars
|
|
27
|
+
protected moduleName: string,
|
|
28
|
+
@Inject(Constants.API_MODULE_AUTHORIZATION_SERVICE)
|
|
29
|
+
// eslint-disable-next-line no-unused-vars
|
|
30
|
+
protected authorizationService: IAMAuthorizationService<AuthorizationPoint<unknown>>,
|
|
31
|
+
@Inject(Constants.AUTHORIZATION_MIDDLEWARE_TOKEN_MANAGER_SERVICE)
|
|
32
|
+
// eslint-disable-next-line no-unused-vars
|
|
33
|
+
protected tokenManager?: IAMTokenManagerService<IAMUserManagerUserTokenEnityFields>,
|
|
34
|
+
@Inject(Constants.AUTHENTICATION_MIDDLEWARE_USERS_SERVICE)
|
|
35
|
+
// eslint-disable-next-line no-unused-vars
|
|
36
|
+
protected usersService?: IAMUserManagerService<User>
|
|
37
|
+
) {}
|
|
38
|
+
|
|
39
|
+
use(req: RequestWithLocals<unknown>, res: Response, next: NextFunction): void {
|
|
40
|
+
(async () => {
|
|
41
|
+
const moduleConfig = this.configProvider.config.api![this.moduleName] as AppConfigAPIHTTP;
|
|
42
|
+
const { anonymousAccessRoutes } = moduleConfig;
|
|
43
|
+
const requestMethod = req.method.toLowerCase();
|
|
44
|
+
if (!req.locals) {
|
|
45
|
+
req.locals = {};
|
|
46
|
+
}
|
|
47
|
+
if (anonymousAccessRoutes && Object.keys(anonymousAccessRoutes).length) {
|
|
48
|
+
const originalUrl = req.originalUrl.split('?')[0];
|
|
49
|
+
let isAnonymous = false;
|
|
50
|
+
for (const route in anonymousAccessRoutes) {
|
|
51
|
+
if (
|
|
52
|
+
checkRoutes(originalUrl, [route]) &&
|
|
53
|
+
anonymousAccessRoutes[route].find(method => method === requestMethod)
|
|
54
|
+
) {
|
|
55
|
+
isAnonymous = true;
|
|
56
|
+
break;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
if (isAnonymous) {
|
|
60
|
+
req.locals.isAnonymous = true;
|
|
61
|
+
next();
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
const { tokenManager, usersService } = this;
|
|
66
|
+
const hasApiKey = !!req.headers.authorization?.match(/^ApiKey\s/);
|
|
67
|
+
if (hasApiKey) {
|
|
68
|
+
const [apiKeyFromHeader, requestSignature] =
|
|
69
|
+
req.headers.authorization?.replace(/^ApiKey\s/, '')?.split(' ') || [];
|
|
70
|
+
let signatureContent = '';
|
|
71
|
+
if (requestMethod === 'get' && req.query && Object.keys(req.query).length) {
|
|
72
|
+
signatureContent = JSON.stringify(req.query);
|
|
73
|
+
} else if (
|
|
74
|
+
(requestMethod === 'delete' ||
|
|
75
|
+
requestMethod === 'patch' ||
|
|
76
|
+
requestMethod === 'post' ||
|
|
77
|
+
requestMethod === 'put') &&
|
|
78
|
+
req.body &&
|
|
79
|
+
Object.keys(req.body).length
|
|
80
|
+
) {
|
|
81
|
+
signatureContent = JSON.stringify(req.body);
|
|
82
|
+
} else {
|
|
83
|
+
signatureContent = req.originalUrl.split('?')[0];
|
|
84
|
+
}
|
|
85
|
+
const { valid } = await this.authorizationService.authorizeApiKey(
|
|
86
|
+
{
|
|
87
|
+
apiKey: apiKeyFromHeader,
|
|
88
|
+
signature: requestSignature,
|
|
89
|
+
signatureContent
|
|
90
|
+
},
|
|
91
|
+
{ config: moduleConfig }
|
|
92
|
+
);
|
|
93
|
+
if (!valid) {
|
|
94
|
+
throw new HttpException('Unauthorized', HttpStatus.UNAUTHORIZED);
|
|
95
|
+
}
|
|
96
|
+
next();
|
|
97
|
+
return;
|
|
98
|
+
} else if (!tokenManager) {
|
|
99
|
+
console.error('Missing api key in the configuration and no tokenManager set up.');
|
|
100
|
+
throw new HttpException('Unauthorized', HttpStatus.UNAUTHORIZED);
|
|
101
|
+
}
|
|
102
|
+
let tokens: string[] = [];
|
|
103
|
+
let authToken = req.headers.authorization;
|
|
104
|
+
let refreshToken: string | undefined;
|
|
105
|
+
let useCookie = false;
|
|
106
|
+
if (typeof authToken === 'string' && authToken.length && authToken.match(/^Bearer\s/)) {
|
|
107
|
+
tokens = authToken.split(' ');
|
|
108
|
+
if (tokens.length) {
|
|
109
|
+
authToken = tokens[1];
|
|
110
|
+
refreshToken = tokens[2];
|
|
111
|
+
}
|
|
112
|
+
} else {
|
|
113
|
+
authToken = req.cookies['sid'];
|
|
114
|
+
useCookie = true;
|
|
115
|
+
}
|
|
116
|
+
const { newAuthToken, tokenContent, valid } =
|
|
117
|
+
await this.authorizationService.authorizeBearer<IAMUserManagerUserTokenEnityFields>(
|
|
118
|
+
{ authToken, refreshToken },
|
|
119
|
+
{ identifierDataField: usersService ? 'userId' : undefined }
|
|
120
|
+
);
|
|
121
|
+
if (!valid) {
|
|
122
|
+
throw new HttpException('Unauthorized', HttpStatus.UNAUTHORIZED);
|
|
123
|
+
}
|
|
124
|
+
if (usersService) {
|
|
125
|
+
const userId = tokenContent?.data?.userId;
|
|
126
|
+
if (!userId) {
|
|
127
|
+
console.error('Missing userId in the tokenContent data.');
|
|
128
|
+
throw new HttpException('Unauthorized', HttpStatus.UNAUTHORIZED);
|
|
129
|
+
}
|
|
130
|
+
// use the bearer auth token decoded payload for the user data, if configured this way
|
|
131
|
+
const user = tokenContent?.data?.user;
|
|
132
|
+
if (user) {
|
|
133
|
+
req.locals!.user = user;
|
|
134
|
+
} else {
|
|
135
|
+
req.locals!.user = await usersService.getUserWithPermissionsData({ filters: { id: userId } });
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
if (newAuthToken) {
|
|
139
|
+
res.setHeader('Authorization', `Bearer ${newAuthToken}${refreshToken ? ` ${refreshToken}` : ''}`);
|
|
140
|
+
if (useCookie) {
|
|
141
|
+
res.cookie('sid', newAuthToken);
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
next();
|
|
145
|
+
})().then(
|
|
146
|
+
() => true,
|
|
147
|
+
err => {
|
|
148
|
+
console.error(err);
|
|
149
|
+
res.status((err && err.status) || HttpStatus.INTERNAL_SERVER_ERROR).end();
|
|
150
|
+
}
|
|
151
|
+
);
|
|
152
|
+
}
|
|
153
|
+
}
|
|
@@ -25,9 +25,9 @@ export class HTTPCORSMiddleware implements NestMiddleware {
|
|
|
25
25
|
'Access-Control-Allow-Headers',
|
|
26
26
|
'accept,accept-encoding,accept-language,authorization,connection,content-type,host,origin,referer,user-agent'
|
|
27
27
|
);
|
|
28
|
-
res.set('Access-Control-Expose-Headers', 'Authorization');
|
|
29
28
|
res.set('Access-Control-Allow-Methods', 'OPTIONS,GET,POST,PUT,PATCH,DELETE');
|
|
30
29
|
res.set('Access-Control-Allow-Credentials', 'true');
|
|
30
|
+
res.set('Access-Control-Expose-Headers', 'Authorization');
|
|
31
31
|
if (req.method.toLowerCase() === 'options') {
|
|
32
32
|
res.status(HttpStatus.OK).end();
|
|
33
33
|
return;
|
package/src/middlewares/index.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export * from './http.middlewares.
|
|
1
|
+
export * from './http.middlewares.authorization';
|
|
2
2
|
export * from './http.middlewares.cors';
|
|
@@ -1,16 +1,18 @@
|
|
|
1
|
-
import { DynamicModule, Inject, MiddlewareConsumer, ModuleMetadata } from '@nestjs/common';
|
|
1
|
+
import { DynamicModule, Inject, MiddlewareConsumer, ModuleMetadata, ValidationPipe } from '@nestjs/common';
|
|
2
|
+
import { APP_PIPE } from '@nestjs/core';
|
|
2
3
|
|
|
3
4
|
import { ConfigProviderService, loadDynamicModules } from '@node-c/core';
|
|
4
5
|
|
|
5
6
|
import cookieParser from 'cookie-parser';
|
|
6
7
|
import express, { Response } from 'express';
|
|
8
|
+
import morgan from 'morgan';
|
|
7
9
|
|
|
8
10
|
import { HTTPAPIModuleOptions } from './http.api.module.definitions';
|
|
9
11
|
|
|
10
12
|
import { Constants, RequestWithLocals } from '../common/definitions';
|
|
11
|
-
import { HttpExceptionFilter } from '../
|
|
12
|
-
import {
|
|
13
|
-
import {
|
|
13
|
+
import { HttpExceptionFilter } from '../filters';
|
|
14
|
+
import { HTTPAccessControlInterceptor, HTTPErrorInterceptor } from '../interceptors';
|
|
15
|
+
import { HTTPAuthorizationMiddleware, HTTPCORSMiddleware } from '../middlewares';
|
|
14
16
|
|
|
15
17
|
export class HTTPAPIModule {
|
|
16
18
|
constructor(
|
|
@@ -25,8 +27,12 @@ export class HTTPAPIModule {
|
|
|
25
27
|
consumer.apply(express.urlencoded({ verify: HTTPAPIModule.rawBodyBuffer, extended: true })).forRoutes('*');
|
|
26
28
|
consumer.apply(express.json({ verify: HTTPAPIModule.rawBodyBuffer })).forRoutes('*');
|
|
27
29
|
consumer.apply(cookieParser()).forRoutes('*');
|
|
30
|
+
// configure logging
|
|
31
|
+
consumer
|
|
32
|
+
.apply(morgan(`[${this.moduleName}]: :method :url :status :res[content-length] - :response-time ms`))
|
|
33
|
+
.forRoutes('*');
|
|
28
34
|
consumer.apply(HTTPCORSMiddleware).forRoutes('*');
|
|
29
|
-
consumer.apply(
|
|
35
|
+
consumer.apply(HTTPAuthorizationMiddleware).forRoutes('*');
|
|
30
36
|
}
|
|
31
37
|
|
|
32
38
|
static rawBodyBuffer(req: RequestWithLocals<unknown>, _res: Response, buffer: Buffer): void {
|
|
@@ -43,13 +49,21 @@ export class HTTPAPIModule {
|
|
|
43
49
|
module: moduleClass as DynamicModule['module'],
|
|
44
50
|
imports: [...(importsAtStart || []), ...(importsAtEnd || [])],
|
|
45
51
|
providers: [
|
|
52
|
+
// configure DTO validation
|
|
53
|
+
{
|
|
54
|
+
provide: APP_PIPE,
|
|
55
|
+
// useClass: ValidationPipe
|
|
56
|
+
useValue: new ValidationPipe({
|
|
57
|
+
whitelist: true
|
|
58
|
+
})
|
|
59
|
+
},
|
|
46
60
|
{
|
|
47
61
|
provide: Constants.API_MODULE_NAME,
|
|
48
62
|
useValue: options.moduleName
|
|
49
63
|
},
|
|
50
64
|
{
|
|
51
65
|
provide: Constants.AUTHORIZATION_INTERCEPTOR,
|
|
52
|
-
useClass:
|
|
66
|
+
useClass: HTTPAccessControlInterceptor
|
|
53
67
|
},
|
|
54
68
|
{
|
|
55
69
|
provide: Constants.ERROR_INTERCEPTOR,
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"http.exceptionFilters.httpException.js","sourceRoot":"","sources":["../../src/exceptionFilters/http.exceptionFilters.httpException.ts"],"names":[],"mappings":";;;;;;;;;AAAA,2CAAsF;AAK/E,IAAM,mBAAmB,GAAzB,MAAM,mBAAmB;IAC9B,KAAK,CAAC,SAAwB,EAAE,IAAmB;QACjD,MAAM,GAAG,GAAG,IAAI,CAAC,YAAY,EAAE,CAAC;QAChC,MAAM,QAAQ,GAAG,GAAG,CAAC,WAAW,EAAY,CAAC;QAC7C,MAAM,MAAM,GAAG,SAAS,CAAC,SAAS,EAAE,CAAC;QAMrC,QAAQ,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC;YAC3B,UAAU,EAAE,MAAM;YAClB,OAAO,EAAE,SAAS,CAAC,OAAO;SAC3B,CAAC,CAAC;IACL,CAAC;CACF,CAAA;AAfY,kDAAmB;8BAAnB,mBAAmB;IAD/B,IAAA,cAAK,EAAC,sBAAa,CAAC;GACR,mBAAmB,CAe/B"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './http.exceptionFilters.httpException';
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/exceptionFilters/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,wEAAsD"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"http.interceptors.authorization.js","sourceRoot":"","sources":["../../src/interceptors/http.interceptors.authorization.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAAA,2CAQwB;AAExB,uCAA2E;AAC3E,mDAA0G;AAE1G,0DAAmD;AAGnD,uDAAqE;AAG9D,IAAM,4BAA4B,GAAlC,MAAM,4BAA4B;IAGvC,YAGY,oBAA0E,EAE1E,cAAqC,EAGrC,UAAkB;QALlB,yBAAoB,GAApB,oBAAoB,CAAsD;QAE1E,mBAAc,GAAd,cAAc,CAAuB;QAGrC,eAAU,GAAV,UAAU,CAAQ;IAC3B,CAAC;IAEE,SAAS,CAAC,OAAyB,EAAE,IAAiB;;YAC1D,MAAM,CAAC,GAAG,CAAC,GAAuC,OAAO,CAAC,OAAO,EAAE,CAAC;YACpE,MAAM,MAAM,GAAG,GAAG,CAAC,MAAO,CAAC;YAC3B,IAAI,CAAC,MAAM,EAAE,CAAC;gBACZ,MAAM,IAAI,sBAAa,CAAC,WAAW,EAAE,mBAAU,CAAC,SAAS,CAAC,CAAC;YAC7D,CAAC;iBAAM,IAAI,MAAM,C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AAoB,EAAE,GAAG,oCAAuB,CAAC,WAAW,CAC7E,WAAW,EACX,EAAE,IAAI,EAAE,GAAG,CAAC,IAAI,EAAE,OAAO,EAAE,GAAG,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,CAAC,MAAM,EAAE,KAAK,EAAE,GAAG,CAAC,KAAK,EAAE,EAC9E,IAAI,CACL,CAAC;YACF,IAAI,CAAC,SAAS,EAAE,CAAC;gBACf,OAAO,CAAC,IAAI,CACV,IAAI,UAAU,8DAA8D,cAAc,IAAI,WAAW,GAAG,CAC7G,CAAC;gBACF,MAAM,IAAI,sBAAa,CAAC,WAAW,EAAE,mBAAU,CAAC,SAAS,CAAC,CAAC;YAC7D,CAAC;YACD,KAAK,MAAM,GAAG,IAAI,oBAAoB,EAAE,CAAC;gBACvC,IAAA,yBAAS,EAAC,GAAG,EAAE,GAAG,EAAE,oBAAoB,CAAC,GAAG,CAAC,CAAC,CAAC;YACjD,CAAC;YACD,OAAO,IAAI,CAAC,MAAM,EAAE,CAAC;QACvB,CAAC;KAAA;CACF,CAAA;AA9DY,oEAA4B;uCAA5B,4BAA4B;IADxC,IAAA,mBAAU,GAAE;IAKR,WAAA,IAAA,eAAM,EAAC,uBAAS,CAAC,gCAAgC,CAAC,CAAA;IAKlD,WAAA,IAAA,eAAM,EAAC,uBAAS,CAAC,eAAe,CAAC,CAAA;qCAHF,oCAAuB;QAE7B,4BAAqB;GARtC,4BAA4B,CA8DxC"}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { NestMiddleware } from '@nestjs/common';
|
|
2
|
-
import { ConfigProviderService } from '@node-c/core';
|
|
3
|
-
import { IAMTokenManagerService, IAMUsersService, UserTokenEnityFields } from '@node-c/domain-iam';
|
|
4
|
-
import { NextFunction, Response } from 'express';
|
|
5
|
-
import { RequestWithLocals } from '../common/definitions';
|
|
6
|
-
export declare class HTTPAuthenticationMiddleware<User extends object> implements NestMiddleware {
|
|
7
|
-
protected configProvider: ConfigProviderService;
|
|
8
|
-
protected moduleName: string;
|
|
9
|
-
protected tokenManager: IAMTokenManagerService<UserTokenEnityFields>;
|
|
10
|
-
protected usersService: IAMUsersService<User>;
|
|
11
|
-
constructor(configProvider: ConfigProviderService, moduleName: string, tokenManager: IAMTokenManagerService<UserTokenEnityFields>, usersService: IAMUsersService<User>);
|
|
12
|
-
use(req: RequestWithLocals<unknown>, res: Response, next: NextFunction): void;
|
|
13
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"http.middlewares.authentication.js","sourceRoot":"","sources":["../../src/middlewares/http.middlewares.authentication.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAAA,2CAA+F;AAE/F,uCAAuE;AACvE,mDAAwH;AAExH,0DAAqD;AAIrD,uDAAqE;AAG9D,IAAM,4BAA4B,GAAlC,MAAM,4BAA4B;IACvC,YAEY,cAAqC,EAGrC,UAAkB,EAGlB,YAA0D,EAG1D,YAAmC;QATnC,mBAAc,GAAd,cAAc,CAAuB;QAGrC,eAAU,GAAV,UAAU,CAAQ;QAGlB,iBAAY,GAAZ,YAAY,CAA8C;QAG1D,iBAAY,GAAZ,YAAY,CAAuB;IAC5C,CAAC;IAEJ,GAAG,CAAC,GAA+B,EAAE,GAAa,EAAE,IAAkB;QACpE,CAAC,GAAS,EAAE;;YACV,MAAM,EAAE,qBAAqB,EAAE,GAAG,IAAI,CAAC,cAAc,CAAC,MAAM,CAAC,GAAI,CAAC,IAAI,CAAC,UAAU,CAAqB,CAAC;YACvG,IAAI,CAAC,GAAG,CAAC,MAAM,EAAE,CAAC;gBAChB,GAAG,CAAC,MAAM,GAAG,EAAE,CAAC;YAClB,CAAC;YACD,IAAI,qBAAqB,IAAI,MAAM,CAAC,IAAI,CAAC,qBAAqB,CAAC,CAAC,MAAM,EAAE,CAAC;gBACvE,MAAM,WAAW,GAAG,GAAG,CAAC,WAAW,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;gBACl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