chyz 1.0.12-rc.7 → 1.0.13-rc.2
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.ts +76 -14
- package/Chyz.ts +0 -3
- package/Examples/Controllers/ApiController.ts +88 -30
- package/Examples/Controllers/KeyCloakController.ts +100 -0
- package/Examples/Controllers/PublicController.ts +5 -7
- package/Examples/Controllers/SiteController.ts +82 -32
- package/Examples/Models/Categories.ts +36 -0
- package/Examples/Models/Customer.ts +115 -0
- package/Examples/Models/KeycloakUser.ts +66 -0
- package/Examples/Models/Order.ts +64 -0
- package/Examples/Models/OrderItem.ts +27 -0
- package/Examples/Models/ProductModels.ts +50 -0
- package/Examples/Models/ProductToCategories.ts +35 -0
- package/Examples/Models/Products.ts +49 -0
- package/Examples/Models/Stocks.ts +60 -0
- package/Examples/Models/User.ts +66 -35
- package/Examples/Models/UserPermission.ts +37 -0
- package/Examples/index-keycloack.ts +78 -0
- package/Examples/index.ts +16 -15
- package/Examples/keycloak.json +7 -0
- package/Examples/log/app.log +903 -1034
- package/Examples/log/errors.log +79 -256
- package/Examples/package.json +46 -44
- package/Examples/tsconfig.json +1 -1
- package/Examples/yarn.lock +2549 -0
- package/README.md +118 -16
- package/base/ActionFilter.ts +2 -2
- package/base/BaseError.ts +2 -2
- package/base/DataErrorDbException.ts +1 -1
- package/base/DbConnection.ts +8 -2
- package/base/ForbiddenHttpException.ts +1 -1
- package/base/InvalidConfigException.ts +1 -1
- package/base/Model.ts +204 -15
- package/base/NotFoundHttpException.ts +1 -1
- package/base/RestClient.ts +28 -0
- package/base/UnauthorizedHttpException.ts +2 -1
- package/base/ValidationHttpException.ts +14 -0
- package/base/db/Exception.ts +14 -0
- package/base/index.ts +2 -0
- package/dist/BaseChyz.js +72 -25
- package/dist/BaseChyz.js.map +1 -1
- package/dist/Chyz.js.map +1 -1
- package/dist/base/ActionFilter.js +2 -2
- package/dist/base/ActionFilter.js.map +1 -1
- package/dist/base/BaseError.js +2 -2
- package/dist/base/BaseError.js.map +1 -1
- package/dist/base/DataErrorDbException.js +1 -1
- package/dist/base/DataErrorDbException.js.map +1 -1
- package/dist/base/DbConnection.js +9 -2
- package/dist/base/DbConnection.js.map +1 -1
- package/dist/base/ForbiddenHttpException.js +1 -1
- package/dist/base/ForbiddenHttpException.js.map +1 -1
- package/dist/base/InvalidConfigException.js +1 -1
- package/dist/base/InvalidConfigException.js.map +1 -1
- package/dist/base/Model.js +181 -13
- package/dist/base/Model.js.map +1 -1
- package/dist/base/NotFoundHttpException.js +1 -1
- package/dist/base/NotFoundHttpException.js.map +1 -1
- package/dist/base/RestClient.js +27 -0
- package/dist/base/RestClient.js.map +1 -0
- package/dist/base/UnauthorizedHttpException.js +1 -1
- package/dist/base/UnauthorizedHttpException.js.map +1 -1
- package/dist/base/ValidationHttpException.js +18 -0
- package/dist/base/ValidationHttpException.js.map +1 -0
- package/dist/base/db/Exception.js +16 -0
- package/dist/base/db/Exception.js.map +1 -0
- package/dist/base/index.js +2 -0
- package/dist/base/index.js.map +1 -1
- package/dist/filters/AccessControl.js +2 -2
- package/dist/filters/AccessControl.js.map +1 -1
- package/dist/filters/AccessRule.js.map +1 -1
- package/dist/filters/auth/AuthMethod.js +2 -2
- package/dist/filters/auth/AuthMethod.js.map +1 -1
- package/dist/filters/auth/HttpHeaderAuth.js.map +1 -1
- package/dist/filters/auth/JwtHttpBearerAuth.js +1 -0
- package/dist/filters/auth/JwtHttpBearerAuth.js.map +1 -1
- package/dist/filters/auth/KeyCloakHttpBearerAuth.js +117 -0
- package/dist/filters/auth/KeyCloakHttpBearerAuth.js.map +1 -0
- package/dist/index.js +29 -0
- package/dist/index.js.map +1 -0
- package/dist/web/{User.js → WebUser.js} +12 -7
- package/dist/web/WebUser.js.map +1 -0
- package/filters/AccessControl.ts +3 -3
- package/filters/AccessRule.ts +2 -2
- package/filters/auth/AuthMethod.ts +4 -4
- package/filters/auth/HttpHeaderAuth.ts +2 -2
- package/filters/auth/JwtHttpBearerAuth.ts +4 -5
- package/filters/auth/KeyCloakHttpBearerAuth.ts +115 -0
- package/index.ts +14 -0
- package/package.json +55 -52
- package/web/{User.ts → WebUser.ts} +10 -6
- package/.idea/Chy-Nodejs-Framework.iml +0 -12
- package/.idea/jsLibraryMappings.xml +0 -6
- package/.idea/modules.xml +0 -8
- package/.idea/vcs.xml +0 -6
- package/dist/web/User.js.map +0 -1
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2021. Chy Bilgisayar Bilisim
|
|
3
|
+
* Author: Cihan Ozturk
|
|
4
|
+
* E-mail: cihan@chy.com.tr
|
|
5
|
+
* Github:https://github.com/cihan53/
|
|
6
|
+
*/
|
|
7
|
+
import BaseChyz from "../../BaseChyz";
|
|
8
|
+
import {HttpBearerAuth} from "./HttpBearerAuth";
|
|
9
|
+
import {InvalidConfigException} from "../../base/InvalidConfigException";
|
|
10
|
+
import {UnauthorizedHttpException} from "../../base/UnauthorizedHttpException";
|
|
11
|
+
import {Response, Request} from "express";
|
|
12
|
+
import {WebUser} from "../../web/WebUser";
|
|
13
|
+
|
|
14
|
+
const JsonWebToken = require("jsonwebtoken");
|
|
15
|
+
|
|
16
|
+
export class KeyCloakHttpBearerAuth extends HttpBearerAuth {
|
|
17
|
+
/**
|
|
18
|
+
* @var string|array<string, mixed>|Jwt application component ID of the JWT handler, configuration array, or JWT handler object
|
|
19
|
+
* itself. By default it's assumes that component of ID "jwt" has been configured.
|
|
20
|
+
*/
|
|
21
|
+
public jwt = 'jwt'
|
|
22
|
+
public auth: any = null;
|
|
23
|
+
public keycloak: any = null;
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* @throws InvalidConfigException
|
|
28
|
+
*/
|
|
29
|
+
public init(): void {
|
|
30
|
+
super.init();
|
|
31
|
+
|
|
32
|
+
if (!this.pattern) {
|
|
33
|
+
throw new InvalidConfigException('You must provide pattern to use to extract the HTTP authentication value!');
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
this.keycloak = BaseChyz.getMiddlewares("keycloak").keycloak ?? null;
|
|
37
|
+
this.user = BaseChyz.getComponent("user") ?? null;
|
|
38
|
+
this.auth = this.KeyCloakCheck;
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
public async KeyCloakCheck(token: string, request: Request, response: Response,) {
|
|
44
|
+
if (this.keycloak == null) return false;
|
|
45
|
+
// return await this.keycloak.protect('realm:user')(request, response, () => true /*next*/)
|
|
46
|
+
return await this.keycloak.protect()(request, response, () => true /*next*/);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
public async authenticate(user: WebUser, request: Request, response: Response) // BC signature
|
|
51
|
+
{
|
|
52
|
+
|
|
53
|
+
let identity = null;
|
|
54
|
+
let token = null;
|
|
55
|
+
|
|
56
|
+
let autHeader = this.getHeaderByKey(request.headers, this.header)
|
|
57
|
+
if (autHeader == null || (autHeader = this.patternCheck(autHeader, this.pattern)) == null) {
|
|
58
|
+
return null;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
token = JsonWebToken.decode(autHeader[1], {complete: true})
|
|
62
|
+
if (!token) {
|
|
63
|
+
BaseChyz.warning("Your request was made with invalid or expired JSON Web Token.");
|
|
64
|
+
this.fail(response);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
if (token !== null) {
|
|
68
|
+
identity = await this.KeyCloakCheck(autHeader[1], request, response)
|
|
69
|
+
BaseChyz.debug("KeyCloakCheck Result:", identity)
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
if (identity == null || identity == false) this.fail(response)
|
|
73
|
+
|
|
74
|
+
return identity;
|
|
75
|
+
|
|
76
|
+
/* let autHeader = this.getHeaderByKey(request.headers, this.header)
|
|
77
|
+
if (autHeader == null || (autHeader = this.patternCheck(autHeader, this.pattern)) == null) {
|
|
78
|
+
return null;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
BaseChyz.debug("JSON Web Token.",autHeader);
|
|
82
|
+
let identity = null;
|
|
83
|
+
let token = null;
|
|
84
|
+
|
|
85
|
+
token = JsonWebToken.decode(autHeader[1], {complete: true})
|
|
86
|
+
if (!token) {
|
|
87
|
+
BaseChyz.warning("Your request was made with invalid or expired JSON Web Token.");
|
|
88
|
+
this.fail(response);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
if (token !== null) {
|
|
92
|
+
if (this.auth != null) {
|
|
93
|
+
identity = await this.auth(autHeader[1])
|
|
94
|
+
} else {
|
|
95
|
+
identity = await user.loginByAccessToken(autHeader[1], "JwtHttpBearerAuth")
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
if (identity == null) this.fail(response)
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
return identity;*/
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* @throws UnauthorizedHttpException
|
|
109
|
+
*/
|
|
110
|
+
public fail(response: Response): void {
|
|
111
|
+
// this.challenge(response)
|
|
112
|
+
// this.handleFailure(response);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
}
|
package/index.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export {Request, Response, NextFunction} from "express";
|
|
2
|
+
export * from "./base";
|
|
3
|
+
export * from "./filters";
|
|
4
|
+
export {JwtHttpBearerAuth} from "./filters/auth";
|
|
5
|
+
export * from "./decorator";
|
|
6
|
+
export * from "./requiments/Utils";
|
|
7
|
+
export {RouteDefinition} from "./model/RouteDefinition";
|
|
8
|
+
export {WebUser} from "./web/WebUser";
|
|
9
|
+
|
|
10
|
+
import BaseChyz from "./BaseChyz";
|
|
11
|
+
export {BaseChyz}
|
|
12
|
+
|
|
13
|
+
const Chyz = new BaseChyz();
|
|
14
|
+
export default Chyz;
|
package/package.json
CHANGED
|
@@ -1,52 +1,55 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "chyz",
|
|
3
|
-
"version": "1.0.
|
|
4
|
-
"description": "Nodejs MicroServis Framework",
|
|
5
|
-
"main": "dist/
|
|
6
|
-
"scripts": {
|
|
7
|
-
"dev": "nodemon
|
|
8
|
-
"debug": "ts-node
|
|
9
|
-
"build": "npx tsc && xcopy .\\log .\\dist\\log /e /i /h /Y",
|
|
10
|
-
"test": "echo \"Error: no test specified\" && exit 1",
|
|
11
|
-
"postversion": "git push && git push --tags"
|
|
12
|
-
},
|
|
13
|
-
"repository": {
|
|
14
|
-
"type": "git",
|
|
15
|
-
"url": "git+https://github.com/cihan53/Chy-Nodejs-Framework.git"
|
|
16
|
-
},
|
|
17
|
-
"author": "Cihan Ozturk",
|
|
18
|
-
"license": "MIT",
|
|
19
|
-
"bugs": {
|
|
20
|
-
"url": "https://github.com/cihan53/Chy-Nodejs-Framework/issues"
|
|
21
|
-
},
|
|
22
|
-
"homepage": "https://github.com/cihan53/Chy-Nodejs-Framework#readme",
|
|
23
|
-
"dependencies": {
|
|
24
|
-
"
|
|
25
|
-
"
|
|
26
|
-
"
|
|
27
|
-
"
|
|
28
|
-
"
|
|
29
|
-
"
|
|
30
|
-
"
|
|
31
|
-
"
|
|
32
|
-
"
|
|
33
|
-
"
|
|
34
|
-
"
|
|
35
|
-
"
|
|
36
|
-
"
|
|
37
|
-
"
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
"
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
"
|
|
44
|
-
"
|
|
45
|
-
"
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
"
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
1
|
+
{
|
|
2
|
+
"name": "chyz",
|
|
3
|
+
"version": "1.0.13-rc.2",
|
|
4
|
+
"description": "Nodejs MicroServis Framework",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"dev": "nodemon index.ts",
|
|
8
|
+
"debug": "ts-node index.ts",
|
|
9
|
+
"build": "npx tsc && xcopy .\\log .\\dist\\log /e /i /h /Y ",
|
|
10
|
+
"test": "echo \"Error: no test specified\" && exit 1",
|
|
11
|
+
"postversion": "git push && git push --tags"
|
|
12
|
+
},
|
|
13
|
+
"repository": {
|
|
14
|
+
"type": "git",
|
|
15
|
+
"url": "git+https://github.com/cihan53/Chy-Nodejs-Framework.git"
|
|
16
|
+
},
|
|
17
|
+
"author": "Cihan Ozturk",
|
|
18
|
+
"license": "MIT",
|
|
19
|
+
"bugs": {
|
|
20
|
+
"url": "https://github.com/cihan53/Chy-Nodejs-Framework/issues"
|
|
21
|
+
},
|
|
22
|
+
"homepage": "https://github.com/cihan53/Chy-Nodejs-Framework#readme",
|
|
23
|
+
"dependencies": {
|
|
24
|
+
"axios": "^0.23.0",
|
|
25
|
+
"babel-plugin-transform-decorators-legacy": "^1.3.5",
|
|
26
|
+
"body-parser": "^1.19.0",
|
|
27
|
+
"dotenv-flow": "^3.2.0",
|
|
28
|
+
"express": "^4.17.1",
|
|
29
|
+
"express-session": "^1.17.2",
|
|
30
|
+
"glob": "^7.1.7",
|
|
31
|
+
"ip": "^1.1.5",
|
|
32
|
+
"jsonwebtoken": "^8.5.1",
|
|
33
|
+
"lodash": "^4.17.21",
|
|
34
|
+
"log4js": "^6.3.0",
|
|
35
|
+
"method-override": "^3.0.0",
|
|
36
|
+
"passport": "^0.4.1",
|
|
37
|
+
"pg": "^8.7.1",
|
|
38
|
+
"pg-hstore": "^2.3.4",
|
|
39
|
+
"reflect-metadata": "^0.1.13",
|
|
40
|
+
"sequelize": "^6.6.5"
|
|
41
|
+
},
|
|
42
|
+
"devDependencies": {
|
|
43
|
+
"@types/express": "^4.17.13",
|
|
44
|
+
"@types/node": "^16.6.1",
|
|
45
|
+
"@types/validator": "^13.6.3",
|
|
46
|
+
"nodemon": "^2.0.12",
|
|
47
|
+
"ts-node": "^10.2.0",
|
|
48
|
+
"typescript": "^4.3.5"
|
|
49
|
+
},
|
|
50
|
+
"keywords": [
|
|
51
|
+
"Framework",
|
|
52
|
+
"RespAPI",
|
|
53
|
+
"microservice"
|
|
54
|
+
]
|
|
55
|
+
}
|
|
@@ -10,7 +10,7 @@ import {ForbiddenHttpException} from "../base/ForbiddenHttpException";
|
|
|
10
10
|
import {InvalidConfigException} from "../base/InvalidConfigException";
|
|
11
11
|
import {IdentityInterface} from "./IdentityInterface";
|
|
12
12
|
|
|
13
|
-
export class
|
|
13
|
+
export class WebUser extends Component {
|
|
14
14
|
|
|
15
15
|
/**
|
|
16
16
|
* @var string the class name of the [[identity]] object.
|
|
@@ -40,7 +40,7 @@ export class User extends Component {
|
|
|
40
40
|
}
|
|
41
41
|
|
|
42
42
|
public getIsGuest() {
|
|
43
|
-
return this.getIdentity() === null
|
|
43
|
+
return this.getIdentity() === null;
|
|
44
44
|
}
|
|
45
45
|
|
|
46
46
|
public getIdentity(autoRenew = true) {
|
|
@@ -67,12 +67,16 @@ export class User extends Component {
|
|
|
67
67
|
* @param token
|
|
68
68
|
* @param type
|
|
69
69
|
*/
|
|
70
|
-
public async loginByAccessToken(token: any, type:any = null) {
|
|
70
|
+
public async loginByAccessToken(token: any, type: any = null) {
|
|
71
71
|
|
|
72
72
|
let $class = this.identityClass;
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
73
|
+
if ($class.findIdentityByAccessToken) {
|
|
74
|
+
this.identity = await $class.findIdentityByAccessToken(token, type)
|
|
75
|
+
if (this.identity && this.login(this.identity)) {
|
|
76
|
+
return this.identity;
|
|
77
|
+
}
|
|
78
|
+
}else{
|
|
79
|
+
BaseChyz.error("WebUser::findIdentityByAccessToken undefined")
|
|
76
80
|
}
|
|
77
81
|
return null;
|
|
78
82
|
}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
-
<module type="WEB_MODULE" version="4">
|
|
3
|
-
<component name="NewModuleRootManager">
|
|
4
|
-
<content url="file://$MODULE_DIR$">
|
|
5
|
-
<excludeFolder url="file://$MODULE_DIR$/temp" />
|
|
6
|
-
<excludeFolder url="file://$MODULE_DIR$/.tmp" />
|
|
7
|
-
<excludeFolder url="file://$MODULE_DIR$/tmp" />
|
|
8
|
-
</content>
|
|
9
|
-
<orderEntry type="inheritedJdk" />
|
|
10
|
-
<orderEntry type="sourceFolder" forTests="false" />
|
|
11
|
-
</component>
|
|
12
|
-
</module>
|
package/.idea/modules.xml
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
-
<project version="4">
|
|
3
|
-
<component name="ProjectModuleManager">
|
|
4
|
-
<modules>
|
|
5
|
-
<module fileurl="file://$PROJECT_DIR$/.idea/Chy-Nodejs-Framework.iml" filepath="$PROJECT_DIR$/.idea/Chy-Nodejs-Framework.iml" />
|
|
6
|
-
</modules>
|
|
7
|
-
</component>
|
|
8
|
-
</project>
|
package/.idea/vcs.xml
DELETED
package/dist/web/User.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"User.js","sourceRoot":"","sources":["../../web/User.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA;;;;;GAKG;AACH,2DAAmC;AACnC,iDAA4C;AAC5C,2EAAsE;AACtE,2EAAsE;AAGtE,MAAa,IAAK,SAAQ,qBAAS;IAS/B,IAAI,QAAQ;QACR,OAAO,IAAI,CAAC,SAAS,CAAC;IAC1B,CAAC;IAED,IAAI,QAAQ,CAAC,KAAK;QACd,IAAI,CAAC,SAAS,GAAG,KAAK,CAAC;IAC3B,CAAC;IAEM,IAAI;QACP,KAAK,CAAC,IAAI,EAAE,CAAC;QAEb,IAAI,IAAI,CAAC,aAAa,KAAK,IAAI,EAAE;YAC7B,MAAM,IAAI,+CAAsB,CAAC,kCAAkC,CAAC,CAAC;SACxE;QAGD,IAAI,CAAC,aAAa,GAAG,IAAI,IAAI,CAAC,aAAa,EAAE,CAAC;IAElD,CAAC;IAEM,UAAU;QACb,OAAO,IAAI,CAAC,WAAW,EAAE,KAAK,IAAI,CAAE;IACxC,CAAC;IAEM,WAAW,CAAC,SAAS,GAAG,IAAI;QAC/B,OAAO,IAAI,CAAC,SAAS,CAAC;IAC1B,CAAC;IAEM,aAAa;QAEhB,MAAM,IAAI,+CAAsB,CAAC,kBAAQ,CAAC,CAAC,CAAC,gBAAgB,CAAC,CAAC,CAAC;IACnE,CAAC;IAGD;;;;OAIG;IACO,mBAAmB;IAE7B,CAAC;IAED;;;;OAIG;IACU,kBAAkB,CAAC,KAAU,EAAE,OAAW,IAAI;;YAEvD,IAAI,MAAM,GAAG,IAAI,CAAC,aAAa,CAAC;YAChC,IAAI,CAAC,QAAQ,GAAG,MAAM,MAAM,CAAC,yBAAyB,CAAC,KAAK,EAAE,IAAI,CAAC,CAAA;YACnE,IAAI,IAAI,CAAC,QAAQ,IAAI,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,QAAQ,CAAC,EAAE;gBAC5C,OAAO,IAAI,CAAC,QAAQ,CAAC;aACxB;YACD,OAAO,IAAI,CAAC;QAChB,CAAC;KAAA;IAEM,KAAK,CAAC,QAA2B,EAAE,QAAQ,GAAG,CAAC;QAElD,IAAI,IAAI,CAAC,WAAW,CAAC,QAAQ,EAAE,KAAK,EAAE,QAAQ,CAAC,EAAE;SAEhD;QACD,OAAO,CAAC,IAAI,CAAC,UAAU,EAAE,CAAA;IAC7B,CAAC;IAEM,WAAW,CAAC,QAAa,EAAE,WAAoB,EAAE,QAAgB;QAEpE,OAAO,IAAI,CAAC;IAChB,CAAC;IAEM,UAAU;IAEjB,CAAC;CACJ;AAnFD,oBAmFC"}
|