exodus-framework 2.0.805 → 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.
package/lib/app/controller.js
CHANGED
@@ -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.
|
74
|
-
this.tenant = this.socket.
|
75
|
-
this.requestor = this.socket.
|
76
|
-
this.isApplication = this.socket.
|
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: (
|
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":"
|
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
|
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 (
|
31
|
-
const token =
|
32
|
-
const tenantId =
|
33
|
-
const applicationId =
|
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
|
-
|
39
|
-
res.statusCode = 401;
|
40
|
-
return next(error);
|
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
|
-
|
46
|
-
res.statusCode = 401;
|
47
|
-
return next(error);
|
42
|
+
return next(new Error('Token inválido'));
|
48
43
|
}
|
49
44
|
const account = data['account'];
|
50
|
-
|
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
|
-
|
74
|
-
res.statusCode = 401;
|
75
|
-
return next(error);
|
68
|
+
return next(new Error('Token de aplicação inválido'));
|
76
69
|
} else if (!application.active) {
|
77
|
-
|
78
|
-
res.statusCode = 403;
|
79
|
-
return next(error);
|
70
|
+
return next(new Error('Token de aplicação desativado'));
|
80
71
|
} else if ((0, _dateFns.isBefore)(application.expiresAt, new Date())) {
|
81
|
-
|
82
|
-
res.statusCode = 403;
|
83
|
-
return next(error);
|
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
|
-
|
89
|
-
res.statusCode = 401;
|
90
|
-
return next(error);
|
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,14 +90,13 @@ class SocketAuthenticationMiddleware extends _controller.SocketController {
|
|
103
90
|
requestor.environmentId = account.envUuid;
|
104
91
|
envUuid = account.envUuid;
|
105
92
|
}
|
106
|
-
|
93
|
+
socket.tenant = {
|
107
94
|
id: envUuid || _app.Core.settings.getDatabase().service.database
|
108
95
|
};
|
109
|
-
|
110
|
-
|
96
|
+
socket.requestor = requestor;
|
97
|
+
socket.isApplication = isApplication;
|
111
98
|
next();
|
112
99
|
} catch (error) {
|
113
|
-
res.statusCode = 500;
|
114
100
|
return next(error);
|
115
101
|
}
|
116
102
|
};
|
package/lib/services/socket.js
CHANGED
@@ -49,7 +49,7 @@ class SocketIOService extends _service.default {
|
|
49
49
|
cors
|
50
50
|
});
|
51
51
|
const middleware = new _authentication.SocketAuthenticationMiddleware();
|
52
|
-
this.server.
|
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