itlab-internal-services 1.2.2 → 1.3.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.
|
@@ -1,11 +1,14 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Request } from 'express';
|
|
2
|
+
import { Strategy, VerifiedCallback } from 'passport-custom';
|
|
2
3
|
export declare const INTERNAL_HEADER_KEY = "X-itlab-k8s-auth";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
declare const InternalStrategy_base: new (...args: any[]) => Strategy;
|
|
5
|
+
export declare class InternalStrategy extends InternalStrategy_base {
|
|
6
|
+
protected readonly token: string;
|
|
7
|
+
constructor(token?: string);
|
|
8
|
+
validate(req: Request, done: VerifiedCallback): void;
|
|
7
9
|
}
|
|
8
|
-
|
|
9
|
-
|
|
10
|
+
declare const InternalGuard_base: import("@nestjs/passport").Type<import("@nestjs/passport").IAuthGuard>;
|
|
11
|
+
export declare class InternalGuard extends InternalGuard_base {
|
|
10
12
|
}
|
|
11
13
|
export declare const Internal: () => <TFunction extends Function, Y>(target: object | TFunction, propertyKey?: string | symbol, descriptor?: TypedPropertyDescriptor<Y>) => void;
|
|
14
|
+
export {};
|
|
@@ -12,40 +12,38 @@ var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
|
12
12
|
return function (target, key) { decorator(target, key, paramIndex); }
|
|
13
13
|
};
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
exports.Internal = exports.
|
|
15
|
+
exports.Internal = exports.InternalGuard = exports.InternalStrategy = exports.INTERNAL_HEADER_KEY = void 0;
|
|
16
16
|
const common_1 = require("@nestjs/common");
|
|
17
|
+
const passport_1 = require("@nestjs/passport");
|
|
17
18
|
const swagger_1 = require("@nestjs/swagger");
|
|
19
|
+
const passport_custom_1 = require("passport-custom");
|
|
18
20
|
const internal_constants_1 = require("../internal.constants");
|
|
19
21
|
exports.INTERNAL_HEADER_KEY = 'X-itlab-k8s-auth';
|
|
20
22
|
const description = 'Application unauthorized';
|
|
21
23
|
const status = common_1.HttpStatus.FORBIDDEN;
|
|
22
|
-
let
|
|
23
|
-
constructor(
|
|
24
|
-
|
|
24
|
+
let InternalStrategy = class InternalStrategy extends (0, passport_1.PassportStrategy)(passport_custom_1.Strategy, 'internal') {
|
|
25
|
+
constructor(token = '') {
|
|
26
|
+
super();
|
|
27
|
+
this.token = token;
|
|
25
28
|
}
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
throw new UnauthorizedApplicationException();
|
|
29
|
+
validate(req, done) {
|
|
30
|
+
const headerToken = req.header(exports.INTERNAL_HEADER_KEY);
|
|
31
|
+
if (this.token === headerToken)
|
|
32
|
+
return done(null, true);
|
|
33
|
+
return done(new common_1.HttpException(description, status), false);
|
|
32
34
|
}
|
|
33
35
|
};
|
|
34
|
-
|
|
36
|
+
InternalStrategy = __decorate([
|
|
35
37
|
(0, common_1.Injectable)(),
|
|
36
38
|
__param(0, (0, common_1.Inject)(internal_constants_1.INTERNAL_MODULE_HEADER_TOKEN)),
|
|
37
39
|
__metadata("design:paramtypes", [String])
|
|
40
|
+
], InternalStrategy);
|
|
41
|
+
exports.InternalStrategy = InternalStrategy;
|
|
42
|
+
let InternalGuard = class InternalGuard extends (0, passport_1.AuthGuard)('internal') {
|
|
43
|
+
};
|
|
44
|
+
InternalGuard = __decorate([
|
|
45
|
+
(0, common_1.Injectable)()
|
|
38
46
|
], InternalGuard);
|
|
39
47
|
exports.InternalGuard = InternalGuard;
|
|
40
|
-
|
|
41
|
-
constructor() {
|
|
42
|
-
super(description, status);
|
|
43
|
-
}
|
|
44
|
-
};
|
|
45
|
-
UnauthorizedApplicationException = __decorate([
|
|
46
|
-
(0, common_1.Injectable)(),
|
|
47
|
-
__metadata("design:paramtypes", [])
|
|
48
|
-
], UnauthorizedApplicationException);
|
|
49
|
-
exports.UnauthorizedApplicationException = UnauthorizedApplicationException;
|
|
50
|
-
const Internal = () => (0, common_1.applyDecorators)((0, swagger_1.ApiBasicAuth)(exports.INTERNAL_HEADER_KEY), (0, common_1.UseGuards)(new InternalGuard()), (0, swagger_1.ApiResponse)({ description, status }));
|
|
48
|
+
const Internal = () => (0, common_1.applyDecorators)((0, swagger_1.ApiBasicAuth)(exports.INTERNAL_HEADER_KEY), (0, common_1.UseGuards)(InternalGuard), (0, swagger_1.ApiResponse)({ description, status }));
|
|
51
49
|
exports.Internal = Internal;
|
package/dist/internal.module.js
CHANGED
|
@@ -26,16 +26,16 @@ const axios_1 = __importDefault(require("axios"));
|
|
|
26
26
|
const guards_1 = require("./guards");
|
|
27
27
|
const internal_constants_1 = require("./internal.constants");
|
|
28
28
|
const services_1 = require("./services");
|
|
29
|
-
const
|
|
29
|
+
const createAxios = (token) => axios_1.default.create({
|
|
30
30
|
baseURL: 'https://services.svi-itlab.com/',
|
|
31
|
-
headers: {
|
|
31
|
+
headers: { [guards_1.INTERNAL_HEADER_KEY]: token },
|
|
32
32
|
});
|
|
33
33
|
let InternalModule = InternalModule_1 = class InternalModule {
|
|
34
34
|
static register(options) {
|
|
35
35
|
return {
|
|
36
36
|
module: InternalModule_1,
|
|
37
37
|
providers: [
|
|
38
|
-
{ provide: internal_constants_1.AXIOS_INSTANCE_TOKEN, useValue:
|
|
38
|
+
{ provide: internal_constants_1.AXIOS_INSTANCE_TOKEN, useValue: createAxios(options.token) },
|
|
39
39
|
{ provide: internal_constants_1.INTERNAL_MODULE_ID, useValue: (0, random_string_generator_util_1.randomStringGenerator)() },
|
|
40
40
|
{ provide: internal_constants_1.INTERNAL_MODULE_TARGET, useValue: options.target },
|
|
41
41
|
{ provide: internal_constants_1.INTERNAL_MODULE_HEADER_TOKEN, useValue: options.token },
|
|
@@ -51,7 +51,7 @@ let InternalModule = InternalModule_1 = class InternalModule {
|
|
|
51
51
|
...this.createAsyncProviders(options),
|
|
52
52
|
{
|
|
53
53
|
provide: internal_constants_1.AXIOS_INSTANCE_TOKEN,
|
|
54
|
-
useFactory: (config) =>
|
|
54
|
+
useFactory: (config) => createAxios(config.token),
|
|
55
55
|
inject: [internal_constants_1.INTERNAL_MODULE_OPTIONS],
|
|
56
56
|
},
|
|
57
57
|
{
|
|
@@ -114,7 +114,11 @@ InternalModule = InternalModule_1 = __decorate([
|
|
|
114
114
|
services_1.ContentService,
|
|
115
115
|
services_1.SearchService,
|
|
116
116
|
{ provide: internal_constants_1.AXIOS_INSTANCE_TOKEN, useValue: axios_1.default },
|
|
117
|
+
{ provide: internal_constants_1.INTERNAL_MODULE_TARGET, useValue: '' },
|
|
118
|
+
{ provide: internal_constants_1.INTERNAL_MODULE_HEADER_TOKEN, useValue: '' },
|
|
119
|
+
{ provide: internal_constants_1.INTERNAL_MODULE_JWT_SECRET, useValue: '' },
|
|
117
120
|
guards_1.JwtStrategy,
|
|
121
|
+
guards_1.InternalStrategy,
|
|
118
122
|
],
|
|
119
123
|
exports: [services_1.CommentService, services_1.ContentService, services_1.SearchService],
|
|
120
124
|
})
|
package/package.json
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
"email": "timo.scheuermann@sv-informatik.de",
|
|
6
6
|
"url": "https://timos.design"
|
|
7
7
|
},
|
|
8
|
-
"version": "1.
|
|
8
|
+
"version": "1.3.0",
|
|
9
9
|
"type": "commonjs",
|
|
10
10
|
"files": [
|
|
11
11
|
"dist"
|
|
@@ -23,7 +23,8 @@
|
|
|
23
23
|
},
|
|
24
24
|
"dependencies": {
|
|
25
25
|
"axios": "^1.2.3",
|
|
26
|
-
"itlab-functions": "^0.2.0"
|
|
26
|
+
"itlab-functions": "^0.2.0",
|
|
27
|
+
"passport-custom": "^1.1.1"
|
|
27
28
|
},
|
|
28
29
|
"devDependencies": {
|
|
29
30
|
"@nestjs/common": "9.2.0",
|
|
@@ -32,6 +33,7 @@
|
|
|
32
33
|
"@nestjs/platform-express": "9.2.0",
|
|
33
34
|
"@nestjs/swagger": "^6.1.3",
|
|
34
35
|
"@types/node": "18.11.9",
|
|
36
|
+
"@types/passport-strategy": "^0.2.35",
|
|
35
37
|
"@typescript-eslint/eslint-plugin": "5.42.1",
|
|
36
38
|
"@typescript-eslint/parser": "5.42.1",
|
|
37
39
|
"class-validator": "^0.13.2",
|