@bee.js/node 0.0.99 → 0.0.102

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/JWT/beeJWT.js CHANGED
@@ -1,5 +1,6 @@
1
1
  const CryptoJS = require("crypto-js");
2
2
  const log = require("../beeHive/log");
3
+ const bee = { tools: require("../../tools/beeTools") };
3
4
 
4
5
  function base64url(source) {
5
6
  let encodedSource = CryptoJS.enc.Base64.stringify(source);
@@ -66,8 +67,16 @@ module.exports = function token(_payload = null, header = {}, options = {}) {
66
67
 
67
68
  return {
68
69
  ...this,
69
- verify: function (token) {
70
+ verify: function (token, headers = {}) {
70
71
  const secret = global.configs.jwt.secret;
72
+ const apiKey =
73
+ headers["x-api-key"] || headers["api-key"] || headers["apikey"];
74
+
75
+ // Acesso de maquinas via API key (md5 do segredo JWT).
76
+ if (apiKey && apiKey === bee.tools.md5(secret)) {
77
+ return JSON.stringify({ machine: true });
78
+ }
79
+
71
80
  if (!token || typeof token !== "string") return false;
72
81
  const array = token.split(".");
73
82
  if (array.length !== 3) return false;
package/lib/WEB/route.js CHANGED
@@ -15,7 +15,7 @@ module.exports = async function(req, res, next, ignoreMiddlewares = false) {
15
15
  if(global.configs.jwt) {
16
16
  log(`Token verify: ${token}`)
17
17
 
18
- token = beeJWT().verify(token)
18
+ token = beeJWT().verify(token, req.headers)
19
19
 
20
20
  if (token?.error?.message === "TOKEN_EXPIRED")
21
21
  return res.status(token.error.status).send({data: null, error: {message: 'TOKEN_EXPIRED'}, action: 'TOKEN_EXPIRED'})
@@ -29,7 +29,10 @@ module.exports = function () {
29
29
 
30
30
  router[r.method || "get"](
31
31
  r.route,
32
- r.free ? freeRoute : route,
32
+ (req, res, next) => {
33
+ req.routeConfig = r;
34
+ return (r.free ? freeRoute : route)(req, res, next);
35
+ },
33
36
  controller
34
37
  );
35
38
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bee.js/node",
3
- "version": "0.0.99",
3
+ "version": "0.0.102",
4
4
  "description": "A JavaScript framework for making Node.js API´s",
5
5
  "main": "index.js",
6
6
  "scripts": {