chyz 2.0.0-rc.8 → 2.0.1-rc.1
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/BaseChyz.d.ts +73 -56
- package/BaseChyz.d.ts.map +1 -1
- package/BaseChyz.js +569 -404
- package/README.md +1 -1
- package/base/ActionFilter.d.ts +32 -32
- package/base/ActionFilter.d.ts.map +1 -1
- package/base/ActionFilter.js +82 -82
- package/base/BadRequestHttpException.d.ts +6 -0
- package/base/BadRequestHttpException.d.ts.map +1 -0
- package/base/BadRequestHttpException.js +17 -0
- package/base/BaseError.d.ts +43 -10
- package/base/BaseError.d.ts.map +1 -1
- package/base/BaseError.js +58 -26
- package/base/Behavior.d.ts +3 -3
- package/base/Behavior.js +7 -7
- package/base/CBaseObject.d.ts +4 -4
- package/base/CBaseObject.d.ts.map +1 -1
- package/base/CBaseObject.js +16 -16
- package/base/CEvents.d.ts +13 -0
- package/base/CEvents.d.ts.map +1 -0
- package/base/CEvents.js +24 -0
- package/base/CRequest.d.ts +1 -1
- package/base/CRequest.js +10 -10
- package/base/CWebController.d.ts +43 -43
- package/base/CWebController.d.ts.map +1 -1
- package/base/CWebController.js +81 -74
- package/base/Component.d.ts +20 -20
- package/base/Component.d.ts.map +1 -1
- package/base/Component.js +57 -57
- package/base/Configurable.d.ts +2 -2
- package/base/Configurable.js +8 -8
- package/base/DataErrorDbException.d.ts +5 -5
- package/base/DataErrorDbException.d.ts.map +1 -1
- package/base/DataErrorDbException.js +17 -17
- package/base/DbConnection.d.ts +12 -12
- package/base/DbConnection.js +53 -53
- package/base/ForbiddenHttpException.d.ts +4 -4
- package/base/ForbiddenHttpException.d.ts.map +1 -1
- package/base/ForbiddenHttpException.js +16 -16
- package/base/InvalidArgumentException.d.ts +5 -5
- package/base/InvalidArgumentException.d.ts.map +1 -1
- package/base/InvalidArgumentException.js +17 -17
- package/base/InvalidConfigException.d.ts +5 -5
- package/base/InvalidConfigException.d.ts.map +1 -1
- package/base/InvalidConfigException.js +17 -17
- package/base/Logs.d.ts +21 -21
- package/base/Logs.d.ts.map +1 -1
- package/base/Logs.js +57 -57
- package/base/Model.d.ts +301 -298
- package/base/Model.d.ts.map +1 -1
- package/base/Model.js +545 -507
- package/base/ModelManager.d.ts +1 -1
- package/base/ModelManager.js +19 -19
- package/base/NotFoundHttpException.d.ts +5 -5
- package/base/NotFoundHttpException.d.ts.map +1 -1
- package/base/NotFoundHttpException.js +17 -17
- package/base/RestClient.d.ts +6 -6
- package/base/RestClient.d.ts.map +1 -1
- package/base/RestClient.js +25 -25
- package/base/UnauthorizedHttpException.d.ts +5 -5
- package/base/UnauthorizedHttpException.d.ts.map +1 -1
- package/base/UnauthorizedHttpException.js +17 -17
- package/base/ValidationHttpException.d.ts +5 -5
- package/base/ValidationHttpException.d.ts.map +1 -1
- package/base/ValidationHttpException.js +17 -17
- package/base/db/Exception.d.ts +6 -6
- package/base/db/Exception.js +15 -15
- package/base/index.d.ts +19 -18
- package/base/index.d.ts.map +1 -1
- package/base/index.js +41 -39
- package/decorator/Middleware.d.ts +3 -3
- package/decorator/Middleware.js +11 -11
- package/decorator/controller.d.ts +2 -2
- package/decorator/controller.js +24 -24
- package/decorator/delete.d.ts +3 -0
- package/decorator/delete.d.ts.map +1 -0
- package/decorator/delete.js +36 -0
- package/decorator/enums/ControllerDecoratorParams.d.ts +5 -5
- package/decorator/enums/ControllerDecoratorParams.js +9 -9
- package/decorator/get.d.ts +2 -2
- package/decorator/get.js +36 -36
- package/decorator/index.d.ts +5 -3
- package/decorator/index.d.ts.map +1 -1
- package/decorator/index.js +13 -9
- package/decorator/post.d.ts +2 -2
- package/decorator/post.js +36 -36
- package/decorator/put.d.ts +3 -0
- package/decorator/put.d.ts.map +1 -0
- package/decorator/put.js +36 -0
- package/filters/AccessControl.d.ts +12 -12
- package/filters/AccessControl.d.ts.map +1 -1
- package/filters/AccessControl.js +83 -83
- package/filters/AccessRule.d.ts +82 -82
- package/filters/AccessRule.d.ts.map +1 -1
- package/filters/AccessRule.js +136 -137
- package/filters/auth/AuthInterface.d.ts +25 -25
- package/filters/auth/AuthInterface.js +2 -2
- package/filters/auth/AuthMethod.d.ts +37 -37
- package/filters/auth/AuthMethod.d.ts.map +1 -1
- package/filters/auth/AuthMethod.js +82 -82
- package/filters/auth/HttpBasicAuth.d.ts +23 -22
- package/filters/auth/HttpBasicAuth.d.ts.map +1 -1
- package/filters/auth/HttpBasicAuth.js +78 -72
- package/filters/auth/HttpBearerAuth.d.ts +17 -17
- package/filters/auth/HttpBearerAuth.d.ts.map +1 -1
- package/filters/auth/HttpBearerAuth.js +33 -32
- package/filters/auth/HttpHeaderAuth.d.ts +18 -14
- package/filters/auth/HttpHeaderAuth.d.ts.map +1 -1
- package/filters/auth/HttpHeaderAuth.js +64 -57
- package/filters/auth/JwtHttpBearerAuth.d.ts +20 -20
- package/filters/auth/JwtHttpBearerAuth.d.ts.map +1 -1
- package/filters/auth/JwtHttpBearerAuth.js +87 -81
- package/filters/auth/KeyCloakHttpBearerAuth.d.ts +22 -22
- package/filters/auth/KeyCloakHttpBearerAuth.js +116 -116
- package/filters/auth/index.d.ts +4 -4
- package/filters/auth/index.js +11 -11
- package/filters/index.d.ts +2 -2
- package/filters/index.js +7 -7
- package/index.d.ts +28 -21
- package/index.d.ts.map +1 -1
- package/index.js +71 -60
- package/model/RouteDefinition.d.ts +6 -6
- package/model/RouteDefinition.js +8 -8
- package/package.json +22 -24
- package/rbac/AuthAssignment.d.ts +18 -18
- package/rbac/AuthAssignment.js +44 -44
- package/rbac/AuthItem.d.ts +26 -26
- package/rbac/AuthItem.js +51 -51
- package/rbac/AuthItemChild.d.ts +18 -18
- package/rbac/AuthItemChild.js +43 -43
- package/rbac/AuthManager.d.ts +111 -111
- package/rbac/AuthManager.d.ts.map +1 -1
- package/rbac/AuthManager.js +356 -355
- package/rbac/index.d.ts +5 -0
- package/rbac/index.d.ts.map +1 -0
- package/rbac/index.js +28 -0
- package/requiments/Glob.d.ts +2 -2
- package/requiments/Glob.js +10 -10
- package/requiments/ReflectUtil.js +24 -24
- package/requiments/Utils.d.ts +1 -8
- package/requiments/Utils.d.ts.map +1 -1
- package/requiments/Utils.js +115 -112
- package/validators/BooleanValidator.js +1 -1
- package/validators/CompareValidator.js +1 -1
- package/validators/DateValidator.js +1 -1
- package/validators/EmailValidator.js +1 -1
- package/validators/Validator.d.ts +17 -17
- package/validators/Validator.js +27 -27
- package/web/IdentityInterface.d.ts +55 -54
- package/web/IdentityInterface.d.ts.map +1 -1
- package/web/IdentityInterface.js +8 -8
- package/web/WebUser.d.ts +71 -71
- package/web/WebUser.js +165 -165
|
@@ -1,72 +1,78 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/*
|
|
3
|
-
* Copyright (c) 2021. Chy Bilgisayar Bilisim
|
|
4
|
-
* Author: Cihan Ozturk
|
|
5
|
-
* E-mail: cihan@chy.com.tr
|
|
6
|
-
* Github:https://github.com/cihan53/
|
|
7
|
-
*/
|
|
8
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
9
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
10
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
11
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
12
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
13
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
14
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
15
|
-
});
|
|
16
|
-
};
|
|
17
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
18
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
19
|
-
};
|
|
20
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
21
|
-
exports.HttpBasicAuth = void 0;
|
|
22
|
-
const AuthMethod_1 = require("./AuthMethod");
|
|
23
|
-
const base_1 = require("../../base");
|
|
24
|
-
const BaseChyz_1 = __importDefault(require("../../BaseChyz"));
|
|
25
|
-
class HttpBasicAuth extends AuthMethod_1.AuthMethod {
|
|
26
|
-
constructor() {
|
|
27
|
-
super(...arguments);
|
|
28
|
-
/**
|
|
29
|
-
* @var string the HTTP header name
|
|
30
|
-
*/
|
|
31
|
-
this.header = 'Authorization';
|
|
32
|
-
/**
|
|
33
|
-
* @var string a pattern to use to extract the HTTP authentication value
|
|
34
|
-
*/
|
|
35
|
-
this.pattern = /^Basic\s+(.*?)$/;
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
let identity =
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* Copyright (c) 2021. Chy Bilgisayar Bilisim
|
|
4
|
+
* Author: Cihan Ozturk
|
|
5
|
+
* E-mail: cihan@chy.com.tr
|
|
6
|
+
* Github:https://github.com/cihan53/
|
|
7
|
+
*/
|
|
8
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
9
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
10
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
11
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
12
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
13
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
14
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
15
|
+
});
|
|
16
|
+
};
|
|
17
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
18
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
19
|
+
};
|
|
20
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
21
|
+
exports.HttpBasicAuth = void 0;
|
|
22
|
+
const AuthMethod_1 = require("./AuthMethod");
|
|
23
|
+
const base_1 = require("../../base");
|
|
24
|
+
const BaseChyz_1 = __importDefault(require("../../BaseChyz"));
|
|
25
|
+
class HttpBasicAuth extends AuthMethod_1.AuthMethod {
|
|
26
|
+
constructor() {
|
|
27
|
+
super(...arguments);
|
|
28
|
+
/**
|
|
29
|
+
* @var string the HTTP header name
|
|
30
|
+
*/
|
|
31
|
+
this.header = 'Authorization';
|
|
32
|
+
/**
|
|
33
|
+
* @var string a pattern to use to extract the HTTP authentication value
|
|
34
|
+
*/
|
|
35
|
+
this.pattern = /^Basic\s+(.*?)$/;
|
|
36
|
+
this.auth = null;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* @throws InvalidConfigException
|
|
40
|
+
*/
|
|
41
|
+
init() {
|
|
42
|
+
var _a;
|
|
43
|
+
super.init();
|
|
44
|
+
if (!this.pattern) {
|
|
45
|
+
throw new base_1.InvalidConfigException('You must provide pattern to use to extract the HTTP authentication value!');
|
|
46
|
+
}
|
|
47
|
+
this.user = (_a = BaseChyz_1.default.getComponent("user")) !== null && _a !== void 0 ? _a : null;
|
|
48
|
+
}
|
|
49
|
+
authenticate(user, request, response) {
|
|
50
|
+
return __awaiter(this, arguments, void 0, function* () {
|
|
51
|
+
let autHeader = this.getHeaderByKey(request.headers, this.header);
|
|
52
|
+
if (autHeader == null || (autHeader = this.patternCheck(autHeader, this.pattern)) == null) {
|
|
53
|
+
return this.fail(response);
|
|
54
|
+
}
|
|
55
|
+
let identity = null;
|
|
56
|
+
let token = null;
|
|
57
|
+
let buff = new Buffer(autHeader[1], "base64");
|
|
58
|
+
let basicauth = buff.toString().split(":");
|
|
59
|
+
if (this.auth != null) {
|
|
60
|
+
identity = yield this.auth(autHeader[1], ...arguments, basicauth);
|
|
61
|
+
}
|
|
62
|
+
else {
|
|
63
|
+
identity = yield user.loginByAccessToken(basicauth, "HttpBasicAuth");
|
|
64
|
+
}
|
|
65
|
+
if (identity == null)
|
|
66
|
+
this.fail(response);
|
|
67
|
+
return identity;
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* @throws UnauthorizedHttpException
|
|
72
|
+
*/
|
|
73
|
+
fail(response) {
|
|
74
|
+
this.challenge(response);
|
|
75
|
+
this.handleFailure(response);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
exports.HttpBasicAuth = HttpBasicAuth;
|
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
import { HttpHeaderAuth } from "./HttpHeaderAuth";
|
|
2
|
-
import { Response } from "express";
|
|
3
|
-
export declare class HttpBearerAuth extends HttpHeaderAuth {
|
|
4
|
-
/**
|
|
5
|
-
* {@inheritdoc}
|
|
6
|
-
*/
|
|
7
|
-
header: string;
|
|
8
|
-
pattern: RegExp;
|
|
9
|
-
/**
|
|
10
|
-
* @var string the HTTP authentication realm
|
|
11
|
-
*/
|
|
12
|
-
realm: string;
|
|
13
|
-
/**
|
|
14
|
-
* {@inheritdoc}
|
|
15
|
-
*/
|
|
16
|
-
challenge(response: Response):
|
|
17
|
-
}
|
|
1
|
+
import { HttpHeaderAuth } from "./HttpHeaderAuth";
|
|
2
|
+
import { Response } from "express";
|
|
3
|
+
export declare class HttpBearerAuth extends HttpHeaderAuth {
|
|
4
|
+
/**
|
|
5
|
+
* {@inheritdoc}
|
|
6
|
+
*/
|
|
7
|
+
header: string;
|
|
8
|
+
pattern: RegExp;
|
|
9
|
+
/**
|
|
10
|
+
* @var string the HTTP authentication realm
|
|
11
|
+
*/
|
|
12
|
+
realm: string;
|
|
13
|
+
/**
|
|
14
|
+
* {@inheritdoc}
|
|
15
|
+
*/
|
|
16
|
+
challenge(response: Response): Response;
|
|
17
|
+
}
|
|
18
18
|
//# sourceMappingURL=HttpBearerAuth.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"HttpBearerAuth.d.ts","sourceRoot":"","sources":["../../../src/filters/auth/HttpBearerAuth.ts"],"names":[],"mappings":"AAOA,OAAO,EAAC,cAAc,EAAC,MAAM,kBAAkB,CAAC;AAChD,OAAO,EAAC,QAAQ,EAAC,MAAM,SAAS,CAAC;AAEjC,qBAAa,cAAe,SAAQ,cAAc;IAE9C;;OAEG;IACI,MAAM,SAAmB;IAEzB,OAAO,SAAsB;IACpC;;OAEG;IACI,KAAK,SAAS;IAGrB;;OAEG;IACI,SAAS,CAAC,QAAQ,EAAE,QAAQ;
|
|
1
|
+
{"version":3,"file":"HttpBearerAuth.d.ts","sourceRoot":"","sources":["../../../src/filters/auth/HttpBearerAuth.ts"],"names":[],"mappings":"AAOA,OAAO,EAAC,cAAc,EAAC,MAAM,kBAAkB,CAAC;AAChD,OAAO,EAAC,QAAQ,EAAC,MAAM,SAAS,CAAC;AAEjC,qBAAa,cAAe,SAAQ,cAAc;IAE9C;;OAEG;IACI,MAAM,SAAmB;IAEzB,OAAO,SAAsB;IACpC;;OAEG;IACI,KAAK,SAAS;IAGrB;;OAEG;IACI,SAAS,CAAC,QAAQ,EAAE,QAAQ,GAAE,QAAQ;CAMhD"}
|
|
@@ -1,32 +1,33 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/*
|
|
3
|
-
* Copyright (c) 2021. Chy Bilgisayar Bilisim
|
|
4
|
-
* Author: Cihan Ozturk
|
|
5
|
-
* E-mail: cihan@chy.com.tr
|
|
6
|
-
* Github:https://github.com/cihan53/
|
|
7
|
-
*/
|
|
8
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
-
exports.HttpBearerAuth = void 0;
|
|
10
|
-
const HttpHeaderAuth_1 = require("./HttpHeaderAuth");
|
|
11
|
-
class HttpBearerAuth extends HttpHeaderAuth_1.HttpHeaderAuth {
|
|
12
|
-
constructor() {
|
|
13
|
-
super(...arguments);
|
|
14
|
-
/**
|
|
15
|
-
* {@inheritdoc}
|
|
16
|
-
*/
|
|
17
|
-
this.header = 'Authorization';
|
|
18
|
-
// @ts-ignore
|
|
19
|
-
this.pattern = /^Bearer\s+(.*?)$/;
|
|
20
|
-
/**
|
|
21
|
-
* @var string the HTTP authentication realm
|
|
22
|
-
*/
|
|
23
|
-
this.realm = 'api';
|
|
24
|
-
}
|
|
25
|
-
/**
|
|
26
|
-
* {@inheritdoc}
|
|
27
|
-
*/
|
|
28
|
-
challenge(response) {
|
|
29
|
-
response.set('WWW-Authenticate', `Bearer realm="${this.realm}"`);
|
|
30
|
-
|
|
31
|
-
}
|
|
32
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* Copyright (c) 2021. Chy Bilgisayar Bilisim
|
|
4
|
+
* Author: Cihan Ozturk
|
|
5
|
+
* E-mail: cihan@chy.com.tr
|
|
6
|
+
* Github:https://github.com/cihan53/
|
|
7
|
+
*/
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.HttpBearerAuth = void 0;
|
|
10
|
+
const HttpHeaderAuth_1 = require("./HttpHeaderAuth");
|
|
11
|
+
class HttpBearerAuth extends HttpHeaderAuth_1.HttpHeaderAuth {
|
|
12
|
+
constructor() {
|
|
13
|
+
super(...arguments);
|
|
14
|
+
/**
|
|
15
|
+
* {@inheritdoc}
|
|
16
|
+
*/
|
|
17
|
+
this.header = 'Authorization';
|
|
18
|
+
// @ts-ignore
|
|
19
|
+
this.pattern = /^Bearer\s+(.*?)$/;
|
|
20
|
+
/**
|
|
21
|
+
* @var string the HTTP authentication realm
|
|
22
|
+
*/
|
|
23
|
+
this.realm = 'api';
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* {@inheritdoc}
|
|
27
|
+
*/
|
|
28
|
+
challenge(response) {
|
|
29
|
+
response.set('WWW-Authenticate', `Bearer realm="${this.realm}"`);
|
|
30
|
+
return response;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
exports.HttpBearerAuth = HttpBearerAuth;
|
|
@@ -1,15 +1,19 @@
|
|
|
1
|
-
import { AuthMethod } from "./AuthMethod";
|
|
2
|
-
import { WebUser } from "../../web/WebUser";
|
|
3
|
-
import { Request, Response } from "express";
|
|
4
|
-
export declare class HttpHeaderAuth extends AuthMethod {
|
|
5
|
-
/**
|
|
6
|
-
* @var string the HTTP header name
|
|
7
|
-
*/
|
|
8
|
-
header: string;
|
|
9
|
-
/**
|
|
10
|
-
* @var string a pattern to use to extract the HTTP authentication value
|
|
11
|
-
*/
|
|
12
|
-
pattern: string;
|
|
13
|
-
authenticate(user: WebUser, request: Request, response: Response): Promise<any>;
|
|
14
|
-
|
|
1
|
+
import { AuthMethod } from "./AuthMethod";
|
|
2
|
+
import { WebUser } from "../../web/WebUser";
|
|
3
|
+
import { Request, Response } from "express";
|
|
4
|
+
export declare class HttpHeaderAuth extends AuthMethod {
|
|
5
|
+
/**
|
|
6
|
+
* @var string the HTTP header name
|
|
7
|
+
*/
|
|
8
|
+
header: string;
|
|
9
|
+
/**
|
|
10
|
+
* @var string a pattern to use to extract the HTTP authentication value
|
|
11
|
+
*/
|
|
12
|
+
pattern: string;
|
|
13
|
+
authenticate(user: WebUser, request: Request, response: Response): Promise<any>;
|
|
14
|
+
/**
|
|
15
|
+
* @throws UnauthorizedHttpException
|
|
16
|
+
*/
|
|
17
|
+
fail(response: Response): void;
|
|
18
|
+
}
|
|
15
19
|
//# sourceMappingURL=HttpHeaderAuth.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"HttpHeaderAuth.d.ts","sourceRoot":"","sources":["../../../src/filters/auth/HttpHeaderAuth.ts"],"names":[],"mappings":"AAOA,OAAO,EAAC,UAAU,EAAC,MAAM,cAAc,CAAC;AACxC,OAAO,EAAC,OAAO,EAAC,MAAM,mBAAmB,CAAC;AAE1C,OAAO,EAAC,OAAO,EAAE,QAAQ,EAAC,MAAM,SAAS,CAAC;AAE1C,qBAAa,cAAe,SAAQ,UAAU;IAC1C;;OAEG;IACI,MAAM,SAAe;IAG5B;;OAEG;IAEI,OAAO,EAAG,MAAM,CAAC;IAGlB,YAAY,CAAC,IAAI,EAAE,OAAO,EAAE,OAAO,EAAC,OAAO,EAAE,QAAQ,EAAC,QAAQ;
|
|
1
|
+
{"version":3,"file":"HttpHeaderAuth.d.ts","sourceRoot":"","sources":["../../../src/filters/auth/HttpHeaderAuth.ts"],"names":[],"mappings":"AAOA,OAAO,EAAC,UAAU,EAAC,MAAM,cAAc,CAAC;AACxC,OAAO,EAAC,OAAO,EAAC,MAAM,mBAAmB,CAAC;AAE1C,OAAO,EAAC,OAAO,EAAE,QAAQ,EAAC,MAAM,SAAS,CAAC;AAE1C,qBAAa,cAAe,SAAQ,UAAU;IAC1C;;OAEG;IACI,MAAM,SAAe;IAG5B;;OAEG;IAEI,OAAO,EAAG,MAAM,CAAC;IAGlB,YAAY,CAAC,IAAI,EAAE,OAAO,EAAE,OAAO,EAAC,OAAO,EAAE,QAAQ,EAAC,QAAQ;IA2BpE;;OAEG;IACI,IAAI,CAAC,QAAQ,EAAE,QAAQ,GAAG,IAAI;CAIxC"}
|
|
@@ -1,57 +1,64 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/*
|
|
3
|
-
* Copyright (c) 2021. Chy Bilgisayar Bilisim
|
|
4
|
-
* Author: Cihan Ozturk
|
|
5
|
-
* E-mail: cihan@chy.com.tr
|
|
6
|
-
* Github:https://github.com/cihan53/
|
|
7
|
-
*/
|
|
8
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
9
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
10
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
11
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
12
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
13
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
14
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
15
|
-
});
|
|
16
|
-
};
|
|
17
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
-
exports.HttpHeaderAuth = void 0;
|
|
19
|
-
const AuthMethod_1 = require("./AuthMethod");
|
|
20
|
-
const Utils_1 = require("../../requiments/Utils");
|
|
21
|
-
class HttpHeaderAuth extends AuthMethod_1.AuthMethod {
|
|
22
|
-
constructor() {
|
|
23
|
-
super(...arguments);
|
|
24
|
-
/**
|
|
25
|
-
* @var string the HTTP header name
|
|
26
|
-
*/
|
|
27
|
-
this.header = 'X-Api-Key';
|
|
28
|
-
}
|
|
29
|
-
authenticate(user, request, response) {
|
|
30
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
31
|
-
let key = Object.keys(request.headers).find(key => key.toLowerCase() === this.header.toLowerCase());
|
|
32
|
-
if (key) {
|
|
33
|
-
let authHeader = request.headers[key];
|
|
34
|
-
if (!Utils_1.Utils.isEmpty(authHeader)) {
|
|
35
|
-
if (this.pattern) {
|
|
36
|
-
//preg_match
|
|
37
|
-
let matches = authHeader.match(this.pattern);
|
|
38
|
-
if (matches && matches.length > 0) {
|
|
39
|
-
authHeader = matches[1];
|
|
40
|
-
}
|
|
41
|
-
else {
|
|
42
|
-
return
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
let identity = yield user.loginByAccessToken(authHeader, "HttpHeaderAuth");
|
|
46
|
-
if (identity === null) {
|
|
47
|
-
this.challenge(response);
|
|
48
|
-
this.handleFailure(response);
|
|
49
|
-
}
|
|
50
|
-
return identity;
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
return
|
|
54
|
-
});
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* Copyright (c) 2021. Chy Bilgisayar Bilisim
|
|
4
|
+
* Author: Cihan Ozturk
|
|
5
|
+
* E-mail: cihan@chy.com.tr
|
|
6
|
+
* Github:https://github.com/cihan53/
|
|
7
|
+
*/
|
|
8
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
9
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
10
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
11
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
12
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
13
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
14
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
15
|
+
});
|
|
16
|
+
};
|
|
17
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
+
exports.HttpHeaderAuth = void 0;
|
|
19
|
+
const AuthMethod_1 = require("./AuthMethod");
|
|
20
|
+
const Utils_1 = require("../../requiments/Utils");
|
|
21
|
+
class HttpHeaderAuth extends AuthMethod_1.AuthMethod {
|
|
22
|
+
constructor() {
|
|
23
|
+
super(...arguments);
|
|
24
|
+
/**
|
|
25
|
+
* @var string the HTTP header name
|
|
26
|
+
*/
|
|
27
|
+
this.header = 'X-Api-Key';
|
|
28
|
+
}
|
|
29
|
+
authenticate(user, request, response) {
|
|
30
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
31
|
+
let key = Object.keys(request.headers).find(key => key.toLowerCase() === this.header.toLowerCase());
|
|
32
|
+
if (key) {
|
|
33
|
+
let authHeader = request.headers[key];
|
|
34
|
+
if (!Utils_1.Utils.isEmpty(authHeader)) {
|
|
35
|
+
if (this.pattern) {
|
|
36
|
+
//preg_match
|
|
37
|
+
let matches = authHeader.match(this.pattern);
|
|
38
|
+
if (matches && matches.length > 0) {
|
|
39
|
+
authHeader = matches[1];
|
|
40
|
+
}
|
|
41
|
+
else {
|
|
42
|
+
return this.fail(response);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
let identity = yield user.loginByAccessToken(authHeader, "HttpHeaderAuth");
|
|
46
|
+
if (identity === null) {
|
|
47
|
+
this.challenge(response);
|
|
48
|
+
this.handleFailure(response);
|
|
49
|
+
}
|
|
50
|
+
return identity;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
return this.fail(response);
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* @throws UnauthorizedHttpException
|
|
58
|
+
*/
|
|
59
|
+
fail(response) {
|
|
60
|
+
this.challenge(response);
|
|
61
|
+
this.handleFailure(response);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
exports.HttpHeaderAuth = HttpHeaderAuth;
|
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
import { HttpBearerAuth } from "./HttpBearerAuth";
|
|
2
|
-
import { Response, Request } from "express";
|
|
3
|
-
import { WebUser } from "../../web/WebUser";
|
|
4
|
-
export declare class JwtHttpBearerAuth extends HttpBearerAuth {
|
|
5
|
-
/**
|
|
6
|
-
* @var string|array<string, mixed>|Jwt application component ID of the JWT handler, configuration array, or JWT handler object
|
|
7
|
-
* itself. By default it's assumes that component of ID "jwt" has been configured.
|
|
8
|
-
*/
|
|
9
|
-
jwt: string;
|
|
10
|
-
auth: any;
|
|
11
|
-
/**
|
|
12
|
-
* @throws InvalidConfigException
|
|
13
|
-
*/
|
|
14
|
-
init(): void;
|
|
15
|
-
authenticate(user: WebUser, request: Request, response: Response): Promise<any>;
|
|
16
|
-
/**
|
|
17
|
-
* @throws UnauthorizedHttpException
|
|
18
|
-
*/
|
|
19
|
-
fail(response: Response): void;
|
|
20
|
-
}
|
|
1
|
+
import { HttpBearerAuth } from "./HttpBearerAuth";
|
|
2
|
+
import { Response, Request } from "express";
|
|
3
|
+
import { WebUser } from "../../web/WebUser";
|
|
4
|
+
export declare class JwtHttpBearerAuth extends HttpBearerAuth {
|
|
5
|
+
/**
|
|
6
|
+
* @var string|array<string, mixed>|Jwt application component ID of the JWT handler, configuration array, or JWT handler object
|
|
7
|
+
* itself. By default it's assumes that component of ID "jwt" has been configured.
|
|
8
|
+
*/
|
|
9
|
+
jwt: string;
|
|
10
|
+
auth: any;
|
|
11
|
+
/**
|
|
12
|
+
* @throws InvalidConfigException
|
|
13
|
+
*/
|
|
14
|
+
init(): void;
|
|
15
|
+
authenticate(user: WebUser, request: Request, response: Response): Promise<any>;
|
|
16
|
+
/**
|
|
17
|
+
* @throws UnauthorizedHttpException
|
|
18
|
+
*/
|
|
19
|
+
fail(response: Response): void;
|
|
20
|
+
}
|
|
21
21
|
//# sourceMappingURL=JwtHttpBearerAuth.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"JwtHttpBearerAuth.d.ts","sourceRoot":"","sources":["../../../src/filters/auth/JwtHttpBearerAuth.ts"],"names":[],"mappings":"AAOA,OAAO,EAAC,cAAc,EAAC,MAAM,kBAAkB,CAAC;AAEhD,OAAO,EAAC,QAAQ,
|
|
1
|
+
{"version":3,"file":"JwtHttpBearerAuth.d.ts","sourceRoot":"","sources":["../../../src/filters/auth/JwtHttpBearerAuth.ts"],"names":[],"mappings":"AAOA,OAAO,EAAC,cAAc,EAAC,MAAM,kBAAkB,CAAC;AAEhD,OAAO,EAAC,QAAQ,EAAE,OAAO,EAAC,MAAM,SAAS,CAAC;AAC1C,OAAO,EAAC,OAAO,EAAC,MAAM,mBAAmB,CAAC;AAI1C,qBAAa,iBAAkB,SAAQ,cAAc;IACjD;;;OAGG;IACI,GAAG,SAAQ;IACX,IAAI,EAAE,GAAG,CAAQ;IAGxB;;OAEG;IACI,IAAI,IAAI,IAAI;IAWN,YAAY,CAAC,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,QAAQ;IAqC7E;;OAEG;IACI,IAAI,CAAC,QAAQ,EAAE,QAAQ,GAAG,IAAI;CAKxC"}
|
|
@@ -1,81 +1,87 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
-
};
|
|
14
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
exports.JwtHttpBearerAuth = void 0;
|
|
16
|
-
/*
|
|
17
|
-
* Copyright (c) 2021. Chy Bilgisayar Bilisim
|
|
18
|
-
* Author: Cihan Ozturk
|
|
19
|
-
* E-mail: cihan@chy.com.tr
|
|
20
|
-
* Github:https://github.com/cihan53/
|
|
21
|
-
*/
|
|
22
|
-
const BaseChyz_1 = __importDefault(require("../../BaseChyz"));
|
|
23
|
-
const HttpBearerAuth_1 = require("./HttpBearerAuth");
|
|
24
|
-
const
|
|
25
|
-
const JsonWebToken = require("jsonwebtoken");
|
|
26
|
-
class JwtHttpBearerAuth extends HttpBearerAuth_1.HttpBearerAuth {
|
|
27
|
-
constructor() {
|
|
28
|
-
super(...arguments);
|
|
29
|
-
/**
|
|
30
|
-
* @var string|array<string, mixed>|Jwt application component ID of the JWT handler, configuration array, or JWT handler object
|
|
31
|
-
* itself. By default it's assumes that component of ID "jwt" has been configured.
|
|
32
|
-
*/
|
|
33
|
-
this.jwt = 'jwt';
|
|
34
|
-
this.auth = null;
|
|
35
|
-
}
|
|
36
|
-
/**
|
|
37
|
-
* @throws InvalidConfigException
|
|
38
|
-
*/
|
|
39
|
-
init() {
|
|
40
|
-
var _a;
|
|
41
|
-
super.init();
|
|
42
|
-
if (!this.pattern) {
|
|
43
|
-
throw new
|
|
44
|
-
}
|
|
45
|
-
this.user = (_a = BaseChyz_1.default.getComponent("user")) !== null && _a !== void 0 ? _a : null;
|
|
46
|
-
}
|
|
47
|
-
authenticate(user, request, response) {
|
|
48
|
-
return __awaiter(this, arguments, void 0, function* () {
|
|
49
|
-
let autHeader = this.getHeaderByKey(request.headers, this.header);
|
|
50
|
-
if (autHeader == null || (autHeader = this.patternCheck(autHeader, this.pattern)) == null) {
|
|
51
|
-
return null;
|
|
52
|
-
}
|
|
53
|
-
let identity = null;
|
|
54
|
-
let token = null;
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.JwtHttpBearerAuth = void 0;
|
|
16
|
+
/*
|
|
17
|
+
* Copyright (c) 2021. Chy Bilgisayar Bilisim
|
|
18
|
+
* Author: Cihan Ozturk
|
|
19
|
+
* E-mail: cihan@chy.com.tr
|
|
20
|
+
* Github:https://github.com/cihan53/
|
|
21
|
+
*/
|
|
22
|
+
const BaseChyz_1 = __importDefault(require("../../BaseChyz"));
|
|
23
|
+
const HttpBearerAuth_1 = require("./HttpBearerAuth");
|
|
24
|
+
const base_1 = require("../../base");
|
|
25
|
+
const JsonWebToken = require("jsonwebtoken");
|
|
26
|
+
class JwtHttpBearerAuth extends HttpBearerAuth_1.HttpBearerAuth {
|
|
27
|
+
constructor() {
|
|
28
|
+
super(...arguments);
|
|
29
|
+
/**
|
|
30
|
+
* @var string|array<string, mixed>|Jwt application component ID of the JWT handler, configuration array, or JWT handler object
|
|
31
|
+
* itself. By default it's assumes that component of ID "jwt" has been configured.
|
|
32
|
+
*/
|
|
33
|
+
this.jwt = 'jwt';
|
|
34
|
+
this.auth = null;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* @throws InvalidConfigException
|
|
38
|
+
*/
|
|
39
|
+
init() {
|
|
40
|
+
var _a;
|
|
41
|
+
super.init();
|
|
42
|
+
if (!this.pattern) {
|
|
43
|
+
throw new base_1.InvalidConfigException('You must provide pattern to use to extract the HTTP authentication value!');
|
|
44
|
+
}
|
|
45
|
+
this.user = (_a = BaseChyz_1.default.getComponent("user")) !== null && _a !== void 0 ? _a : null;
|
|
46
|
+
}
|
|
47
|
+
authenticate(user, request, response) {
|
|
48
|
+
return __awaiter(this, arguments, void 0, function* () {
|
|
49
|
+
let autHeader = this.getHeaderByKey(request.headers, this.header);
|
|
50
|
+
if (autHeader == null || (autHeader = this.patternCheck(autHeader, this.pattern)) == null) {
|
|
51
|
+
return null;
|
|
52
|
+
}
|
|
53
|
+
let identity = null;
|
|
54
|
+
let token = null;
|
|
55
|
+
try {
|
|
56
|
+
token = JsonWebToken.decode(autHeader[1], { complete: true });
|
|
57
|
+
if (!token) {
|
|
58
|
+
BaseChyz_1.default.warning("Your request was made with invalid or expired JSON Web Token.");
|
|
59
|
+
this.fail(response);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
catch (e) {
|
|
63
|
+
BaseChyz_1.default.warning("Your request was made with invalid or expired JSON Web Token.", autHeader, request.path);
|
|
64
|
+
this.fail(response);
|
|
65
|
+
}
|
|
66
|
+
if (token !== null) {
|
|
67
|
+
if (this.auth != null) {
|
|
68
|
+
identity = yield this.auth(autHeader[1], ...arguments);
|
|
69
|
+
}
|
|
70
|
+
else {
|
|
71
|
+
identity = yield user.loginByAccessToken(autHeader[1], "JwtHttpBearerAuth");
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
if (identity == null)
|
|
75
|
+
this.fail(response);
|
|
76
|
+
return identity;
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* @throws UnauthorizedHttpException
|
|
81
|
+
*/
|
|
82
|
+
fail(response) {
|
|
83
|
+
this.challenge(response);
|
|
84
|
+
this.handleFailure(response);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
exports.JwtHttpBearerAuth = JwtHttpBearerAuth;
|