@bee.js/node 0.0.42 → 0.0.44
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/lib/DBA/beeDBA.js +3 -1
- package/lib/JWT/beeJWT.js +46 -56
- package/package.json +4 -4
- package/tools/hash.js +5 -11
package/lib/DBA/beeDBA.js
CHANGED
|
@@ -105,7 +105,9 @@ module.exports.actions = {
|
|
|
105
105
|
|
|
106
106
|
for (let field in model.relations)
|
|
107
107
|
SQL += ` ADD CONSTRAINT ${q(
|
|
108
|
-
`FK_${model.relations[field].split(".")[0]}_X_${
|
|
108
|
+
`FK_${model.relations[field].split(".")[0]}_X_${
|
|
109
|
+
model.table
|
|
110
|
+
}_${field}`.slice(0, 64)
|
|
109
111
|
)}
|
|
110
112
|
FOREIGN KEY (${field})
|
|
111
113
|
REFERENCES ${
|
package/lib/JWT/beeJWT.js
CHANGED
|
@@ -1,73 +1,63 @@
|
|
|
1
|
-
const
|
|
2
|
-
const log
|
|
1
|
+
const HMACSHA256 = require("crypto-js/hmac-sha256");
|
|
2
|
+
const log = require("../beeHive/log");
|
|
3
3
|
|
|
4
4
|
module.exports = function token(_payload = null, header = {}) {
|
|
5
|
+
if (_payload) {
|
|
6
|
+
let { jwt, ...payload } = _payload;
|
|
5
7
|
|
|
6
|
-
if(
|
|
8
|
+
if (!global.configs.jwt && !global.configs.jwt.secret)
|
|
9
|
+
return log("ERROR: no jwt.secret defined in configs.");
|
|
7
10
|
|
|
8
|
-
|
|
11
|
+
let secret = global.configs.jwt.secret;
|
|
12
|
+
let iat = new Date().getTime();
|
|
13
|
+
let exp = new Date().getTime() + 60 * 1000;
|
|
9
14
|
|
|
10
|
-
|
|
15
|
+
header = {
|
|
16
|
+
...header,
|
|
17
|
+
typ: header.typ || "JWT",
|
|
18
|
+
alg: header.alg || "HS256",
|
|
19
|
+
};
|
|
11
20
|
|
|
12
|
-
|
|
13
|
-
let iat = new Date().getTime()
|
|
14
|
-
let exp = new Date().getTime() + 60 * 1000
|
|
15
|
-
|
|
16
|
-
header = {...header,
|
|
17
|
-
typ: header.typ || "JWT",
|
|
18
|
-
alg: header.alg || "HS256"
|
|
19
|
-
}
|
|
21
|
+
payload = { ...payload, iat: iat, exp: exp };
|
|
20
22
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
exp: exp,
|
|
24
|
-
}
|
|
23
|
+
header = JSON.stringify(header);
|
|
24
|
+
header = new Buffer.from(header).toString("base64");
|
|
25
25
|
|
|
26
|
-
|
|
27
|
-
|
|
26
|
+
payload = JSON.stringify(payload);
|
|
27
|
+
payload = new Buffer.from(payload).toString("base64");
|
|
28
28
|
|
|
29
|
-
|
|
30
|
-
|
|
29
|
+
const signature = HMACSHA256(`${header}.${payload}`, secret);
|
|
30
|
+
const token = new Buffer.from(`${header}.${payload}.${signature}`).toString(
|
|
31
|
+
"base64"
|
|
32
|
+
);
|
|
31
33
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
34
|
+
this.data.jwt =
|
|
35
|
+
this.data.jwt && typeof this.data.jwt !== "object"
|
|
36
|
+
? [this.data.jwt]
|
|
37
|
+
: this.data.jwt;
|
|
36
38
|
|
|
37
|
-
|
|
39
|
+
this.data.jwt = !this.data.jwt ? token : this.data.jwt.concat(token);
|
|
38
40
|
|
|
39
|
-
|
|
40
|
-
? [this.data.jwt]
|
|
41
|
-
: this.data.jwt
|
|
41
|
+
this.counters.jwt = (this.counters.jwt || 0) + 1;
|
|
42
42
|
|
|
43
|
-
|
|
44
|
-
? token
|
|
45
|
-
: this.data.jwt.concat(token)
|
|
43
|
+
log("JWT created: " + this.data.jwt);
|
|
46
44
|
|
|
47
|
-
|
|
45
|
+
return this;
|
|
46
|
+
}
|
|
48
47
|
|
|
49
|
-
|
|
48
|
+
return {
|
|
49
|
+
...this,
|
|
50
|
+
verify: function (token) {
|
|
51
|
+
const secret = global.configs.jwt.secret;
|
|
52
|
+
const array = token.split(".");
|
|
53
|
+
const header = array[0];
|
|
54
|
+
const payload = array[1];
|
|
50
55
|
|
|
51
|
-
|
|
52
|
-
}
|
|
56
|
+
const signature = HMACSHA256(`${header}.${payload}`, secret);
|
|
53
57
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
let payload = array[1]
|
|
61
|
-
|
|
62
|
-
let signature = crypto
|
|
63
|
-
.createHmac("sha256", secret)
|
|
64
|
-
.update(`${header}.${payload}`)
|
|
65
|
-
.digest("base64")
|
|
66
|
-
|
|
67
|
-
return token === `${header}.${payload}.${signature}`
|
|
68
|
-
? (new Buffer.from(payload, 'base64')).toString("ascii")
|
|
69
|
-
: false
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
}
|
|
73
|
-
}
|
|
58
|
+
return token === `${header}.${payload}.${signature}`
|
|
59
|
+
? new Buffer.from(payload, "base64").toString("ascii")
|
|
60
|
+
: false;
|
|
61
|
+
},
|
|
62
|
+
};
|
|
63
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bee.js/node",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.44",
|
|
4
4
|
"description": "A JavaScript framework for making Node.js API´s",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -26,15 +26,15 @@
|
|
|
26
26
|
"license": "MIT",
|
|
27
27
|
"dependencies": {
|
|
28
28
|
"body-parser": "^1.19.0",
|
|
29
|
-
"crypto": "^1.
|
|
29
|
+
"crypto-js": "^4.1.1",
|
|
30
30
|
"debug": "^4.1.1",
|
|
31
31
|
"express": "^4.17.1",
|
|
32
|
+
"glob": "^7.1.6",
|
|
32
33
|
"http": "^0.0.1-security",
|
|
33
34
|
"make-error": "^1.3.6",
|
|
34
35
|
"mysql2": "^2.2.5",
|
|
35
36
|
"nodemon": "^2.0.6",
|
|
36
37
|
"util": "^0.12.2",
|
|
37
|
-
"uuid": "^
|
|
38
|
-
"glob": "^7.1.6"
|
|
38
|
+
"uuid": "^9.0.0"
|
|
39
39
|
}
|
|
40
40
|
}
|
package/tools/hash.js
CHANGED
|
@@ -1,13 +1,7 @@
|
|
|
1
|
-
|
|
1
|
+
import sha256 from "crypto-js/sha256";
|
|
2
|
+
import md5 from "crypto-js/md5";
|
|
2
3
|
|
|
3
4
|
module.exports = {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
: "";
|
|
8
|
-
},
|
|
9
|
-
|
|
10
|
-
sha256: function() {
|
|
11
|
-
|
|
12
|
-
},
|
|
13
|
-
}
|
|
5
|
+
md5,
|
|
6
|
+
sha256,
|
|
7
|
+
};
|