exodus-framework 2.0.804 → 2.0.806

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.
@@ -70,10 +70,10 @@ class SocketRequest extends _core.default {
70
70
  super();
71
71
  this.socket = socket;
72
72
  this.event = event;
73
- this.auth = this.socket.request.auth;
74
- this.tenant = this.socket.request.tenant;
75
- this.requestor = this.socket.request.requestor;
76
- this.isApplication = this.socket.request.isApplication;
73
+ this.auth = this.socket.auth;
74
+ this.tenant = this.socket.tenant;
75
+ this.requestor = this.socket.requestor;
76
+ this.isApplication = this.socket.isApplication;
77
77
  }
78
78
  send(event, ...data) {
79
79
  this.socket.emit(event, ...data);
@@ -1,11 +1,11 @@
1
1
  import { RequestHandler } from 'express';
2
+ import { Socket } from 'socket.io';
3
+ import { ExtendedError } from 'socket.io/dist/namespace';
2
4
  import HttpController, { SocketController } from '../app/controller';
3
- import { IncomingMessage } from 'http';
4
- import { ServerResponse } from 'http';
5
5
  export declare class AuthenticationMiddleware extends HttpController {
6
6
  decryptToken(required?: boolean): RequestHandler;
7
7
  }
8
8
  export declare class SocketAuthenticationMiddleware extends SocketController {
9
- decryptToken: (req: IncomingMessage, res: ServerResponse, next: (err?: any) => void) => Promise<void>;
9
+ decryptToken: (socket: Socket, next: (err?: ExtendedError) => void) => Promise<void>;
10
10
  }
11
11
  //# sourceMappingURL=authentication.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"authentication.d.ts","sourceRoot":"","sources":["../../src/middlewares/authentication.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAGzC,OAAO,cAAc,EAAE,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AAErE,OAAO,EAAE,eAAe,EAAE,MAAM,MAAM,CAAC;AACvC,OAAO,EAAE,cAAc,EAAE,MAAM,MAAM,CAAC;AAMtC,qBAAa,wBAAyB,SAAQ,cAAc;IAC1D,YAAY,CAAC,QAAQ,GAAE,OAAc,GAAG,cAAc;CAUvD;AAED,qBAAa,8BAA+B,SAAQ,gBAAgB;IAClE,YAAY,QAAe,eAAe,OAAO,cAAc,QAAQ,CAAC,GAAG,CAAC,EAAE,GAAG,KAAK,IAAI,mBAgGxF;CACH"}
1
+ {"version":3,"file":"authentication.d.ts","sourceRoot":"","sources":["../../src/middlewares/authentication.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAEzC,OAAO,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC;AACnC,OAAO,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AAEzD,OAAO,cAAc,EAAE,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AAMrE,qBAAa,wBAAyB,SAAQ,cAAc;IAC1D,YAAY,CAAC,QAAQ,GAAE,OAAc,GAAG,cAAc;CAUvD;AAED,qBAAa,8BAA+B,SAAQ,gBAAgB;IAClE,YAAY,WAAkB,MAAM,QAAQ,CAAC,GAAG,CAAC,EAAE,aAAa,KAAK,IAAI,mBAoFvE;CACH"}
@@ -4,12 +4,12 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.SocketAuthenticationMiddleware = exports.AuthenticationMiddleware = void 0;
7
+ var _dateFns = require("date-fns");
7
8
  var _expressJwt = require("express-jwt");
8
9
  var _app = require("../app");
9
10
  var _controller = _interopRequireWildcard(require("../app/controller"));
10
- var _security = _interopRequireDefault(require("../services/security"));
11
11
  var _models = require("../models");
12
- var _dateFns = require("date-fns");
12
+ var _security = _interopRequireDefault(require("../services/security"));
13
13
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
14
14
  function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
15
15
  function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
@@ -27,27 +27,22 @@ class AuthenticationMiddleware extends _controller.default {
27
27
  }
28
28
  exports.AuthenticationMiddleware = AuthenticationMiddleware;
29
29
  class SocketAuthenticationMiddleware extends _controller.SocketController {
30
- decryptToken = async (req, res, next) => {
31
- const token = req.headers.authorization ? req.headers.authorization.replace('Bearer ', '') : '';
32
- const tenantId = req.headers['X-Exodus-Tenant-ID'];
33
- const applicationId = req.headers['X-Exodus-Application-ID'];
30
+ decryptToken = async (socket, next) => {
31
+ const token = socket.handshake.auth['bearer'] ? socket.handshake.auth['bearer'].replace('Bearer ', '') : '';
32
+ const tenantId = socket.handshake.auth['X-Exodus-Tenant-ID'];
33
+ const applicationId = socket.handshake.auth['X-Exodus-Application-ID'];
34
34
  let isApplication = false;
35
35
  let envUuid = '';
36
36
  try {
37
37
  if (!token) {
38
- const error = new Error('Token ausente');
39
- res.statusCode = 401;
40
- return res.writeContinue();
41
- // return next(error);
38
+ return next(new Error('Token ausente'));
42
39
  }
43
40
  const data = await _security.default.getService().verifySignature(token, _security.default.singleton().getServicePublicKey());
44
41
  if (!data) {
45
- const error = new Error('Token inválido');
46
- res.statusCode = 401;
47
- return res.writeContinue();
42
+ return next(new Error('Token inválido'));
48
43
  }
49
44
  const account = data['account'];
50
- req.auth = {
45
+ socket.auth = {
51
46
  account: account,
52
47
  exp: data.exp || 0,
53
48
  iat: 0,
@@ -70,24 +65,16 @@ class SocketAuthenticationMiddleware extends _controller.SocketController {
70
65
  }
71
66
  });
72
67
  if (!application) {
73
- const error = new Error('Token de aplicação inválido');
74
- res.statusCode = 401;
75
- return res.writeContinue();
68
+ return next(new Error('Token de aplicação inválido'));
76
69
  } else if (!application.active) {
77
- const error = new Error('Token de aplicação desativado');
78
- res.statusCode = 403;
79
- return res.writeContinue();
70
+ return next(new Error('Token de aplicação desativado'));
80
71
  } else if ((0, _dateFns.isBefore)(application.expiresAt, new Date())) {
81
- const error = new Error('Token de aplicação expirado');
82
- res.statusCode = 403;
83
- return res.writeContinue();
72
+ return next(new Error('Token de aplicação expirado'));
84
73
  } else {
85
74
  //valido
86
75
  const data = await _security.default.singleton().verifySignature(applicationId, _security.default.singleton().getServicePublicKey());
87
76
  if (!data) {
88
- const error = new Error('Token de aplicação sem autênticidade');
89
- res.statusCode = 401;
90
- return res.writeContinue();
77
+ return next(new Error('Token de aplicação sem autênticidade'));
91
78
  }
92
79
  requestor.database = data.payload.database;
93
80
  requestor.environmentId = data.payload.envUuid;
@@ -103,15 +90,14 @@ class SocketAuthenticationMiddleware extends _controller.SocketController {
103
90
  requestor.environmentId = account.envUuid;
104
91
  envUuid = account.envUuid;
105
92
  }
106
- req.tenant = {
93
+ socket.tenant = {
107
94
  id: envUuid || _app.Core.settings.getDatabase().service.database
108
95
  };
109
- req.requestor = requestor;
110
- req.isApplication = isApplication;
96
+ socket.requestor = requestor;
97
+ socket.isApplication = isApplication;
111
98
  next();
112
99
  } catch (error) {
113
- res.statusCode = 500;
114
- return res.writeContinue();
100
+ return next(error);
115
101
  }
116
102
  };
117
103
  }
@@ -49,7 +49,7 @@ class SocketIOService extends _service.default {
49
49
  cors
50
50
  });
51
51
  const middleware = new _authentication.SocketAuthenticationMiddleware();
52
- this.server.engine.use(middleware.decryptToken);
52
+ this.server.use(middleware.decryptToken);
53
53
  }
54
54
  static registerRouter(router) {
55
55
  this.getService().mainRouter = router;
package/lib/socket.d.js CHANGED
@@ -1,3 +1,3 @@
1
1
  "use strict";
2
2
 
3
- var _http = require("http");
3
+ var _socket = require("socket.io");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "exodus-framework",
3
- "version": "2.0.804",
3
+ "version": "2.0.806",
4
4
  "description": "Exodus Framework",
5
5
  "author": "jhownpaixao",
6
6
  "license": "ISC",