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.
Files changed (153) hide show
  1. package/BaseChyz.d.ts +73 -56
  2. package/BaseChyz.d.ts.map +1 -1
  3. package/BaseChyz.js +569 -404
  4. package/README.md +1 -1
  5. package/base/ActionFilter.d.ts +32 -32
  6. package/base/ActionFilter.d.ts.map +1 -1
  7. package/base/ActionFilter.js +82 -82
  8. package/base/BadRequestHttpException.d.ts +6 -0
  9. package/base/BadRequestHttpException.d.ts.map +1 -0
  10. package/base/BadRequestHttpException.js +17 -0
  11. package/base/BaseError.d.ts +43 -10
  12. package/base/BaseError.d.ts.map +1 -1
  13. package/base/BaseError.js +58 -26
  14. package/base/Behavior.d.ts +3 -3
  15. package/base/Behavior.js +7 -7
  16. package/base/CBaseObject.d.ts +4 -4
  17. package/base/CBaseObject.d.ts.map +1 -1
  18. package/base/CBaseObject.js +16 -16
  19. package/base/CEvents.d.ts +13 -0
  20. package/base/CEvents.d.ts.map +1 -0
  21. package/base/CEvents.js +24 -0
  22. package/base/CRequest.d.ts +1 -1
  23. package/base/CRequest.js +10 -10
  24. package/base/CWebController.d.ts +43 -43
  25. package/base/CWebController.d.ts.map +1 -1
  26. package/base/CWebController.js +81 -74
  27. package/base/Component.d.ts +20 -20
  28. package/base/Component.d.ts.map +1 -1
  29. package/base/Component.js +57 -57
  30. package/base/Configurable.d.ts +2 -2
  31. package/base/Configurable.js +8 -8
  32. package/base/DataErrorDbException.d.ts +5 -5
  33. package/base/DataErrorDbException.d.ts.map +1 -1
  34. package/base/DataErrorDbException.js +17 -17
  35. package/base/DbConnection.d.ts +12 -12
  36. package/base/DbConnection.js +53 -53
  37. package/base/ForbiddenHttpException.d.ts +4 -4
  38. package/base/ForbiddenHttpException.d.ts.map +1 -1
  39. package/base/ForbiddenHttpException.js +16 -16
  40. package/base/InvalidArgumentException.d.ts +5 -5
  41. package/base/InvalidArgumentException.d.ts.map +1 -1
  42. package/base/InvalidArgumentException.js +17 -17
  43. package/base/InvalidConfigException.d.ts +5 -5
  44. package/base/InvalidConfigException.d.ts.map +1 -1
  45. package/base/InvalidConfigException.js +17 -17
  46. package/base/Logs.d.ts +21 -21
  47. package/base/Logs.d.ts.map +1 -1
  48. package/base/Logs.js +57 -57
  49. package/base/Model.d.ts +301 -298
  50. package/base/Model.d.ts.map +1 -1
  51. package/base/Model.js +545 -507
  52. package/base/ModelManager.d.ts +1 -1
  53. package/base/ModelManager.js +19 -19
  54. package/base/NotFoundHttpException.d.ts +5 -5
  55. package/base/NotFoundHttpException.d.ts.map +1 -1
  56. package/base/NotFoundHttpException.js +17 -17
  57. package/base/RestClient.d.ts +6 -6
  58. package/base/RestClient.d.ts.map +1 -1
  59. package/base/RestClient.js +25 -25
  60. package/base/UnauthorizedHttpException.d.ts +5 -5
  61. package/base/UnauthorizedHttpException.d.ts.map +1 -1
  62. package/base/UnauthorizedHttpException.js +17 -17
  63. package/base/ValidationHttpException.d.ts +5 -5
  64. package/base/ValidationHttpException.d.ts.map +1 -1
  65. package/base/ValidationHttpException.js +17 -17
  66. package/base/db/Exception.d.ts +6 -6
  67. package/base/db/Exception.js +15 -15
  68. package/base/index.d.ts +19 -18
  69. package/base/index.d.ts.map +1 -1
  70. package/base/index.js +41 -39
  71. package/decorator/Middleware.d.ts +3 -3
  72. package/decorator/Middleware.js +11 -11
  73. package/decorator/controller.d.ts +2 -2
  74. package/decorator/controller.js +24 -24
  75. package/decorator/delete.d.ts +3 -0
  76. package/decorator/delete.d.ts.map +1 -0
  77. package/decorator/delete.js +36 -0
  78. package/decorator/enums/ControllerDecoratorParams.d.ts +5 -5
  79. package/decorator/enums/ControllerDecoratorParams.js +9 -9
  80. package/decorator/get.d.ts +2 -2
  81. package/decorator/get.js +36 -36
  82. package/decorator/index.d.ts +5 -3
  83. package/decorator/index.d.ts.map +1 -1
  84. package/decorator/index.js +13 -9
  85. package/decorator/post.d.ts +2 -2
  86. package/decorator/post.js +36 -36
  87. package/decorator/put.d.ts +3 -0
  88. package/decorator/put.d.ts.map +1 -0
  89. package/decorator/put.js +36 -0
  90. package/filters/AccessControl.d.ts +12 -12
  91. package/filters/AccessControl.d.ts.map +1 -1
  92. package/filters/AccessControl.js +83 -83
  93. package/filters/AccessRule.d.ts +82 -82
  94. package/filters/AccessRule.d.ts.map +1 -1
  95. package/filters/AccessRule.js +136 -137
  96. package/filters/auth/AuthInterface.d.ts +25 -25
  97. package/filters/auth/AuthInterface.js +2 -2
  98. package/filters/auth/AuthMethod.d.ts +37 -37
  99. package/filters/auth/AuthMethod.d.ts.map +1 -1
  100. package/filters/auth/AuthMethod.js +82 -82
  101. package/filters/auth/HttpBasicAuth.d.ts +23 -22
  102. package/filters/auth/HttpBasicAuth.d.ts.map +1 -1
  103. package/filters/auth/HttpBasicAuth.js +78 -72
  104. package/filters/auth/HttpBearerAuth.d.ts +17 -17
  105. package/filters/auth/HttpBearerAuth.d.ts.map +1 -1
  106. package/filters/auth/HttpBearerAuth.js +33 -32
  107. package/filters/auth/HttpHeaderAuth.d.ts +18 -14
  108. package/filters/auth/HttpHeaderAuth.d.ts.map +1 -1
  109. package/filters/auth/HttpHeaderAuth.js +64 -57
  110. package/filters/auth/JwtHttpBearerAuth.d.ts +20 -20
  111. package/filters/auth/JwtHttpBearerAuth.d.ts.map +1 -1
  112. package/filters/auth/JwtHttpBearerAuth.js +87 -81
  113. package/filters/auth/KeyCloakHttpBearerAuth.d.ts +22 -22
  114. package/filters/auth/KeyCloakHttpBearerAuth.js +116 -116
  115. package/filters/auth/index.d.ts +4 -4
  116. package/filters/auth/index.js +11 -11
  117. package/filters/index.d.ts +2 -2
  118. package/filters/index.js +7 -7
  119. package/index.d.ts +28 -21
  120. package/index.d.ts.map +1 -1
  121. package/index.js +71 -60
  122. package/model/RouteDefinition.d.ts +6 -6
  123. package/model/RouteDefinition.js +8 -8
  124. package/package.json +22 -24
  125. package/rbac/AuthAssignment.d.ts +18 -18
  126. package/rbac/AuthAssignment.js +44 -44
  127. package/rbac/AuthItem.d.ts +26 -26
  128. package/rbac/AuthItem.js +51 -51
  129. package/rbac/AuthItemChild.d.ts +18 -18
  130. package/rbac/AuthItemChild.js +43 -43
  131. package/rbac/AuthManager.d.ts +111 -111
  132. package/rbac/AuthManager.d.ts.map +1 -1
  133. package/rbac/AuthManager.js +356 -355
  134. package/rbac/index.d.ts +5 -0
  135. package/rbac/index.d.ts.map +1 -0
  136. package/rbac/index.js +28 -0
  137. package/requiments/Glob.d.ts +2 -2
  138. package/requiments/Glob.js +10 -10
  139. package/requiments/ReflectUtil.js +24 -24
  140. package/requiments/Utils.d.ts +1 -8
  141. package/requiments/Utils.d.ts.map +1 -1
  142. package/requiments/Utils.js +115 -112
  143. package/validators/BooleanValidator.js +1 -1
  144. package/validators/CompareValidator.js +1 -1
  145. package/validators/DateValidator.js +1 -1
  146. package/validators/EmailValidator.js +1 -1
  147. package/validators/Validator.d.ts +17 -17
  148. package/validators/Validator.js +27 -27
  149. package/web/IdentityInterface.d.ts +55 -54
  150. package/web/IdentityInterface.d.ts.map +1 -1
  151. package/web/IdentityInterface.js +8 -8
  152. package/web/WebUser.d.ts +71 -71
  153. 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
- * @throws InvalidConfigException
39
- */
40
- init() {
41
- var _a;
42
- super.init();
43
- if (!this.pattern) {
44
- throw new base_1.InvalidConfigException('You must provide pattern to use to extract the HTTP authentication value!');
45
- }
46
- this.user = (_a = BaseChyz_1.default.getComponent("user")) !== null && _a !== void 0 ? _a : null;
47
- }
48
- authenticate(user, request, response) {
49
- return __awaiter(this, void 0, void 0, function* () {
50
- let autHeader = this.getHeaderByKey(request.headers, this.header);
51
- if (autHeader == null || (autHeader = this.patternCheck(autHeader, this.pattern)) == null) {
52
- return null;
53
- }
54
- let basicauth = autHeader[1].split(":");
55
- let identity = yield user.loginByAccessToken(basicauth, "HttpBasicAuth");
56
- if (identity === null) {
57
- this.challenge(response);
58
- this.handleFailure(response);
59
- }
60
- return identity;
61
- return null;
62
- });
63
- }
64
- /**
65
- * @throws UnauthorizedHttpException
66
- */
67
- fail(response) {
68
- this.challenge(response);
69
- this.handleFailure(response);
70
- }
71
- }
72
- exports.HttpBasicAuth = HttpBasicAuth;
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): void;
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;CAGtC"}
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
- exports.HttpBearerAuth = HttpBearerAuth;
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;CA0BvE"}
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 null;
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 null;
54
- });
55
- }
56
- }
57
- exports.HttpHeaderAuth = HttpHeaderAuth;
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,EAAC,OAAO,EAAC,MAAM,SAAS,CAAC;AACzC,OAAO,EAAC,OAAO,EAAC,MAAM,mBAAmB,CAAC;AAI1C,qBAAa,iBAAkB,SAAQ,cAAc;IACjD;;;OAGG;IACI,GAAG,SAAQ;IACX,IAAI,EAAC,GAAG,CAAQ;IAGvB;;OAEG;IACI,IAAI,IAAI,IAAI;IAWN,YAAY,CAAC,IAAI,EAAC,OAAO,EAAE,OAAO,EAAC,OAAO,EAAE,QAAQ,EAAC,QAAQ;IAiC1E;;OAEG;IACI,IAAI,CAAC,QAAQ,EAAC,QAAQ,GAAG,IAAI;CAKvC"}
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 InvalidConfigException_1 = require("../../base/InvalidConfigException");
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 InvalidConfigException_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
- token = JsonWebToken.decode(autHeader[1], { complete: true });
56
- if (!token) {
57
- BaseChyz_1.default.warning("Your request was made with invalid or expired JSON Web Token.");
58
- this.fail(response);
59
- }
60
- if (token !== null) {
61
- if (this.auth != null) {
62
- identity = yield this.auth(autHeader[1], ...arguments);
63
- }
64
- else {
65
- identity = yield user.loginByAccessToken(autHeader[1], "JwtHttpBearerAuth");
66
- }
67
- }
68
- if (identity == null)
69
- this.fail(response);
70
- return identity;
71
- });
72
- }
73
- /**
74
- * @throws UnauthorizedHttpException
75
- */
76
- fail(response) {
77
- this.challenge(response);
78
- this.handleFailure(response);
79
- }
80
- }
81
- exports.JwtHttpBearerAuth = JwtHttpBearerAuth;
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;