chyz 1.0.12-rc.24 → 1.0.12-rc.28
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 +46 -9
- package/Examples/Controllers/KeyCloakController.ts +102 -0
- package/Examples/Models/KeycloakUser.ts +66 -0
- package/Examples/index.ts +48 -8
- package/Examples/keycloak.json +7 -0
- package/Examples/log/app.log +5423 -0
- package/Examples/log/errors.log +1139 -0
- package/Examples/package.json +46 -45
- package/Examples/yarn.lock +354 -7
- package/base/BaseError.ts +2 -2
- package/base/DataErrorDbException.ts +1 -1
- package/base/ForbiddenHttpException.ts +1 -1
- package/base/InvalidConfigException.ts +1 -1
- package/base/Model.ts +13 -2
- package/base/NotFoundHttpException.ts +1 -1
- package/base/UnauthorizedHttpException.ts +2 -1
- package/base/ValidationHttpException.ts +1 -1
- package/base/index.ts +1 -1
- package/dist/BaseChyz.js +32 -3
- package/dist/BaseChyz.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/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 +13 -0
- 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/UnauthorizedHttpException.js +1 -1
- package/dist/base/UnauthorizedHttpException.js.map +1 -1
- package/dist/base/ValidationHttpException.js +1 -1
- package/dist/base/ValidationHttpException.js.map +1 -1
- package/dist/base/index.js.map +1 -1
- 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 +40 -8
- package/dist/index.js.map +1 -1
- package/dist/web/User.js +8 -3
- package/dist/web/User.js.map +1 -1
- package/filters/auth/JwtHttpBearerAuth.ts +1 -3
- package/filters/auth/KeyCloakHttpBearerAuth.ts +115 -0
- package/index.ts +22 -6
- package/package.json +2 -1
- package/web/User.ts +9 -5
package/dist/web/User.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
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,
|
|
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,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AA;IAC7B,CAAC;IAEM,WAAW,CAAC,QAAa,EAAE,WAAoB,EAAE,QAAgB;QAEpE,OAAO,IAAI,CAAC;IAChB,CAAC;IAEM,UAAU;IAEjB,CAAC;CACJ;AAvFD,oBAuFC"}
|
|
@@ -21,6 +21,7 @@ export class JwtHttpBearerAuth extends HttpBearerAuth {
|
|
|
21
21
|
public jwt = 'jwt'
|
|
22
22
|
public auth:any = null;
|
|
23
23
|
|
|
24
|
+
|
|
24
25
|
/**
|
|
25
26
|
* @throws InvalidConfigException
|
|
26
27
|
*/
|
|
@@ -39,17 +40,14 @@ export class JwtHttpBearerAuth extends HttpBearerAuth {
|
|
|
39
40
|
{
|
|
40
41
|
|
|
41
42
|
let autHeader = this.getHeaderByKey(request.headers, this.header)
|
|
42
|
-
|
|
43
43
|
if (autHeader == null || (autHeader = this.patternCheck(autHeader, this.pattern)) == null) {
|
|
44
44
|
return null;
|
|
45
45
|
}
|
|
46
46
|
|
|
47
47
|
BaseChyz.debug("JSON Web Token.",autHeader);
|
|
48
|
-
|
|
49
48
|
let identity = null;
|
|
50
49
|
let token = null;
|
|
51
50
|
|
|
52
|
-
|
|
53
51
|
token = JsonWebToken.decode(autHeader[1], {complete: true})
|
|
54
52
|
if (!token) {
|
|
55
53
|
BaseChyz.warning("Your request was made with invalid or expired JSON Web Token.");
|
|
@@ -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 {User} from "../../web/User";
|
|
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: User, 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
CHANGED
|
@@ -1,12 +1,28 @@
|
|
|
1
1
|
export {Request, Response, NextFunction} from "express";
|
|
2
|
-
export
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
2
|
+
export {
|
|
3
|
+
ActionFilter,
|
|
4
|
+
BaseObject,
|
|
5
|
+
BaseError,
|
|
6
|
+
Behavior,
|
|
7
|
+
Component,
|
|
8
|
+
Configurable,
|
|
9
|
+
Controller,
|
|
10
|
+
DbConnection,
|
|
11
|
+
ForbiddenHttpException,
|
|
12
|
+
InvalidConfigException,
|
|
13
|
+
NotFoundHttpException,
|
|
14
|
+
UnauthorizedHttpException,
|
|
15
|
+
DataErrorDbException,
|
|
16
|
+
ValidationHttpException,
|
|
17
|
+
Model,
|
|
18
|
+
RestClient
|
|
19
|
+
} from "./base";
|
|
20
|
+
export {AccessControl, AccessRule} from "./filters";
|
|
21
|
+
export {JwtHttpBearerAuth, HttpBearerAuth, HttpHeaderAuth} from "./filters/auth";
|
|
22
|
+
export {controller, get, post} from "./decorator";
|
|
23
|
+
export * as Utils from "./requiments/Utils";
|
|
7
24
|
export {RouteDefinition} from "./model/RouteDefinition";
|
|
8
25
|
export {User} from "./web/User";
|
|
9
|
-
|
|
10
26
|
import BaseChyz from "./BaseChyz";
|
|
11
27
|
export {BaseChyz}
|
|
12
28
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "chyz",
|
|
3
|
-
"version": "1.0.12-rc.
|
|
3
|
+
"version": "1.0.12-rc.28",
|
|
4
4
|
"description": "Nodejs MicroServis Framework",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -26,6 +26,7 @@
|
|
|
26
26
|
"body-parser": "^1.19.0",
|
|
27
27
|
"dotenv-flow": "^3.2.0",
|
|
28
28
|
"express": "^4.17.1",
|
|
29
|
+
"express-session": "^1.17.2",
|
|
29
30
|
"glob": "^7.1.7",
|
|
30
31
|
"ip": "^1.1.5",
|
|
31
32
|
"jsonwebtoken": "^8.5.1",
|
package/web/User.ts
CHANGED
|
@@ -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
|
}
|