@vulkano/core 1.15.0 → 1.15.2

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.
Files changed (2) hide show
  1. package/libs/Jwt.js +39 -9
  2. package/package.json +1 -1
package/libs/Jwt.js CHANGED
@@ -74,13 +74,18 @@ module.exports = {
74
74
  ? req.cookies[cookieName]
75
75
  : null;
76
76
 
77
+ // Get Token via Cookie RAW
78
+ const cookieTokenRaw = req.headers.cookie && this.getCookieRAW(req, cookieName)
79
+ ? this.getCookieRAW(req, cookieName)
80
+ : null;
81
+
77
82
  // Get Token via Query Parameter
78
83
  const queryToken = req.query && req.query[queryParameter]
79
84
  ? req.query[queryParameter]
80
85
  : null;
81
86
 
82
87
  // Current Token
83
- const token = headerToken || cookieToken || queryToken || null;
88
+ const token = headerToken || cookieToken || cookieTokenRaw || queryToken || null;
84
89
 
85
90
  // Decode Token
86
91
  const hasData = this.decode(token);
@@ -202,25 +207,50 @@ module.exports = {
202
207
  */
203
208
  socket(socket) {
204
209
 
205
- const {
210
+ let {
206
211
  token
207
212
  } = socket.handshake.auth || {};
208
213
 
209
214
  if (token === null || typeof token === 'undefined' || !token) {
210
- return false;
215
+ token = this.getToken(socket.handshake);
216
+ if (!token) {
217
+ return null;
218
+ }
211
219
  }
212
220
 
221
+ // Decode Token
213
222
  const data = this.decode(token);
214
223
 
224
+ // Return only if token is valid
225
+ return data ? data : null;
226
+
227
+ },
228
+
229
+ /**
230
+ * Read cookie RAW
231
+ *
232
+ * @param {Socket} socket
233
+ * @returns String
234
+ */
235
+ getCookieRAW(req, cookieName) {
236
+
215
237
  const {
216
- _id
217
- } = data || {};
238
+ cookie
239
+ } = req.headers || {};
218
240
 
219
- if (!_id) {
220
- return false;
221
- }
241
+ const name = `${cookieName}=`;
242
+ const cDecoded = decodeURIComponent(cookie || '');
243
+ const cArr = cDecoded.split(';');
222
244
 
223
- return data;
245
+ let res;
246
+
247
+ cArr.forEach((val) => {
248
+ if (String(val).trim().indexOf(name) === 0) {
249
+ res = String(val).trim().substring(name.length);
250
+ }
251
+ });
252
+
253
+ return res;
224
254
 
225
255
  }
226
256
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vulkano/core",
3
- "version": "1.15.0",
3
+ "version": "1.15.2",
4
4
  "description": "A MVC framework using Express 4",
5
5
  "license": "MIT",
6
6
  "author": "Vulkano Team",