dauth-md-node 0.1.69 → 0.1.70
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/dist/dauth-md-node.cjs.development.js +27 -419
- package/dist/dauth-md-node.cjs.development.js.map +1 -1
- package/dist/dauth-md-node.cjs.production.min.js +1 -1
- package/dist/dauth-md-node.cjs.production.min.js.map +1 -1
- package/dist/dauth-md-node.esm.js +27 -419
- package/dist/dauth-md-node.esm.js.map +1 -1
- package/dist/index.d.ts +2 -2
- package/package.json +1 -1
- package/src/index.ts +4 -55
|
@@ -6,430 +6,38 @@ function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'defau
|
|
|
6
6
|
|
|
7
7
|
var jwt = _interopDefault(require('jsonwebtoken'));
|
|
8
8
|
|
|
9
|
-
function
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
n = r.hasOwnProperty,
|
|
17
|
-
o = Object.defineProperty || function (t, e, r) {
|
|
18
|
-
t[e] = r.value;
|
|
19
|
-
},
|
|
20
|
-
i = "function" == typeof Symbol ? Symbol : {},
|
|
21
|
-
a = i.iterator || "@@iterator",
|
|
22
|
-
c = i.asyncIterator || "@@asyncIterator",
|
|
23
|
-
u = i.toStringTag || "@@toStringTag";
|
|
24
|
-
function define(t, e, r) {
|
|
25
|
-
return Object.defineProperty(t, e, {
|
|
26
|
-
value: r,
|
|
27
|
-
enumerable: !0,
|
|
28
|
-
configurable: !0,
|
|
29
|
-
writable: !0
|
|
30
|
-
}), t[e];
|
|
31
|
-
}
|
|
32
|
-
try {
|
|
33
|
-
define({}, "");
|
|
34
|
-
} catch (t) {
|
|
35
|
-
define = function (t, e, r) {
|
|
36
|
-
return t[e] = r;
|
|
37
|
-
};
|
|
38
|
-
}
|
|
39
|
-
function wrap(t, e, r, n) {
|
|
40
|
-
var i = e && e.prototype instanceof Generator ? e : Generator,
|
|
41
|
-
a = Object.create(i.prototype),
|
|
42
|
-
c = new Context(n || []);
|
|
43
|
-
return o(a, "_invoke", {
|
|
44
|
-
value: makeInvokeMethod(t, r, c)
|
|
45
|
-
}), a;
|
|
46
|
-
}
|
|
47
|
-
function tryCatch(t, e, r) {
|
|
48
|
-
try {
|
|
49
|
-
return {
|
|
50
|
-
type: "normal",
|
|
51
|
-
arg: t.call(e, r)
|
|
52
|
-
};
|
|
53
|
-
} catch (t) {
|
|
54
|
-
return {
|
|
55
|
-
type: "throw",
|
|
56
|
-
arg: t
|
|
57
|
-
};
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
e.wrap = wrap;
|
|
61
|
-
var h = "suspendedStart",
|
|
62
|
-
l = "suspendedYield",
|
|
63
|
-
f = "executing",
|
|
64
|
-
s = "completed",
|
|
65
|
-
y = {};
|
|
66
|
-
function Generator() {}
|
|
67
|
-
function GeneratorFunction() {}
|
|
68
|
-
function GeneratorFunctionPrototype() {}
|
|
69
|
-
var p = {};
|
|
70
|
-
define(p, a, function () {
|
|
71
|
-
return this;
|
|
72
|
-
});
|
|
73
|
-
var d = Object.getPrototypeOf,
|
|
74
|
-
v = d && d(d(values([])));
|
|
75
|
-
v && v !== r && n.call(v, a) && (p = v);
|
|
76
|
-
var g = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(p);
|
|
77
|
-
function defineIteratorMethods(t) {
|
|
78
|
-
["next", "throw", "return"].forEach(function (e) {
|
|
79
|
-
define(t, e, function (t) {
|
|
80
|
-
return this._invoke(e, t);
|
|
9
|
+
var dauth = function dauth(_ref) {
|
|
10
|
+
var ssid = _ref.ssid;
|
|
11
|
+
return function (req, res, next) {
|
|
12
|
+
if (!req.headers.authorization) {
|
|
13
|
+
return res.status(403).send({
|
|
14
|
+
status: 'token-not-found',
|
|
15
|
+
mdKey: 'ensure_auth'
|
|
81
16
|
});
|
|
82
|
-
});
|
|
83
|
-
}
|
|
84
|
-
function AsyncIterator(t, e) {
|
|
85
|
-
function invoke(r, o, i, a) {
|
|
86
|
-
var c = tryCatch(t[r], t, o);
|
|
87
|
-
if ("throw" !== c.type) {
|
|
88
|
-
var u = c.arg,
|
|
89
|
-
h = u.value;
|
|
90
|
-
return h && "object" == typeof h && n.call(h, "__await") ? e.resolve(h.__await).then(function (t) {
|
|
91
|
-
invoke("next", t, i, a);
|
|
92
|
-
}, function (t) {
|
|
93
|
-
invoke("throw", t, i, a);
|
|
94
|
-
}) : e.resolve(h).then(function (t) {
|
|
95
|
-
u.value = t, i(u);
|
|
96
|
-
}, function (t) {
|
|
97
|
-
return invoke("throw", t, i, a);
|
|
98
|
-
});
|
|
99
|
-
}
|
|
100
|
-
a(c.arg);
|
|
101
|
-
}
|
|
102
|
-
var r;
|
|
103
|
-
o(this, "_invoke", {
|
|
104
|
-
value: function (t, n) {
|
|
105
|
-
function callInvokeWithMethodAndArg() {
|
|
106
|
-
return new e(function (e, r) {
|
|
107
|
-
invoke(t, n, e, r);
|
|
108
|
-
});
|
|
109
|
-
}
|
|
110
|
-
return r = r ? r.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg();
|
|
111
|
-
}
|
|
112
|
-
});
|
|
113
|
-
}
|
|
114
|
-
function makeInvokeMethod(e, r, n) {
|
|
115
|
-
var o = h;
|
|
116
|
-
return function (i, a) {
|
|
117
|
-
if (o === f) throw new Error("Generator is already running");
|
|
118
|
-
if (o === s) {
|
|
119
|
-
if ("throw" === i) throw a;
|
|
120
|
-
return {
|
|
121
|
-
value: t,
|
|
122
|
-
done: !0
|
|
123
|
-
};
|
|
124
|
-
}
|
|
125
|
-
for (n.method = i, n.arg = a;;) {
|
|
126
|
-
var c = n.delegate;
|
|
127
|
-
if (c) {
|
|
128
|
-
var u = maybeInvokeDelegate(c, n);
|
|
129
|
-
if (u) {
|
|
130
|
-
if (u === y) continue;
|
|
131
|
-
return u;
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) {
|
|
135
|
-
if (o === h) throw o = s, n.arg;
|
|
136
|
-
n.dispatchException(n.arg);
|
|
137
|
-
} else "return" === n.method && n.abrupt("return", n.arg);
|
|
138
|
-
o = f;
|
|
139
|
-
var p = tryCatch(e, r, n);
|
|
140
|
-
if ("normal" === p.type) {
|
|
141
|
-
if (o = n.done ? s : l, p.arg === y) continue;
|
|
142
|
-
return {
|
|
143
|
-
value: p.arg,
|
|
144
|
-
done: n.done
|
|
145
|
-
};
|
|
146
|
-
}
|
|
147
|
-
"throw" === p.type && (o = s, n.method = "throw", n.arg = p.arg);
|
|
148
|
-
}
|
|
149
|
-
};
|
|
150
|
-
}
|
|
151
|
-
function maybeInvokeDelegate(e, r) {
|
|
152
|
-
var n = r.method,
|
|
153
|
-
o = e.iterator[n];
|
|
154
|
-
if (o === t) return r.delegate = null, "throw" === n && e.iterator.return && (r.method = "return", r.arg = t, maybeInvokeDelegate(e, r), "throw" === r.method) || "return" !== n && (r.method = "throw", r.arg = new TypeError("The iterator does not provide a '" + n + "' method")), y;
|
|
155
|
-
var i = tryCatch(o, e.iterator, r.arg);
|
|
156
|
-
if ("throw" === i.type) return r.method = "throw", r.arg = i.arg, r.delegate = null, y;
|
|
157
|
-
var a = i.arg;
|
|
158
|
-
return a ? a.done ? (r[e.resultName] = a.value, r.next = e.nextLoc, "return" !== r.method && (r.method = "next", r.arg = t), r.delegate = null, y) : a : (r.method = "throw", r.arg = new TypeError("iterator result is not an object"), r.delegate = null, y);
|
|
159
|
-
}
|
|
160
|
-
function pushTryEntry(t) {
|
|
161
|
-
var e = {
|
|
162
|
-
tryLoc: t[0]
|
|
163
|
-
};
|
|
164
|
-
1 in t && (e.catchLoc = t[1]), 2 in t && (e.finallyLoc = t[2], e.afterLoc = t[3]), this.tryEntries.push(e);
|
|
165
|
-
}
|
|
166
|
-
function resetTryEntry(t) {
|
|
167
|
-
var e = t.completion || {};
|
|
168
|
-
e.type = "normal", delete e.arg, t.completion = e;
|
|
169
|
-
}
|
|
170
|
-
function Context(t) {
|
|
171
|
-
this.tryEntries = [{
|
|
172
|
-
tryLoc: "root"
|
|
173
|
-
}], t.forEach(pushTryEntry, this), this.reset(!0);
|
|
174
|
-
}
|
|
175
|
-
function values(e) {
|
|
176
|
-
if (e || "" === e) {
|
|
177
|
-
var r = e[a];
|
|
178
|
-
if (r) return r.call(e);
|
|
179
|
-
if ("function" == typeof e.next) return e;
|
|
180
|
-
if (!isNaN(e.length)) {
|
|
181
|
-
var o = -1,
|
|
182
|
-
i = function next() {
|
|
183
|
-
for (; ++o < e.length;) if (n.call(e, o)) return next.value = e[o], next.done = !1, next;
|
|
184
|
-
return next.value = t, next.done = !0, next;
|
|
185
|
-
};
|
|
186
|
-
return i.next = i;
|
|
187
|
-
}
|
|
188
17
|
}
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
}, e.awrap = function (t) {
|
|
203
|
-
return {
|
|
204
|
-
__await: t
|
|
205
|
-
};
|
|
206
|
-
}, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, c, function () {
|
|
207
|
-
return this;
|
|
208
|
-
}), e.AsyncIterator = AsyncIterator, e.async = function (t, r, n, o, i) {
|
|
209
|
-
void 0 === i && (i = Promise);
|
|
210
|
-
var a = new AsyncIterator(wrap(t, r, n, o), i);
|
|
211
|
-
return e.isGeneratorFunction(r) ? a : a.next().then(function (t) {
|
|
212
|
-
return t.done ? t.value : a.next();
|
|
213
|
-
});
|
|
214
|
-
}, defineIteratorMethods(g), define(g, u, "Generator"), define(g, a, function () {
|
|
215
|
-
return this;
|
|
216
|
-
}), define(g, "toString", function () {
|
|
217
|
-
return "[object Generator]";
|
|
218
|
-
}), e.keys = function (t) {
|
|
219
|
-
var e = Object(t),
|
|
220
|
-
r = [];
|
|
221
|
-
for (var n in e) r.push(n);
|
|
222
|
-
return r.reverse(), function next() {
|
|
223
|
-
for (; r.length;) {
|
|
224
|
-
var t = r.pop();
|
|
225
|
-
if (t in e) return next.value = t, next.done = !1, next;
|
|
226
|
-
}
|
|
227
|
-
return next.done = !0, next;
|
|
228
|
-
};
|
|
229
|
-
}, e.values = values, Context.prototype = {
|
|
230
|
-
constructor: Context,
|
|
231
|
-
reset: function (e) {
|
|
232
|
-
if (this.prev = 0, this.next = 0, this.sent = this._sent = t, this.done = !1, this.delegate = null, this.method = "next", this.arg = t, this.tryEntries.forEach(resetTryEntry), !e) for (var r in this) "t" === r.charAt(0) && n.call(this, r) && !isNaN(+r.slice(1)) && (this[r] = t);
|
|
233
|
-
},
|
|
234
|
-
stop: function () {
|
|
235
|
-
this.done = !0;
|
|
236
|
-
var t = this.tryEntries[0].completion;
|
|
237
|
-
if ("throw" === t.type) throw t.arg;
|
|
238
|
-
return this.rval;
|
|
239
|
-
},
|
|
240
|
-
dispatchException: function (e) {
|
|
241
|
-
if (this.done) throw e;
|
|
242
|
-
var r = this;
|
|
243
|
-
function handle(n, o) {
|
|
244
|
-
return a.type = "throw", a.arg = e, r.next = n, o && (r.method = "next", r.arg = t), !!o;
|
|
245
|
-
}
|
|
246
|
-
for (var o = this.tryEntries.length - 1; o >= 0; --o) {
|
|
247
|
-
var i = this.tryEntries[o],
|
|
248
|
-
a = i.completion;
|
|
249
|
-
if ("root" === i.tryLoc) return handle("end");
|
|
250
|
-
if (i.tryLoc <= this.prev) {
|
|
251
|
-
var c = n.call(i, "catchLoc"),
|
|
252
|
-
u = n.call(i, "finallyLoc");
|
|
253
|
-
if (c && u) {
|
|
254
|
-
if (this.prev < i.catchLoc) return handle(i.catchLoc, !0);
|
|
255
|
-
if (this.prev < i.finallyLoc) return handle(i.finallyLoc);
|
|
256
|
-
} else if (c) {
|
|
257
|
-
if (this.prev < i.catchLoc) return handle(i.catchLoc, !0);
|
|
258
|
-
} else {
|
|
259
|
-
if (!u) throw new Error("try statement without catch or finally");
|
|
260
|
-
if (this.prev < i.finallyLoc) return handle(i.finallyLoc);
|
|
261
|
-
}
|
|
262
|
-
}
|
|
263
|
-
}
|
|
264
|
-
},
|
|
265
|
-
abrupt: function (t, e) {
|
|
266
|
-
for (var r = this.tryEntries.length - 1; r >= 0; --r) {
|
|
267
|
-
var o = this.tryEntries[r];
|
|
268
|
-
if (o.tryLoc <= this.prev && n.call(o, "finallyLoc") && this.prev < o.finallyLoc) {
|
|
269
|
-
var i = o;
|
|
270
|
-
break;
|
|
271
|
-
}
|
|
272
|
-
}
|
|
273
|
-
i && ("break" === t || "continue" === t) && i.tryLoc <= e && e <= i.finallyLoc && (i = null);
|
|
274
|
-
var a = i ? i.completion : {};
|
|
275
|
-
return a.type = t, a.arg = e, i ? (this.method = "next", this.next = i.finallyLoc, y) : this.complete(a);
|
|
276
|
-
},
|
|
277
|
-
complete: function (t, e) {
|
|
278
|
-
if ("throw" === t.type) throw t.arg;
|
|
279
|
-
return "break" === t.type || "continue" === t.type ? this.next = t.arg : "return" === t.type ? (this.rval = this.arg = t.arg, this.method = "return", this.next = "end") : "normal" === t.type && e && (this.next = e), y;
|
|
280
|
-
},
|
|
281
|
-
finish: function (t) {
|
|
282
|
-
for (var e = this.tryEntries.length - 1; e >= 0; --e) {
|
|
283
|
-
var r = this.tryEntries[e];
|
|
284
|
-
if (r.finallyLoc === t) return this.complete(r.completion, r.afterLoc), resetTryEntry(r), y;
|
|
285
|
-
}
|
|
286
|
-
},
|
|
287
|
-
catch: function (t) {
|
|
288
|
-
for (var e = this.tryEntries.length - 1; e >= 0; --e) {
|
|
289
|
-
var r = this.tryEntries[e];
|
|
290
|
-
if (r.tryLoc === t) {
|
|
291
|
-
var n = r.completion;
|
|
292
|
-
if ("throw" === n.type) {
|
|
293
|
-
var o = n.arg;
|
|
294
|
-
resetTryEntry(r);
|
|
295
|
-
}
|
|
296
|
-
return o;
|
|
297
|
-
}
|
|
18
|
+
var token = req.headers.authorization.replace(/['"]+/g, '');
|
|
19
|
+
try {
|
|
20
|
+
var payload = jwt.verify(token, ssid);
|
|
21
|
+
req.auth = payload;
|
|
22
|
+
return next();
|
|
23
|
+
} catch (error) {
|
|
24
|
+
if (error && (error == null ? void 0 : error.message) === 'jwt expired') {
|
|
25
|
+
return res.status(500).send({
|
|
26
|
+
status: 'token-expired',
|
|
27
|
+
message: 'El token ha expirado',
|
|
28
|
+
error: error,
|
|
29
|
+
mdKey: 'ensure_auth'
|
|
30
|
+
});
|
|
298
31
|
}
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
nextLoc: n
|
|
306
|
-
}, "next" === this.method && (this.arg = t), y;
|
|
32
|
+
return res.status(500).send({
|
|
33
|
+
status: 'token-invalid',
|
|
34
|
+
message: 'El token no es válido',
|
|
35
|
+
error: error,
|
|
36
|
+
mdKey: 'ensure_auth'
|
|
37
|
+
});
|
|
307
38
|
}
|
|
308
|
-
}, e;
|
|
309
|
-
}
|
|
310
|
-
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
|
|
311
|
-
try {
|
|
312
|
-
var info = gen[key](arg);
|
|
313
|
-
var value = info.value;
|
|
314
|
-
} catch (error) {
|
|
315
|
-
reject(error);
|
|
316
|
-
return;
|
|
317
|
-
}
|
|
318
|
-
if (info.done) {
|
|
319
|
-
resolve(value);
|
|
320
|
-
} else {
|
|
321
|
-
Promise.resolve(value).then(_next, _throw);
|
|
322
|
-
}
|
|
323
|
-
}
|
|
324
|
-
function _asyncToGenerator(fn) {
|
|
325
|
-
return function () {
|
|
326
|
-
var self = this,
|
|
327
|
-
args = arguments;
|
|
328
|
-
return new Promise(function (resolve, reject) {
|
|
329
|
-
var gen = fn.apply(self, args);
|
|
330
|
-
function _next(value) {
|
|
331
|
-
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
|
|
332
|
-
}
|
|
333
|
-
function _throw(err) {
|
|
334
|
-
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
|
|
335
|
-
}
|
|
336
|
-
_next(undefined);
|
|
337
|
-
});
|
|
338
|
-
};
|
|
339
|
-
}
|
|
340
|
-
|
|
341
|
-
// async function getUser(token: string) {
|
|
342
|
-
// const params = {
|
|
343
|
-
// method: "GET",
|
|
344
|
-
// headers: {
|
|
345
|
-
// Authorization: token,
|
|
346
|
-
// "Content-Type": "application/json",
|
|
347
|
-
// }
|
|
348
|
-
// }
|
|
349
|
-
// const response = await fetch(`http://localhost:4012/api/v1/get-tenant-user/easymediacloud`, params)
|
|
350
|
-
// const data = await response.json()
|
|
351
|
-
// return { response, data }
|
|
352
|
-
// }
|
|
353
|
-
// async function getDauthUser() {
|
|
354
|
-
// const getUserFetch = await getUser()
|
|
355
|
-
// if (getUserFetch.response.status === 404) {
|
|
356
|
-
// return 404
|
|
357
|
-
// // return res.status(404).send({ status: 'domain-not-found', message: 'Dauth domain does not exist' });
|
|
358
|
-
// }
|
|
359
|
-
// if (getUserFetch.response.status === 500) {
|
|
360
|
-
// return 500
|
|
361
|
-
// // return res.status(500).send({ status: 'error', message: 'Dauth server error' });
|
|
362
|
-
// }
|
|
363
|
-
// if (getUserFetch.response.status === 200) {
|
|
364
|
-
// // req.user = getUserFetch.data as any
|
|
365
|
-
// // console.log('node-fetch', req.user);
|
|
366
|
-
// // next()
|
|
367
|
-
// return getUserFetch.data
|
|
368
|
-
// }
|
|
369
|
-
// return null
|
|
370
|
-
// }
|
|
371
|
-
var dauth = /*#__PURE__*/function () {
|
|
372
|
-
var _ref2 = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(_ref) {
|
|
373
|
-
var ssid;
|
|
374
|
-
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
375
|
-
while (1) switch (_context.prev = _context.next) {
|
|
376
|
-
case 0:
|
|
377
|
-
ssid = _ref.ssid;
|
|
378
|
-
return _context.abrupt("return", function (req, res, next) {
|
|
379
|
-
if (!req.headers.authorization) {
|
|
380
|
-
return res.status(403).send({
|
|
381
|
-
status: 'token-not-found',
|
|
382
|
-
mdKey: 'ensure_auth'
|
|
383
|
-
});
|
|
384
|
-
}
|
|
385
|
-
var token = req.headers.authorization.replace(/['"]+/g, '');
|
|
386
|
-
try {
|
|
387
|
-
var payload = jwt.verify(token, ssid);
|
|
388
|
-
req.user = payload;
|
|
389
|
-
// getUser(token).then((getUserFetch: any) => {
|
|
390
|
-
// if (getUserFetch.response.status === 404) {
|
|
391
|
-
// return res.status(404).send({ status: 'domain-not-found', message: 'Dauth domain does not exist' });
|
|
392
|
-
// }
|
|
393
|
-
// if (getUserFetch.response.status === 500) {
|
|
394
|
-
// return res.status(500).send({ status: 'error', message: 'Dauth server error' });
|
|
395
|
-
// }
|
|
396
|
-
// if (getUserFetch.response.status === 200) {
|
|
397
|
-
// req.user = getUserFetch.data
|
|
398
|
-
// console.log('node-fetch npm', req.user);
|
|
399
|
-
// }
|
|
400
|
-
// return next();
|
|
401
|
-
// }).catch((error: any) => {
|
|
402
|
-
// console.log('getDauthUser error', error);
|
|
403
|
-
// return next();
|
|
404
|
-
// })
|
|
405
|
-
next();
|
|
406
|
-
} catch (error) {
|
|
407
|
-
if (error && (error == null ? void 0 : error.message) === 'jwt expired') {
|
|
408
|
-
return res.status(500).send({
|
|
409
|
-
status: 'token-expired',
|
|
410
|
-
message: 'El token ha expirado',
|
|
411
|
-
error: error,
|
|
412
|
-
mdKey: 'ensure_auth'
|
|
413
|
-
});
|
|
414
|
-
}
|
|
415
|
-
return res.status(500).send({
|
|
416
|
-
status: 'token-invalid',
|
|
417
|
-
message: 'El token no es válido',
|
|
418
|
-
error: error,
|
|
419
|
-
mdKey: 'ensure_auth'
|
|
420
|
-
});
|
|
421
|
-
}
|
|
422
|
-
});
|
|
423
|
-
case 2:
|
|
424
|
-
case "end":
|
|
425
|
-
return _context.stop();
|
|
426
|
-
}
|
|
427
|
-
}, _callee);
|
|
428
|
-
}));
|
|
429
|
-
return function dauth(_x) {
|
|
430
|
-
return _ref2.apply(this, arguments);
|
|
431
39
|
};
|
|
432
|
-
}
|
|
40
|
+
};
|
|
433
41
|
|
|
434
42
|
exports.dauth = dauth;
|
|
435
43
|
//# sourceMappingURL=dauth-md-node.cjs.development.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dauth-md-node.cjs.development.js","sources":["../src/index.ts"],"sourcesContent":["import {\n Request,\n NextFunction,\n Response as ExpressResponse,\n Handler,\n} from 'express';\nimport mongoose from 'mongoose';\nimport jwt from 'jsonwebtoken';\n
|
|
1
|
+
{"version":3,"file":"dauth-md-node.cjs.development.js","sources":["../src/index.ts"],"sourcesContent":["import {\n Request,\n NextFunction,\n Response as ExpressResponse,\n Handler,\n} from 'express';\nimport mongoose from 'mongoose';\nimport jwt from 'jsonwebtoken';\n\nexport interface IAccessToken {\n _id: string | mongoose.Types.ObjectId;\n sid: string;\n name: string;\n lastname: string;\n email: string;\n createToken?: number;\n exp?: number;\n iat?: number;\n}\n\ninterface IRequestUser extends Request {\n auth: IAccessToken;\n files: {\n image: { path: string };\n avatar: { path: string };\n };\n headers: {\n authorization: string;\n };\n}\n\ninterface TCustomResponse extends ExpressResponse {\n status(code: number): any;\n send(body?: any): any;\n}\n\nexport const dauth = ({ ssid }: { ssid: string }) => {\n return (\n req: IRequestUser,\n res: TCustomResponse,\n next: NextFunction\n ): Handler | void => {\n if (!req.headers.authorization) {\n return res\n .status(403)\n .send({ status: 'token-not-found', mdKey: 'ensure_auth' });\n }\n const token = req.headers.authorization.replace(/['\"]+/g, '');\n try {\n const payload = jwt.verify(token, ssid as string) as IAccessToken;\n req.auth = payload;\n return next();\n } catch (error) {\n if (error && error?.message === 'jwt expired') {\n return res.status(500).send({\n status: 'token-expired',\n message: 'El token ha expirado',\n error: error,\n mdKey: 'ensure_auth',\n });\n }\n return res.status(500).send({\n status: 'token-invalid',\n message: 'El token no es válido',\n error: error,\n mdKey: 'ensure_auth',\n });\n }\n };\n};\n"],"names":["dauth","_ref","ssid","req","res","next","headers","authorization","status","send","mdKey","token","replace","payload","jwt","verify","auth","error","message"],"mappings":";;;;;;;;IAoCaA,KAAK,GAAG,SAARA,KAAKA,CAAAC,IAAA;MAAMC,IAAI,GAAAD,IAAA,CAAJC,IAAI;EAC1B,OAAO,UACLC,GAAiB,EACjBC,GAAoB,EACpBC,IAAkB;IAElB,IAAI,CAACF,GAAG,CAACG,OAAO,CAACC,aAAa,EAAE;MAC9B,OAAOH,GAAG,CACPI,MAAM,CAAC,GAAG,CAAC,CACXC,IAAI,CAAC;QAAED,MAAM,EAAE,iBAAiB;QAAEE,KAAK,EAAE;OAAe,CAAC;;IAE9D,IAAMC,KAAK,GAAGR,GAAG,CAACG,OAAO,CAACC,aAAa,CAACK,OAAO,CAAC,QAAQ,EAAE,EAAE,CAAC;IAC7D,IAAI;MACF,IAAMC,OAAO,GAAGC,GAAG,CAACC,MAAM,CAACJ,KAAK,EAAET,IAAc,CAAiB;MACjEC,GAAG,CAACa,IAAI,GAAGH,OAAO;MAClB,OAAOR,IAAI,EAAE;KACd,CAAC,OAAOY,KAAK,EAAE;MACd,IAAIA,KAAK,IAAI,CAAAA,KAAK,oBAALA,KAAK,CAAEC,OAAO,MAAK,aAAa,EAAE;QAC7C,OAAOd,GAAG,CAACI,MAAM,CAAC,GAAG,CAAC,CAACC,IAAI,CAAC;UAC1BD,MAAM,EAAE,eAAe;UACvBU,OAAO,EAAE,sBAAsB;UAC/BD,KAAK,EAAEA,KAAK;UACZP,KAAK,EAAE;SACR,CAAC;;MAEJ,OAAON,GAAG,CAACI,MAAM,CAAC,GAAG,CAAC,CAACC,IAAI,CAAC;QAC1BD,MAAM,EAAE,eAAe;QACvBU,OAAO,EAAE,uBAAuB;QAChCD,KAAK,EAAEA,KAAK;QACZP,KAAK,EAAE;OACR,CAAC;;GAEL;AACH;;;;"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e,t=(e=require("jsonwebtoken"))&&"object"==typeof e&&"default"in e?e.default:e;exports.dauth=function(e){var r=e.ssid;return function(e,s,a){if(!e.headers.authorization)return s.status(403).send({status:"token-not-found",mdKey:"ensure_auth"});var n=e.headers.authorization.replace(/['"]+/g,"");try{var u=t.verify(n,r);return e.auth=u,a()}catch(e){return e&&"jwt expired"===(null==e?void 0:e.message)?s.status(500).send({status:"token-expired",message:"El token ha expirado",error:e,mdKey:"ensure_auth"}):s.status(500).send({status:"token-invalid",message:"El token no es válido",error:e,mdKey:"ensure_auth"})}}};
|
|
2
2
|
//# sourceMappingURL=dauth-md-node.cjs.production.min.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dauth-md-node.cjs.production.min.js","sources":["../src/index.ts"],"sourcesContent":["import {\n Request,\n NextFunction,\n Response as ExpressResponse,\n Handler,\n} from 'express';\nimport mongoose from 'mongoose';\nimport jwt from 'jsonwebtoken';\n
|
|
1
|
+
{"version":3,"file":"dauth-md-node.cjs.production.min.js","sources":["../src/index.ts"],"sourcesContent":["import {\n Request,\n NextFunction,\n Response as ExpressResponse,\n Handler,\n} from 'express';\nimport mongoose from 'mongoose';\nimport jwt from 'jsonwebtoken';\n\nexport interface IAccessToken {\n _id: string | mongoose.Types.ObjectId;\n sid: string;\n name: string;\n lastname: string;\n email: string;\n createToken?: number;\n exp?: number;\n iat?: number;\n}\n\ninterface IRequestUser extends Request {\n auth: IAccessToken;\n files: {\n image: { path: string };\n avatar: { path: string };\n };\n headers: {\n authorization: string;\n };\n}\n\ninterface TCustomResponse extends ExpressResponse {\n status(code: number): any;\n send(body?: any): any;\n}\n\nexport const dauth = ({ ssid }: { ssid: string }) => {\n return (\n req: IRequestUser,\n res: TCustomResponse,\n next: NextFunction\n ): Handler | void => {\n if (!req.headers.authorization) {\n return res\n .status(403)\n .send({ status: 'token-not-found', mdKey: 'ensure_auth' });\n }\n const token = req.headers.authorization.replace(/['\"]+/g, '');\n try {\n const payload = jwt.verify(token, ssid as string) as IAccessToken;\n req.auth = payload;\n return next();\n } catch (error) {\n if (error && error?.message === 'jwt expired') {\n return res.status(500).send({\n status: 'token-expired',\n message: 'El token ha expirado',\n error: error,\n mdKey: 'ensure_auth',\n });\n }\n return res.status(500).send({\n status: 'token-invalid',\n message: 'El token no es válido',\n error: error,\n mdKey: 'ensure_auth',\n });\n }\n };\n};\n"],"names":["_ref","ssid","req","res","next","headers","authorization","status","send","mdKey","token","replace","payload","jwt","verify","auth","error","message"],"mappings":"qKAoCqB,SAAHA,OAAMC,EAAID,EAAJC,KACtB,OAAO,SACLC,EACAC,EACAC,GAEA,IAAKF,EAAIG,QAAQC,cACf,OAAOH,EACJI,OAAO,KACPC,KAAK,CAAED,OAAQ,kBAAmBE,MAAO,gBAE9C,IAAMC,EAAQR,EAAIG,QAAQC,cAAcK,QAAQ,SAAU,IAC1D,IACE,IAAMC,EAAUC,EAAIC,OAAOJ,EAAOT,GAElC,OADAC,EAAIa,KAAOH,EACJR,IACP,MAAOY,GACP,OAAIA,GAA4B,uBAAnBA,SAAAA,EAAOC,SACXd,EAAII,OAAO,KAAKC,KAAK,CAC1BD,OAAQ,gBACRU,QAAS,uBACTD,MAAOA,EACPP,MAAO,gBAGJN,EAAII,OAAO,KAAKC,KAAK,CAC1BD,OAAQ,gBACRU,QAAS,wBACTD,MAAOA,EACPP,MAAO"}
|
|
@@ -1,429 +1,37 @@
|
|
|
1
1
|
import jwt from 'jsonwebtoken';
|
|
2
2
|
|
|
3
|
-
function
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
n = r.hasOwnProperty,
|
|
11
|
-
o = Object.defineProperty || function (t, e, r) {
|
|
12
|
-
t[e] = r.value;
|
|
13
|
-
},
|
|
14
|
-
i = "function" == typeof Symbol ? Symbol : {},
|
|
15
|
-
a = i.iterator || "@@iterator",
|
|
16
|
-
c = i.asyncIterator || "@@asyncIterator",
|
|
17
|
-
u = i.toStringTag || "@@toStringTag";
|
|
18
|
-
function define(t, e, r) {
|
|
19
|
-
return Object.defineProperty(t, e, {
|
|
20
|
-
value: r,
|
|
21
|
-
enumerable: !0,
|
|
22
|
-
configurable: !0,
|
|
23
|
-
writable: !0
|
|
24
|
-
}), t[e];
|
|
25
|
-
}
|
|
26
|
-
try {
|
|
27
|
-
define({}, "");
|
|
28
|
-
} catch (t) {
|
|
29
|
-
define = function (t, e, r) {
|
|
30
|
-
return t[e] = r;
|
|
31
|
-
};
|
|
32
|
-
}
|
|
33
|
-
function wrap(t, e, r, n) {
|
|
34
|
-
var i = e && e.prototype instanceof Generator ? e : Generator,
|
|
35
|
-
a = Object.create(i.prototype),
|
|
36
|
-
c = new Context(n || []);
|
|
37
|
-
return o(a, "_invoke", {
|
|
38
|
-
value: makeInvokeMethod(t, r, c)
|
|
39
|
-
}), a;
|
|
40
|
-
}
|
|
41
|
-
function tryCatch(t, e, r) {
|
|
42
|
-
try {
|
|
43
|
-
return {
|
|
44
|
-
type: "normal",
|
|
45
|
-
arg: t.call(e, r)
|
|
46
|
-
};
|
|
47
|
-
} catch (t) {
|
|
48
|
-
return {
|
|
49
|
-
type: "throw",
|
|
50
|
-
arg: t
|
|
51
|
-
};
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
e.wrap = wrap;
|
|
55
|
-
var h = "suspendedStart",
|
|
56
|
-
l = "suspendedYield",
|
|
57
|
-
f = "executing",
|
|
58
|
-
s = "completed",
|
|
59
|
-
y = {};
|
|
60
|
-
function Generator() {}
|
|
61
|
-
function GeneratorFunction() {}
|
|
62
|
-
function GeneratorFunctionPrototype() {}
|
|
63
|
-
var p = {};
|
|
64
|
-
define(p, a, function () {
|
|
65
|
-
return this;
|
|
66
|
-
});
|
|
67
|
-
var d = Object.getPrototypeOf,
|
|
68
|
-
v = d && d(d(values([])));
|
|
69
|
-
v && v !== r && n.call(v, a) && (p = v);
|
|
70
|
-
var g = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(p);
|
|
71
|
-
function defineIteratorMethods(t) {
|
|
72
|
-
["next", "throw", "return"].forEach(function (e) {
|
|
73
|
-
define(t, e, function (t) {
|
|
74
|
-
return this._invoke(e, t);
|
|
3
|
+
var dauth = function dauth(_ref) {
|
|
4
|
+
var ssid = _ref.ssid;
|
|
5
|
+
return function (req, res, next) {
|
|
6
|
+
if (!req.headers.authorization) {
|
|
7
|
+
return res.status(403).send({
|
|
8
|
+
status: 'token-not-found',
|
|
9
|
+
mdKey: 'ensure_auth'
|
|
75
10
|
});
|
|
76
|
-
});
|
|
77
|
-
}
|
|
78
|
-
function AsyncIterator(t, e) {
|
|
79
|
-
function invoke(r, o, i, a) {
|
|
80
|
-
var c = tryCatch(t[r], t, o);
|
|
81
|
-
if ("throw" !== c.type) {
|
|
82
|
-
var u = c.arg,
|
|
83
|
-
h = u.value;
|
|
84
|
-
return h && "object" == typeof h && n.call(h, "__await") ? e.resolve(h.__await).then(function (t) {
|
|
85
|
-
invoke("next", t, i, a);
|
|
86
|
-
}, function (t) {
|
|
87
|
-
invoke("throw", t, i, a);
|
|
88
|
-
}) : e.resolve(h).then(function (t) {
|
|
89
|
-
u.value = t, i(u);
|
|
90
|
-
}, function (t) {
|
|
91
|
-
return invoke("throw", t, i, a);
|
|
92
|
-
});
|
|
93
|
-
}
|
|
94
|
-
a(c.arg);
|
|
95
|
-
}
|
|
96
|
-
var r;
|
|
97
|
-
o(this, "_invoke", {
|
|
98
|
-
value: function (t, n) {
|
|
99
|
-
function callInvokeWithMethodAndArg() {
|
|
100
|
-
return new e(function (e, r) {
|
|
101
|
-
invoke(t, n, e, r);
|
|
102
|
-
});
|
|
103
|
-
}
|
|
104
|
-
return r = r ? r.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg();
|
|
105
|
-
}
|
|
106
|
-
});
|
|
107
|
-
}
|
|
108
|
-
function makeInvokeMethod(e, r, n) {
|
|
109
|
-
var o = h;
|
|
110
|
-
return function (i, a) {
|
|
111
|
-
if (o === f) throw new Error("Generator is already running");
|
|
112
|
-
if (o === s) {
|
|
113
|
-
if ("throw" === i) throw a;
|
|
114
|
-
return {
|
|
115
|
-
value: t,
|
|
116
|
-
done: !0
|
|
117
|
-
};
|
|
118
|
-
}
|
|
119
|
-
for (n.method = i, n.arg = a;;) {
|
|
120
|
-
var c = n.delegate;
|
|
121
|
-
if (c) {
|
|
122
|
-
var u = maybeInvokeDelegate(c, n);
|
|
123
|
-
if (u) {
|
|
124
|
-
if (u === y) continue;
|
|
125
|
-
return u;
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) {
|
|
129
|
-
if (o === h) throw o = s, n.arg;
|
|
130
|
-
n.dispatchException(n.arg);
|
|
131
|
-
} else "return" === n.method && n.abrupt("return", n.arg);
|
|
132
|
-
o = f;
|
|
133
|
-
var p = tryCatch(e, r, n);
|
|
134
|
-
if ("normal" === p.type) {
|
|
135
|
-
if (o = n.done ? s : l, p.arg === y) continue;
|
|
136
|
-
return {
|
|
137
|
-
value: p.arg,
|
|
138
|
-
done: n.done
|
|
139
|
-
};
|
|
140
|
-
}
|
|
141
|
-
"throw" === p.type && (o = s, n.method = "throw", n.arg = p.arg);
|
|
142
|
-
}
|
|
143
|
-
};
|
|
144
|
-
}
|
|
145
|
-
function maybeInvokeDelegate(e, r) {
|
|
146
|
-
var n = r.method,
|
|
147
|
-
o = e.iterator[n];
|
|
148
|
-
if (o === t) return r.delegate = null, "throw" === n && e.iterator.return && (r.method = "return", r.arg = t, maybeInvokeDelegate(e, r), "throw" === r.method) || "return" !== n && (r.method = "throw", r.arg = new TypeError("The iterator does not provide a '" + n + "' method")), y;
|
|
149
|
-
var i = tryCatch(o, e.iterator, r.arg);
|
|
150
|
-
if ("throw" === i.type) return r.method = "throw", r.arg = i.arg, r.delegate = null, y;
|
|
151
|
-
var a = i.arg;
|
|
152
|
-
return a ? a.done ? (r[e.resultName] = a.value, r.next = e.nextLoc, "return" !== r.method && (r.method = "next", r.arg = t), r.delegate = null, y) : a : (r.method = "throw", r.arg = new TypeError("iterator result is not an object"), r.delegate = null, y);
|
|
153
|
-
}
|
|
154
|
-
function pushTryEntry(t) {
|
|
155
|
-
var e = {
|
|
156
|
-
tryLoc: t[0]
|
|
157
|
-
};
|
|
158
|
-
1 in t && (e.catchLoc = t[1]), 2 in t && (e.finallyLoc = t[2], e.afterLoc = t[3]), this.tryEntries.push(e);
|
|
159
|
-
}
|
|
160
|
-
function resetTryEntry(t) {
|
|
161
|
-
var e = t.completion || {};
|
|
162
|
-
e.type = "normal", delete e.arg, t.completion = e;
|
|
163
|
-
}
|
|
164
|
-
function Context(t) {
|
|
165
|
-
this.tryEntries = [{
|
|
166
|
-
tryLoc: "root"
|
|
167
|
-
}], t.forEach(pushTryEntry, this), this.reset(!0);
|
|
168
|
-
}
|
|
169
|
-
function values(e) {
|
|
170
|
-
if (e || "" === e) {
|
|
171
|
-
var r = e[a];
|
|
172
|
-
if (r) return r.call(e);
|
|
173
|
-
if ("function" == typeof e.next) return e;
|
|
174
|
-
if (!isNaN(e.length)) {
|
|
175
|
-
var o = -1,
|
|
176
|
-
i = function next() {
|
|
177
|
-
for (; ++o < e.length;) if (n.call(e, o)) return next.value = e[o], next.done = !1, next;
|
|
178
|
-
return next.value = t, next.done = !0, next;
|
|
179
|
-
};
|
|
180
|
-
return i.next = i;
|
|
181
|
-
}
|
|
182
11
|
}
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
}, e.awrap = function (t) {
|
|
197
|
-
return {
|
|
198
|
-
__await: t
|
|
199
|
-
};
|
|
200
|
-
}, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, c, function () {
|
|
201
|
-
return this;
|
|
202
|
-
}), e.AsyncIterator = AsyncIterator, e.async = function (t, r, n, o, i) {
|
|
203
|
-
void 0 === i && (i = Promise);
|
|
204
|
-
var a = new AsyncIterator(wrap(t, r, n, o), i);
|
|
205
|
-
return e.isGeneratorFunction(r) ? a : a.next().then(function (t) {
|
|
206
|
-
return t.done ? t.value : a.next();
|
|
207
|
-
});
|
|
208
|
-
}, defineIteratorMethods(g), define(g, u, "Generator"), define(g, a, function () {
|
|
209
|
-
return this;
|
|
210
|
-
}), define(g, "toString", function () {
|
|
211
|
-
return "[object Generator]";
|
|
212
|
-
}), e.keys = function (t) {
|
|
213
|
-
var e = Object(t),
|
|
214
|
-
r = [];
|
|
215
|
-
for (var n in e) r.push(n);
|
|
216
|
-
return r.reverse(), function next() {
|
|
217
|
-
for (; r.length;) {
|
|
218
|
-
var t = r.pop();
|
|
219
|
-
if (t in e) return next.value = t, next.done = !1, next;
|
|
220
|
-
}
|
|
221
|
-
return next.done = !0, next;
|
|
222
|
-
};
|
|
223
|
-
}, e.values = values, Context.prototype = {
|
|
224
|
-
constructor: Context,
|
|
225
|
-
reset: function (e) {
|
|
226
|
-
if (this.prev = 0, this.next = 0, this.sent = this._sent = t, this.done = !1, this.delegate = null, this.method = "next", this.arg = t, this.tryEntries.forEach(resetTryEntry), !e) for (var r in this) "t" === r.charAt(0) && n.call(this, r) && !isNaN(+r.slice(1)) && (this[r] = t);
|
|
227
|
-
},
|
|
228
|
-
stop: function () {
|
|
229
|
-
this.done = !0;
|
|
230
|
-
var t = this.tryEntries[0].completion;
|
|
231
|
-
if ("throw" === t.type) throw t.arg;
|
|
232
|
-
return this.rval;
|
|
233
|
-
},
|
|
234
|
-
dispatchException: function (e) {
|
|
235
|
-
if (this.done) throw e;
|
|
236
|
-
var r = this;
|
|
237
|
-
function handle(n, o) {
|
|
238
|
-
return a.type = "throw", a.arg = e, r.next = n, o && (r.method = "next", r.arg = t), !!o;
|
|
239
|
-
}
|
|
240
|
-
for (var o = this.tryEntries.length - 1; o >= 0; --o) {
|
|
241
|
-
var i = this.tryEntries[o],
|
|
242
|
-
a = i.completion;
|
|
243
|
-
if ("root" === i.tryLoc) return handle("end");
|
|
244
|
-
if (i.tryLoc <= this.prev) {
|
|
245
|
-
var c = n.call(i, "catchLoc"),
|
|
246
|
-
u = n.call(i, "finallyLoc");
|
|
247
|
-
if (c && u) {
|
|
248
|
-
if (this.prev < i.catchLoc) return handle(i.catchLoc, !0);
|
|
249
|
-
if (this.prev < i.finallyLoc) return handle(i.finallyLoc);
|
|
250
|
-
} else if (c) {
|
|
251
|
-
if (this.prev < i.catchLoc) return handle(i.catchLoc, !0);
|
|
252
|
-
} else {
|
|
253
|
-
if (!u) throw new Error("try statement without catch or finally");
|
|
254
|
-
if (this.prev < i.finallyLoc) return handle(i.finallyLoc);
|
|
255
|
-
}
|
|
256
|
-
}
|
|
257
|
-
}
|
|
258
|
-
},
|
|
259
|
-
abrupt: function (t, e) {
|
|
260
|
-
for (var r = this.tryEntries.length - 1; r >= 0; --r) {
|
|
261
|
-
var o = this.tryEntries[r];
|
|
262
|
-
if (o.tryLoc <= this.prev && n.call(o, "finallyLoc") && this.prev < o.finallyLoc) {
|
|
263
|
-
var i = o;
|
|
264
|
-
break;
|
|
265
|
-
}
|
|
266
|
-
}
|
|
267
|
-
i && ("break" === t || "continue" === t) && i.tryLoc <= e && e <= i.finallyLoc && (i = null);
|
|
268
|
-
var a = i ? i.completion : {};
|
|
269
|
-
return a.type = t, a.arg = e, i ? (this.method = "next", this.next = i.finallyLoc, y) : this.complete(a);
|
|
270
|
-
},
|
|
271
|
-
complete: function (t, e) {
|
|
272
|
-
if ("throw" === t.type) throw t.arg;
|
|
273
|
-
return "break" === t.type || "continue" === t.type ? this.next = t.arg : "return" === t.type ? (this.rval = this.arg = t.arg, this.method = "return", this.next = "end") : "normal" === t.type && e && (this.next = e), y;
|
|
274
|
-
},
|
|
275
|
-
finish: function (t) {
|
|
276
|
-
for (var e = this.tryEntries.length - 1; e >= 0; --e) {
|
|
277
|
-
var r = this.tryEntries[e];
|
|
278
|
-
if (r.finallyLoc === t) return this.complete(r.completion, r.afterLoc), resetTryEntry(r), y;
|
|
279
|
-
}
|
|
280
|
-
},
|
|
281
|
-
catch: function (t) {
|
|
282
|
-
for (var e = this.tryEntries.length - 1; e >= 0; --e) {
|
|
283
|
-
var r = this.tryEntries[e];
|
|
284
|
-
if (r.tryLoc === t) {
|
|
285
|
-
var n = r.completion;
|
|
286
|
-
if ("throw" === n.type) {
|
|
287
|
-
var o = n.arg;
|
|
288
|
-
resetTryEntry(r);
|
|
289
|
-
}
|
|
290
|
-
return o;
|
|
291
|
-
}
|
|
12
|
+
var token = req.headers.authorization.replace(/['"]+/g, '');
|
|
13
|
+
try {
|
|
14
|
+
var payload = jwt.verify(token, ssid);
|
|
15
|
+
req.auth = payload;
|
|
16
|
+
return next();
|
|
17
|
+
} catch (error) {
|
|
18
|
+
if (error && (error == null ? void 0 : error.message) === 'jwt expired') {
|
|
19
|
+
return res.status(500).send({
|
|
20
|
+
status: 'token-expired',
|
|
21
|
+
message: 'El token ha expirado',
|
|
22
|
+
error: error,
|
|
23
|
+
mdKey: 'ensure_auth'
|
|
24
|
+
});
|
|
292
25
|
}
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
nextLoc: n
|
|
300
|
-
}, "next" === this.method && (this.arg = t), y;
|
|
26
|
+
return res.status(500).send({
|
|
27
|
+
status: 'token-invalid',
|
|
28
|
+
message: 'El token no es válido',
|
|
29
|
+
error: error,
|
|
30
|
+
mdKey: 'ensure_auth'
|
|
31
|
+
});
|
|
301
32
|
}
|
|
302
|
-
}, e;
|
|
303
|
-
}
|
|
304
|
-
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
|
|
305
|
-
try {
|
|
306
|
-
var info = gen[key](arg);
|
|
307
|
-
var value = info.value;
|
|
308
|
-
} catch (error) {
|
|
309
|
-
reject(error);
|
|
310
|
-
return;
|
|
311
|
-
}
|
|
312
|
-
if (info.done) {
|
|
313
|
-
resolve(value);
|
|
314
|
-
} else {
|
|
315
|
-
Promise.resolve(value).then(_next, _throw);
|
|
316
|
-
}
|
|
317
|
-
}
|
|
318
|
-
function _asyncToGenerator(fn) {
|
|
319
|
-
return function () {
|
|
320
|
-
var self = this,
|
|
321
|
-
args = arguments;
|
|
322
|
-
return new Promise(function (resolve, reject) {
|
|
323
|
-
var gen = fn.apply(self, args);
|
|
324
|
-
function _next(value) {
|
|
325
|
-
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
|
|
326
|
-
}
|
|
327
|
-
function _throw(err) {
|
|
328
|
-
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
|
|
329
|
-
}
|
|
330
|
-
_next(undefined);
|
|
331
|
-
});
|
|
332
|
-
};
|
|
333
|
-
}
|
|
334
|
-
|
|
335
|
-
// async function getUser(token: string) {
|
|
336
|
-
// const params = {
|
|
337
|
-
// method: "GET",
|
|
338
|
-
// headers: {
|
|
339
|
-
// Authorization: token,
|
|
340
|
-
// "Content-Type": "application/json",
|
|
341
|
-
// }
|
|
342
|
-
// }
|
|
343
|
-
// const response = await fetch(`http://localhost:4012/api/v1/get-tenant-user/easymediacloud`, params)
|
|
344
|
-
// const data = await response.json()
|
|
345
|
-
// return { response, data }
|
|
346
|
-
// }
|
|
347
|
-
// async function getDauthUser() {
|
|
348
|
-
// const getUserFetch = await getUser()
|
|
349
|
-
// if (getUserFetch.response.status === 404) {
|
|
350
|
-
// return 404
|
|
351
|
-
// // return res.status(404).send({ status: 'domain-not-found', message: 'Dauth domain does not exist' });
|
|
352
|
-
// }
|
|
353
|
-
// if (getUserFetch.response.status === 500) {
|
|
354
|
-
// return 500
|
|
355
|
-
// // return res.status(500).send({ status: 'error', message: 'Dauth server error' });
|
|
356
|
-
// }
|
|
357
|
-
// if (getUserFetch.response.status === 200) {
|
|
358
|
-
// // req.user = getUserFetch.data as any
|
|
359
|
-
// // console.log('node-fetch', req.user);
|
|
360
|
-
// // next()
|
|
361
|
-
// return getUserFetch.data
|
|
362
|
-
// }
|
|
363
|
-
// return null
|
|
364
|
-
// }
|
|
365
|
-
var dauth = /*#__PURE__*/function () {
|
|
366
|
-
var _ref2 = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(_ref) {
|
|
367
|
-
var ssid;
|
|
368
|
-
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
369
|
-
while (1) switch (_context.prev = _context.next) {
|
|
370
|
-
case 0:
|
|
371
|
-
ssid = _ref.ssid;
|
|
372
|
-
return _context.abrupt("return", function (req, res, next) {
|
|
373
|
-
if (!req.headers.authorization) {
|
|
374
|
-
return res.status(403).send({
|
|
375
|
-
status: 'token-not-found',
|
|
376
|
-
mdKey: 'ensure_auth'
|
|
377
|
-
});
|
|
378
|
-
}
|
|
379
|
-
var token = req.headers.authorization.replace(/['"]+/g, '');
|
|
380
|
-
try {
|
|
381
|
-
var payload = jwt.verify(token, ssid);
|
|
382
|
-
req.user = payload;
|
|
383
|
-
// getUser(token).then((getUserFetch: any) => {
|
|
384
|
-
// if (getUserFetch.response.status === 404) {
|
|
385
|
-
// return res.status(404).send({ status: 'domain-not-found', message: 'Dauth domain does not exist' });
|
|
386
|
-
// }
|
|
387
|
-
// if (getUserFetch.response.status === 500) {
|
|
388
|
-
// return res.status(500).send({ status: 'error', message: 'Dauth server error' });
|
|
389
|
-
// }
|
|
390
|
-
// if (getUserFetch.response.status === 200) {
|
|
391
|
-
// req.user = getUserFetch.data
|
|
392
|
-
// console.log('node-fetch npm', req.user);
|
|
393
|
-
// }
|
|
394
|
-
// return next();
|
|
395
|
-
// }).catch((error: any) => {
|
|
396
|
-
// console.log('getDauthUser error', error);
|
|
397
|
-
// return next();
|
|
398
|
-
// })
|
|
399
|
-
next();
|
|
400
|
-
} catch (error) {
|
|
401
|
-
if (error && (error == null ? void 0 : error.message) === 'jwt expired') {
|
|
402
|
-
return res.status(500).send({
|
|
403
|
-
status: 'token-expired',
|
|
404
|
-
message: 'El token ha expirado',
|
|
405
|
-
error: error,
|
|
406
|
-
mdKey: 'ensure_auth'
|
|
407
|
-
});
|
|
408
|
-
}
|
|
409
|
-
return res.status(500).send({
|
|
410
|
-
status: 'token-invalid',
|
|
411
|
-
message: 'El token no es válido',
|
|
412
|
-
error: error,
|
|
413
|
-
mdKey: 'ensure_auth'
|
|
414
|
-
});
|
|
415
|
-
}
|
|
416
|
-
});
|
|
417
|
-
case 2:
|
|
418
|
-
case "end":
|
|
419
|
-
return _context.stop();
|
|
420
|
-
}
|
|
421
|
-
}, _callee);
|
|
422
|
-
}));
|
|
423
|
-
return function dauth(_x) {
|
|
424
|
-
return _ref2.apply(this, arguments);
|
|
425
33
|
};
|
|
426
|
-
}
|
|
34
|
+
};
|
|
427
35
|
|
|
428
36
|
export { dauth };
|
|
429
37
|
//# sourceMappingURL=dauth-md-node.esm.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dauth-md-node.esm.js","sources":["../src/index.ts"],"sourcesContent":["import {\n Request,\n NextFunction,\n Response as ExpressResponse,\n Handler,\n} from 'express';\nimport mongoose from 'mongoose';\nimport jwt from 'jsonwebtoken';\n
|
|
1
|
+
{"version":3,"file":"dauth-md-node.esm.js","sources":["../src/index.ts"],"sourcesContent":["import {\n Request,\n NextFunction,\n Response as ExpressResponse,\n Handler,\n} from 'express';\nimport mongoose from 'mongoose';\nimport jwt from 'jsonwebtoken';\n\nexport interface IAccessToken {\n _id: string | mongoose.Types.ObjectId;\n sid: string;\n name: string;\n lastname: string;\n email: string;\n createToken?: number;\n exp?: number;\n iat?: number;\n}\n\ninterface IRequestUser extends Request {\n auth: IAccessToken;\n files: {\n image: { path: string };\n avatar: { path: string };\n };\n headers: {\n authorization: string;\n };\n}\n\ninterface TCustomResponse extends ExpressResponse {\n status(code: number): any;\n send(body?: any): any;\n}\n\nexport const dauth = ({ ssid }: { ssid: string }) => {\n return (\n req: IRequestUser,\n res: TCustomResponse,\n next: NextFunction\n ): Handler | void => {\n if (!req.headers.authorization) {\n return res\n .status(403)\n .send({ status: 'token-not-found', mdKey: 'ensure_auth' });\n }\n const token = req.headers.authorization.replace(/['\"]+/g, '');\n try {\n const payload = jwt.verify(token, ssid as string) as IAccessToken;\n req.auth = payload;\n return next();\n } catch (error) {\n if (error && error?.message === 'jwt expired') {\n return res.status(500).send({\n status: 'token-expired',\n message: 'El token ha expirado',\n error: error,\n mdKey: 'ensure_auth',\n });\n }\n return res.status(500).send({\n status: 'token-invalid',\n message: 'El token no es válido',\n error: error,\n mdKey: 'ensure_auth',\n });\n }\n };\n};\n"],"names":["dauth","_ref","ssid","req","res","next","headers","authorization","status","send","mdKey","token","replace","payload","jwt","verify","auth","error","message"],"mappings":";;IAoCaA,KAAK,GAAG,SAARA,KAAKA,CAAAC,IAAA;MAAMC,IAAI,GAAAD,IAAA,CAAJC,IAAI;EAC1B,OAAO,UACLC,GAAiB,EACjBC,GAAoB,EACpBC,IAAkB;IAElB,IAAI,CAACF,GAAG,CAACG,OAAO,CAACC,aAAa,EAAE;MAC9B,OAAOH,GAAG,CACPI,MAAM,CAAC,GAAG,CAAC,CACXC,IAAI,CAAC;QAAED,MAAM,EAAE,iBAAiB;QAAEE,KAAK,EAAE;OAAe,CAAC;;IAE9D,IAAMC,KAAK,GAAGR,GAAG,CAACG,OAAO,CAACC,aAAa,CAACK,OAAO,CAAC,QAAQ,EAAE,EAAE,CAAC;IAC7D,IAAI;MACF,IAAMC,OAAO,GAAGC,GAAG,CAACC,MAAM,CAACJ,KAAK,EAAET,IAAc,CAAiB;MACjEC,GAAG,CAACa,IAAI,GAAGH,OAAO;MAClB,OAAOR,IAAI,EAAE;KACd,CAAC,OAAOY,KAAK,EAAE;MACd,IAAIA,KAAK,IAAI,CAAAA,KAAK,oBAALA,KAAK,CAAEC,OAAO,MAAK,aAAa,EAAE;QAC7C,OAAOd,GAAG,CAACI,MAAM,CAAC,GAAG,CAAC,CAACC,IAAI,CAAC;UAC1BD,MAAM,EAAE,eAAe;UACvBU,OAAO,EAAE,sBAAsB;UAC/BD,KAAK,EAAEA,KAAK;UACZP,KAAK,EAAE;SACR,CAAC;;MAEJ,OAAON,GAAG,CAACI,MAAM,CAAC,GAAG,CAAC,CAACC,IAAI,CAAC;QAC1BD,MAAM,EAAE,eAAe;QACvBU,OAAO,EAAE,uBAAuB;QAChCD,KAAK,EAAEA,KAAK;QACZP,KAAK,EAAE;OACR,CAAC;;GAEL;AACH;;;;"}
|
package/dist/index.d.ts
CHANGED
|
@@ -11,7 +11,7 @@ export interface IAccessToken {
|
|
|
11
11
|
iat?: number;
|
|
12
12
|
}
|
|
13
13
|
interface IRequestUser extends Request {
|
|
14
|
-
|
|
14
|
+
auth: IAccessToken;
|
|
15
15
|
files: {
|
|
16
16
|
image: {
|
|
17
17
|
path: string;
|
|
@@ -30,5 +30,5 @@ interface TCustomResponse extends ExpressResponse {
|
|
|
30
30
|
}
|
|
31
31
|
export declare const dauth: ({ ssid }: {
|
|
32
32
|
ssid: string;
|
|
33
|
-
}) =>
|
|
33
|
+
}) => (req: IRequestUser, res: TCustomResponse, next: NextFunction) => Handler | void;
|
|
34
34
|
export {};
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -6,8 +6,6 @@ import {
|
|
|
6
6
|
} from 'express';
|
|
7
7
|
import mongoose from 'mongoose';
|
|
8
8
|
import jwt from 'jsonwebtoken';
|
|
9
|
-
// import fetch from 'node-fetch';
|
|
10
|
-
// const fetch = require('node-fetch');
|
|
11
9
|
|
|
12
10
|
export interface IAccessToken {
|
|
13
11
|
_id: string | mongoose.Types.ObjectId;
|
|
@@ -21,7 +19,7 @@ export interface IAccessToken {
|
|
|
21
19
|
}
|
|
22
20
|
|
|
23
21
|
interface IRequestUser extends Request {
|
|
24
|
-
|
|
22
|
+
auth: IAccessToken;
|
|
25
23
|
files: {
|
|
26
24
|
image: { path: string };
|
|
27
25
|
avatar: { path: string };
|
|
@@ -36,40 +34,7 @@ interface TCustomResponse extends ExpressResponse {
|
|
|
36
34
|
send(body?: any): any;
|
|
37
35
|
}
|
|
38
36
|
|
|
39
|
-
|
|
40
|
-
// const params = {
|
|
41
|
-
// method: "GET",
|
|
42
|
-
// headers: {
|
|
43
|
-
// Authorization: token,
|
|
44
|
-
// "Content-Type": "application/json",
|
|
45
|
-
// }
|
|
46
|
-
// }
|
|
47
|
-
// const response = await fetch(`http://localhost:4012/api/v1/get-tenant-user/easymediacloud`, params)
|
|
48
|
-
// const data = await response.json()
|
|
49
|
-
// return { response, data }
|
|
50
|
-
// }
|
|
51
|
-
|
|
52
|
-
// async function getDauthUser() {
|
|
53
|
-
// const getUserFetch = await getUser()
|
|
54
|
-
// if (getUserFetch.response.status === 404) {
|
|
55
|
-
// return 404
|
|
56
|
-
// // return res.status(404).send({ status: 'domain-not-found', message: 'Dauth domain does not exist' });
|
|
57
|
-
// }
|
|
58
|
-
// if (getUserFetch.response.status === 500) {
|
|
59
|
-
// return 500
|
|
60
|
-
// // return res.status(500).send({ status: 'error', message: 'Dauth server error' });
|
|
61
|
-
// }
|
|
62
|
-
// if (getUserFetch.response.status === 200) {
|
|
63
|
-
// // req.user = getUserFetch.data as any
|
|
64
|
-
// // console.log('node-fetch', req.user);
|
|
65
|
-
// // next()
|
|
66
|
-
// return getUserFetch.data
|
|
67
|
-
// }
|
|
68
|
-
// return null
|
|
69
|
-
// }
|
|
70
|
-
|
|
71
|
-
export const dauth = async ({ ssid }: { ssid: string }) => {
|
|
72
|
-
// const getUser = await getDauthUser()
|
|
37
|
+
export const dauth = ({ ssid }: { ssid: string }) => {
|
|
73
38
|
return (
|
|
74
39
|
req: IRequestUser,
|
|
75
40
|
res: TCustomResponse,
|
|
@@ -83,24 +48,8 @@ export const dauth = async ({ ssid }: { ssid: string }) => {
|
|
|
83
48
|
const token = req.headers.authorization.replace(/['"]+/g, '');
|
|
84
49
|
try {
|
|
85
50
|
const payload = jwt.verify(token, ssid as string) as IAccessToken;
|
|
86
|
-
req.
|
|
87
|
-
|
|
88
|
-
// if (getUserFetch.response.status === 404) {
|
|
89
|
-
// return res.status(404).send({ status: 'domain-not-found', message: 'Dauth domain does not exist' });
|
|
90
|
-
// }
|
|
91
|
-
// if (getUserFetch.response.status === 500) {
|
|
92
|
-
// return res.status(500).send({ status: 'error', message: 'Dauth server error' });
|
|
93
|
-
// }
|
|
94
|
-
// if (getUserFetch.response.status === 200) {
|
|
95
|
-
// req.user = getUserFetch.data
|
|
96
|
-
// console.log('node-fetch npm', req.user);
|
|
97
|
-
// }
|
|
98
|
-
// return next();
|
|
99
|
-
// }).catch((error: any) => {
|
|
100
|
-
// console.log('getDauthUser error', error);
|
|
101
|
-
// return next();
|
|
102
|
-
// })
|
|
103
|
-
next();
|
|
51
|
+
req.auth = payload;
|
|
52
|
+
return next();
|
|
104
53
|
} catch (error) {
|
|
105
54
|
if (error && error?.message === 'jwt expired') {
|
|
106
55
|
return res.status(500).send({
|