dauth-md-node 0.1.61 → 0.1.62
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 +447 -27
- 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 +447 -27
- package/dist/dauth-md-node.esm.js.map +1 -1
- package/dist/index.d.ts +2 -2
- package/package.json +3 -2
- package/src/index.ts +61 -3
|
@@ -5,39 +5,459 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
5
5
|
function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }
|
|
6
6
|
|
|
7
7
|
var jwt = _interopDefault(require('jsonwebtoken'));
|
|
8
|
+
var fetch = _interopDefault(require('node-fetch'));
|
|
8
9
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
10
|
+
function _regeneratorRuntime() {
|
|
11
|
+
_regeneratorRuntime = function () {
|
|
12
|
+
return e;
|
|
13
|
+
};
|
|
14
|
+
var t,
|
|
15
|
+
e = {},
|
|
16
|
+
r = Object.prototype,
|
|
17
|
+
n = r.hasOwnProperty,
|
|
18
|
+
o = Object.defineProperty || function (t, e, r) {
|
|
19
|
+
t[e] = r.value;
|
|
20
|
+
},
|
|
21
|
+
i = "function" == typeof Symbol ? Symbol : {},
|
|
22
|
+
a = i.iterator || "@@iterator",
|
|
23
|
+
c = i.asyncIterator || "@@asyncIterator",
|
|
24
|
+
u = i.toStringTag || "@@toStringTag";
|
|
25
|
+
function define(t, e, r) {
|
|
26
|
+
return Object.defineProperty(t, e, {
|
|
27
|
+
value: r,
|
|
28
|
+
enumerable: !0,
|
|
29
|
+
configurable: !0,
|
|
30
|
+
writable: !0
|
|
31
|
+
}), t[e];
|
|
32
|
+
}
|
|
33
|
+
try {
|
|
34
|
+
define({}, "");
|
|
35
|
+
} catch (t) {
|
|
36
|
+
define = function (t, e, r) {
|
|
37
|
+
return t[e] = r;
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
function wrap(t, e, r, n) {
|
|
41
|
+
var i = e && e.prototype instanceof Generator ? e : Generator,
|
|
42
|
+
a = Object.create(i.prototype),
|
|
43
|
+
c = new Context(n || []);
|
|
44
|
+
return o(a, "_invoke", {
|
|
45
|
+
value: makeInvokeMethod(t, r, c)
|
|
46
|
+
}), a;
|
|
47
|
+
}
|
|
48
|
+
function tryCatch(t, e, r) {
|
|
19
49
|
try {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
50
|
+
return {
|
|
51
|
+
type: "normal",
|
|
52
|
+
arg: t.call(e, r)
|
|
53
|
+
};
|
|
54
|
+
} catch (t) {
|
|
55
|
+
return {
|
|
56
|
+
type: "throw",
|
|
57
|
+
arg: t
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
e.wrap = wrap;
|
|
62
|
+
var h = "suspendedStart",
|
|
63
|
+
l = "suspendedYield",
|
|
64
|
+
f = "executing",
|
|
65
|
+
s = "completed",
|
|
66
|
+
y = {};
|
|
67
|
+
function Generator() {}
|
|
68
|
+
function GeneratorFunction() {}
|
|
69
|
+
function GeneratorFunctionPrototype() {}
|
|
70
|
+
var p = {};
|
|
71
|
+
define(p, a, function () {
|
|
72
|
+
return this;
|
|
73
|
+
});
|
|
74
|
+
var d = Object.getPrototypeOf,
|
|
75
|
+
v = d && d(d(values([])));
|
|
76
|
+
v && v !== r && n.call(v, a) && (p = v);
|
|
77
|
+
var g = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(p);
|
|
78
|
+
function defineIteratorMethods(t) {
|
|
79
|
+
["next", "throw", "return"].forEach(function (e) {
|
|
80
|
+
define(t, e, function (t) {
|
|
81
|
+
return this._invoke(e, t);
|
|
82
|
+
});
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
function AsyncIterator(t, e) {
|
|
86
|
+
function invoke(r, o, i, a) {
|
|
87
|
+
var c = tryCatch(t[r], t, o);
|
|
88
|
+
if ("throw" !== c.type) {
|
|
89
|
+
var u = c.arg,
|
|
90
|
+
h = u.value;
|
|
91
|
+
return h && "object" == typeof h && n.call(h, "__await") ? e.resolve(h.__await).then(function (t) {
|
|
92
|
+
invoke("next", t, i, a);
|
|
93
|
+
}, function (t) {
|
|
94
|
+
invoke("throw", t, i, a);
|
|
95
|
+
}) : e.resolve(h).then(function (t) {
|
|
96
|
+
u.value = t, i(u);
|
|
97
|
+
}, function (t) {
|
|
98
|
+
return invoke("throw", t, i, a);
|
|
30
99
|
});
|
|
31
100
|
}
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
101
|
+
a(c.arg);
|
|
102
|
+
}
|
|
103
|
+
var r;
|
|
104
|
+
o(this, "_invoke", {
|
|
105
|
+
value: function (t, n) {
|
|
106
|
+
function callInvokeWithMethodAndArg() {
|
|
107
|
+
return new e(function (e, r) {
|
|
108
|
+
invoke(t, n, e, r);
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
return r = r ? r.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg();
|
|
112
|
+
}
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
function makeInvokeMethod(e, r, n) {
|
|
116
|
+
var o = h;
|
|
117
|
+
return function (i, a) {
|
|
118
|
+
if (o === f) throw new Error("Generator is already running");
|
|
119
|
+
if (o === s) {
|
|
120
|
+
if ("throw" === i) throw a;
|
|
121
|
+
return {
|
|
122
|
+
value: t,
|
|
123
|
+
done: !0
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
for (n.method = i, n.arg = a;;) {
|
|
127
|
+
var c = n.delegate;
|
|
128
|
+
if (c) {
|
|
129
|
+
var u = maybeInvokeDelegate(c, n);
|
|
130
|
+
if (u) {
|
|
131
|
+
if (u === y) continue;
|
|
132
|
+
return u;
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) {
|
|
136
|
+
if (o === h) throw o = s, n.arg;
|
|
137
|
+
n.dispatchException(n.arg);
|
|
138
|
+
} else "return" === n.method && n.abrupt("return", n.arg);
|
|
139
|
+
o = f;
|
|
140
|
+
var p = tryCatch(e, r, n);
|
|
141
|
+
if ("normal" === p.type) {
|
|
142
|
+
if (o = n.done ? s : l, p.arg === y) continue;
|
|
143
|
+
return {
|
|
144
|
+
value: p.arg,
|
|
145
|
+
done: n.done
|
|
146
|
+
};
|
|
147
|
+
}
|
|
148
|
+
"throw" === p.type && (o = s, n.method = "throw", n.arg = p.arg);
|
|
149
|
+
}
|
|
150
|
+
};
|
|
151
|
+
}
|
|
152
|
+
function maybeInvokeDelegate(e, r) {
|
|
153
|
+
var n = r.method,
|
|
154
|
+
o = e.iterator[n];
|
|
155
|
+
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;
|
|
156
|
+
var i = tryCatch(o, e.iterator, r.arg);
|
|
157
|
+
if ("throw" === i.type) return r.method = "throw", r.arg = i.arg, r.delegate = null, y;
|
|
158
|
+
var a = i.arg;
|
|
159
|
+
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);
|
|
160
|
+
}
|
|
161
|
+
function pushTryEntry(t) {
|
|
162
|
+
var e = {
|
|
163
|
+
tryLoc: t[0]
|
|
164
|
+
};
|
|
165
|
+
1 in t && (e.catchLoc = t[1]), 2 in t && (e.finallyLoc = t[2], e.afterLoc = t[3]), this.tryEntries.push(e);
|
|
166
|
+
}
|
|
167
|
+
function resetTryEntry(t) {
|
|
168
|
+
var e = t.completion || {};
|
|
169
|
+
e.type = "normal", delete e.arg, t.completion = e;
|
|
170
|
+
}
|
|
171
|
+
function Context(t) {
|
|
172
|
+
this.tryEntries = [{
|
|
173
|
+
tryLoc: "root"
|
|
174
|
+
}], t.forEach(pushTryEntry, this), this.reset(!0);
|
|
175
|
+
}
|
|
176
|
+
function values(e) {
|
|
177
|
+
if (e || "" === e) {
|
|
178
|
+
var r = e[a];
|
|
179
|
+
if (r) return r.call(e);
|
|
180
|
+
if ("function" == typeof e.next) return e;
|
|
181
|
+
if (!isNaN(e.length)) {
|
|
182
|
+
var o = -1,
|
|
183
|
+
i = function next() {
|
|
184
|
+
for (; ++o < e.length;) if (n.call(e, o)) return next.value = e[o], next.done = !1, next;
|
|
185
|
+
return next.value = t, next.done = !0, next;
|
|
186
|
+
};
|
|
187
|
+
return i.next = i;
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
throw new TypeError(typeof e + " is not iterable");
|
|
191
|
+
}
|
|
192
|
+
return GeneratorFunction.prototype = GeneratorFunctionPrototype, o(g, "constructor", {
|
|
193
|
+
value: GeneratorFunctionPrototype,
|
|
194
|
+
configurable: !0
|
|
195
|
+
}), o(GeneratorFunctionPrototype, "constructor", {
|
|
196
|
+
value: GeneratorFunction,
|
|
197
|
+
configurable: !0
|
|
198
|
+
}), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, u, "GeneratorFunction"), e.isGeneratorFunction = function (t) {
|
|
199
|
+
var e = "function" == typeof t && t.constructor;
|
|
200
|
+
return !!e && (e === GeneratorFunction || "GeneratorFunction" === (e.displayName || e.name));
|
|
201
|
+
}, e.mark = function (t) {
|
|
202
|
+
return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, define(t, u, "GeneratorFunction")), t.prototype = Object.create(g), t;
|
|
203
|
+
}, e.awrap = function (t) {
|
|
204
|
+
return {
|
|
205
|
+
__await: t
|
|
206
|
+
};
|
|
207
|
+
}, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, c, function () {
|
|
208
|
+
return this;
|
|
209
|
+
}), e.AsyncIterator = AsyncIterator, e.async = function (t, r, n, o, i) {
|
|
210
|
+
void 0 === i && (i = Promise);
|
|
211
|
+
var a = new AsyncIterator(wrap(t, r, n, o), i);
|
|
212
|
+
return e.isGeneratorFunction(r) ? a : a.next().then(function (t) {
|
|
213
|
+
return t.done ? t.value : a.next();
|
|
214
|
+
});
|
|
215
|
+
}, defineIteratorMethods(g), define(g, u, "Generator"), define(g, a, function () {
|
|
216
|
+
return this;
|
|
217
|
+
}), define(g, "toString", function () {
|
|
218
|
+
return "[object Generator]";
|
|
219
|
+
}), e.keys = function (t) {
|
|
220
|
+
var e = Object(t),
|
|
221
|
+
r = [];
|
|
222
|
+
for (var n in e) r.push(n);
|
|
223
|
+
return r.reverse(), function next() {
|
|
224
|
+
for (; r.length;) {
|
|
225
|
+
var t = r.pop();
|
|
226
|
+
if (t in e) return next.value = t, next.done = !1, next;
|
|
227
|
+
}
|
|
228
|
+
return next.done = !0, next;
|
|
229
|
+
};
|
|
230
|
+
}, e.values = values, Context.prototype = {
|
|
231
|
+
constructor: Context,
|
|
232
|
+
reset: function (e) {
|
|
233
|
+
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);
|
|
234
|
+
},
|
|
235
|
+
stop: function () {
|
|
236
|
+
this.done = !0;
|
|
237
|
+
var t = this.tryEntries[0].completion;
|
|
238
|
+
if ("throw" === t.type) throw t.arg;
|
|
239
|
+
return this.rval;
|
|
240
|
+
},
|
|
241
|
+
dispatchException: function (e) {
|
|
242
|
+
if (this.done) throw e;
|
|
243
|
+
var r = this;
|
|
244
|
+
function handle(n, o) {
|
|
245
|
+
return a.type = "throw", a.arg = e, r.next = n, o && (r.method = "next", r.arg = t), !!o;
|
|
246
|
+
}
|
|
247
|
+
for (var o = this.tryEntries.length - 1; o >= 0; --o) {
|
|
248
|
+
var i = this.tryEntries[o],
|
|
249
|
+
a = i.completion;
|
|
250
|
+
if ("root" === i.tryLoc) return handle("end");
|
|
251
|
+
if (i.tryLoc <= this.prev) {
|
|
252
|
+
var c = n.call(i, "catchLoc"),
|
|
253
|
+
u = n.call(i, "finallyLoc");
|
|
254
|
+
if (c && u) {
|
|
255
|
+
if (this.prev < i.catchLoc) return handle(i.catchLoc, !0);
|
|
256
|
+
if (this.prev < i.finallyLoc) return handle(i.finallyLoc);
|
|
257
|
+
} else if (c) {
|
|
258
|
+
if (this.prev < i.catchLoc) return handle(i.catchLoc, !0);
|
|
259
|
+
} else {
|
|
260
|
+
if (!u) throw new Error("try statement without catch or finally");
|
|
261
|
+
if (this.prev < i.finallyLoc) return handle(i.finallyLoc);
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
},
|
|
266
|
+
abrupt: function (t, e) {
|
|
267
|
+
for (var r = this.tryEntries.length - 1; r >= 0; --r) {
|
|
268
|
+
var o = this.tryEntries[r];
|
|
269
|
+
if (o.tryLoc <= this.prev && n.call(o, "finallyLoc") && this.prev < o.finallyLoc) {
|
|
270
|
+
var i = o;
|
|
271
|
+
break;
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
i && ("break" === t || "continue" === t) && i.tryLoc <= e && e <= i.finallyLoc && (i = null);
|
|
275
|
+
var a = i ? i.completion : {};
|
|
276
|
+
return a.type = t, a.arg = e, i ? (this.method = "next", this.next = i.finallyLoc, y) : this.complete(a);
|
|
277
|
+
},
|
|
278
|
+
complete: function (t, e) {
|
|
279
|
+
if ("throw" === t.type) throw t.arg;
|
|
280
|
+
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;
|
|
281
|
+
},
|
|
282
|
+
finish: function (t) {
|
|
283
|
+
for (var e = this.tryEntries.length - 1; e >= 0; --e) {
|
|
284
|
+
var r = this.tryEntries[e];
|
|
285
|
+
if (r.finallyLoc === t) return this.complete(r.completion, r.afterLoc), resetTryEntry(r), y;
|
|
286
|
+
}
|
|
287
|
+
},
|
|
288
|
+
catch: function (t) {
|
|
289
|
+
for (var e = this.tryEntries.length - 1; e >= 0; --e) {
|
|
290
|
+
var r = this.tryEntries[e];
|
|
291
|
+
if (r.tryLoc === t) {
|
|
292
|
+
var n = r.completion;
|
|
293
|
+
if ("throw" === n.type) {
|
|
294
|
+
var o = n.arg;
|
|
295
|
+
resetTryEntry(r);
|
|
296
|
+
}
|
|
297
|
+
return o;
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
throw new Error("illegal catch attempt");
|
|
301
|
+
},
|
|
302
|
+
delegateYield: function (e, r, n) {
|
|
303
|
+
return this.delegate = {
|
|
304
|
+
iterator: values(e),
|
|
305
|
+
resultName: r,
|
|
306
|
+
nextLoc: n
|
|
307
|
+
}, "next" === this.method && (this.arg = t), y;
|
|
38
308
|
}
|
|
309
|
+
}, e;
|
|
310
|
+
}
|
|
311
|
+
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
|
|
312
|
+
try {
|
|
313
|
+
var info = gen[key](arg);
|
|
314
|
+
var value = info.value;
|
|
315
|
+
} catch (error) {
|
|
316
|
+
reject(error);
|
|
317
|
+
return;
|
|
318
|
+
}
|
|
319
|
+
if (info.done) {
|
|
320
|
+
resolve(value);
|
|
321
|
+
} else {
|
|
322
|
+
Promise.resolve(value).then(_next, _throw);
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
function _asyncToGenerator(fn) {
|
|
326
|
+
return function () {
|
|
327
|
+
var self = this,
|
|
328
|
+
args = arguments;
|
|
329
|
+
return new Promise(function (resolve, reject) {
|
|
330
|
+
var gen = fn.apply(self, args);
|
|
331
|
+
function _next(value) {
|
|
332
|
+
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
|
|
333
|
+
}
|
|
334
|
+
function _throw(err) {
|
|
335
|
+
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
|
|
336
|
+
}
|
|
337
|
+
_next(undefined);
|
|
338
|
+
});
|
|
339
|
+
};
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
function getUser(_x) {
|
|
343
|
+
return _getUser.apply(this, arguments);
|
|
344
|
+
} // async function getDauthUser() {
|
|
345
|
+
// const getUserFetch = await getUser()
|
|
346
|
+
// if (getUserFetch.response.status === 404) {
|
|
347
|
+
// return 404
|
|
348
|
+
// // return res.status(404).send({ status: 'domain-not-found', message: 'Dauth domain does not exist' });
|
|
349
|
+
// }
|
|
350
|
+
// if (getUserFetch.response.status === 500) {
|
|
351
|
+
// return 500
|
|
352
|
+
// // return res.status(500).send({ status: 'error', message: 'Dauth server error' });
|
|
353
|
+
// }
|
|
354
|
+
// if (getUserFetch.response.status === 200) {
|
|
355
|
+
// // req.user = getUserFetch.data as any
|
|
356
|
+
// // console.log('node-fetch', req.user);
|
|
357
|
+
// // next()
|
|
358
|
+
// return getUserFetch.data
|
|
359
|
+
// }
|
|
360
|
+
// return null
|
|
361
|
+
// }
|
|
362
|
+
function _getUser() {
|
|
363
|
+
_getUser = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(token) {
|
|
364
|
+
var params, response, data;
|
|
365
|
+
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
366
|
+
while (1) switch (_context2.prev = _context2.next) {
|
|
367
|
+
case 0:
|
|
368
|
+
params = {
|
|
369
|
+
method: 'GET',
|
|
370
|
+
headers: {
|
|
371
|
+
Authorization: token,
|
|
372
|
+
'Content-Type': 'application/json'
|
|
373
|
+
}
|
|
374
|
+
};
|
|
375
|
+
_context2.next = 3;
|
|
376
|
+
return fetch("http://localhost:4012/api/v1/get-tenant-user/easymediacloud", params);
|
|
377
|
+
case 3:
|
|
378
|
+
response = _context2.sent;
|
|
379
|
+
_context2.next = 6;
|
|
380
|
+
return response.json();
|
|
381
|
+
case 6:
|
|
382
|
+
data = _context2.sent;
|
|
383
|
+
return _context2.abrupt("return", {
|
|
384
|
+
response: response,
|
|
385
|
+
data: data
|
|
386
|
+
});
|
|
387
|
+
case 8:
|
|
388
|
+
case "end":
|
|
389
|
+
return _context2.stop();
|
|
390
|
+
}
|
|
391
|
+
}, _callee2);
|
|
392
|
+
}));
|
|
393
|
+
return _getUser.apply(this, arguments);
|
|
394
|
+
}
|
|
395
|
+
var dauth = /*#__PURE__*/function () {
|
|
396
|
+
var _ref2 = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(_ref) {
|
|
397
|
+
var ssid;
|
|
398
|
+
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
399
|
+
while (1) switch (_context.prev = _context.next) {
|
|
400
|
+
case 0:
|
|
401
|
+
ssid = _ref.ssid;
|
|
402
|
+
return _context.abrupt("return", function (req, res, next) {
|
|
403
|
+
if (!req.headers.authorization) {
|
|
404
|
+
return res.status(403).send({
|
|
405
|
+
status: 'token-not-found',
|
|
406
|
+
mdKey: 'ensure_auth'
|
|
407
|
+
});
|
|
408
|
+
}
|
|
409
|
+
var token = req.headers.authorization.replace(/['"]+/g, '');
|
|
410
|
+
try {
|
|
411
|
+
var payload = jwt.verify(token, ssid);
|
|
412
|
+
req.user = payload;
|
|
413
|
+
getUser(token).then(function (getUserFetch) {
|
|
414
|
+
if (getUserFetch.response.status === 404) {
|
|
415
|
+
return res.status(404).send({
|
|
416
|
+
status: 'domain-not-found',
|
|
417
|
+
message: 'Dauth domain does not exist'
|
|
418
|
+
});
|
|
419
|
+
}
|
|
420
|
+
if (getUserFetch.response.status === 500) {
|
|
421
|
+
return res.status(500).send({
|
|
422
|
+
status: 'error',
|
|
423
|
+
message: 'Dauth server error'
|
|
424
|
+
});
|
|
425
|
+
}
|
|
426
|
+
if (getUserFetch.response.status === 200) {
|
|
427
|
+
req.user = getUserFetch.data;
|
|
428
|
+
console.log('node-fetch npm', req.user);
|
|
429
|
+
}
|
|
430
|
+
})["catch"](function (error) {
|
|
431
|
+
console.log('getDauthUser error', error);
|
|
432
|
+
});
|
|
433
|
+
return next();
|
|
434
|
+
} catch (error) {
|
|
435
|
+
if (error && (error == null ? void 0 : error.message) === 'jwt expired') {
|
|
436
|
+
return res.status(500).send({
|
|
437
|
+
status: 'token-expired',
|
|
438
|
+
message: 'El token ha expirado',
|
|
439
|
+
error: error,
|
|
440
|
+
mdKey: 'ensure_auth'
|
|
441
|
+
});
|
|
442
|
+
}
|
|
443
|
+
return res.status(500).send({
|
|
444
|
+
status: 'token-invalid',
|
|
445
|
+
message: 'El token no es válido',
|
|
446
|
+
error: error,
|
|
447
|
+
mdKey: 'ensure_auth'
|
|
448
|
+
});
|
|
449
|
+
}
|
|
450
|
+
});
|
|
451
|
+
case 2:
|
|
452
|
+
case "end":
|
|
453
|
+
return _context.stop();
|
|
454
|
+
}
|
|
455
|
+
}, _callee);
|
|
456
|
+
}));
|
|
457
|
+
return function dauth(_x2) {
|
|
458
|
+
return _ref2.apply(this, arguments);
|
|
39
459
|
};
|
|
40
|
-
};
|
|
460
|
+
}();
|
|
41
461
|
|
|
42
462
|
exports.dauth = dauth;
|
|
43
463
|
//# 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\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
|
|
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';\nimport fetch from 'node-fetch';\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 user: 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\nasync function getUser(token: string) {\n const params = {\n method: 'GET',\n headers: {\n Authorization: token,\n 'Content-Type': 'application/json',\n },\n };\n const response = await fetch(\n `http://localhost:4012/api/v1/get-tenant-user/easymediacloud`,\n params\n );\n const data = await response.json();\n return { response, data };\n}\n\n// async function getDauthUser() {\n// const getUserFetch = await getUser()\n// if (getUserFetch.response.status === 404) {\n// return 404\n// // return res.status(404).send({ status: 'domain-not-found', message: 'Dauth domain does not exist' });\n// }\n// if (getUserFetch.response.status === 500) {\n// return 500\n// // return res.status(500).send({ status: 'error', message: 'Dauth server error' });\n// }\n// if (getUserFetch.response.status === 200) {\n// // req.user = getUserFetch.data as any\n// // console.log('node-fetch', req.user);\n// // next()\n// return getUserFetch.data\n// }\n// return null\n// }\n\nexport const dauth = async ({ ssid }: { ssid: string }) => {\n // const getUser = await getDauthUser()\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.user = payload;\n getUser(token)\n .then((getUserFetch: any) => {\n if (getUserFetch.response.status === 404) {\n return res.status(404).send({\n status: 'domain-not-found',\n message: 'Dauth domain does not exist',\n });\n }\n if (getUserFetch.response.status === 500) {\n return res\n .status(500)\n .send({ status: 'error', message: 'Dauth server error' });\n }\n if (getUserFetch.response.status === 200) {\n req.user = getUserFetch.data;\n console.log('node-fetch npm', req.user);\n }\n })\n .catch((error: any) => {\n console.log('getDauthUser error', error);\n });\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":["getUser","_x","_getUser","apply","arguments","_asyncToGenerator","_regeneratorRuntime","mark","_callee2","token","params","response","data","wrap","_callee2$","_context2","prev","next","method","headers","Authorization","fetch","sent","json","abrupt","stop","dauth","_ref2","_callee","_ref","ssid","_callee$","_context","req","res","authorization","status","send","mdKey","replace","payload","jwt","verify","user","then","getUserFetch","message","console","log","error","_x2"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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1C,CAAC,SACI,CAAC,UAACM,KAAU;gBAChBF,OAAO,CAACC,GAAG,CAAC,oBAAoB,EAAEC,KAAK,CAAC;eACzC,CAAC;cACJ,OAAOhC,IAAI,EAAE;aACd,CAAC,OAAOgC,KAAK,EAAE;cACd,IAAIA,KAAK,IAAI,CAAAA,KAAK,oBAALA,KAAK,CAAEH,OAAO,MAAK,aAAa,EAAE;gBAC7C,OAAOZ,GAAG,CAACE,MAAM,CAAC,GAAG,CAAC,CAACC,IAAI,CAAC;kBAC1BD,MAAM,EAAE,eAAe;kBACvBU,OAAO,EAAE,sBAAsB;kBAC/BG,KAAK,EAAEA,KAAK;kBACZX,KAAK,EAAE;iBACR,CAAC;;cAEJ,OAAOJ,GAAG,CAACE,MAAM,CAAC,GAAG,CAAC,CAACC,IAAI,CAAC;gBAC1BD,MAAM,EAAE,eAAe;gBACvBU,OAAO,EAAE,uBAAuB;gBAChCG,KAAK,EAAEA,KAAK;gBACZX,KAAK,EAAE;eACR,CAAC;;WAEL;QAAA;QAAA;UAAA,OAAAN,QAAA,CAAAP,IAAA;;OAAAG,OAAA;GACF;EAAA,gBAvDYF,KAAKA,CAAAwB,GAAA;IAAA,OAAAvB,KAAA,CAAAxB,KAAA,OAAAC,SAAA;;AAAA;;;;"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e,t=(e=
|
|
1
|
+
"use strict";function t(t){return t&&"object"==typeof t&&"default"in t?t.default:t}Object.defineProperty(exports,"__esModule",{value:!0});var e=t(require("jsonwebtoken")),r=t(require("node-fetch"));function n(){n=function(){return e};var t,e={},r=Object.prototype,o=r.hasOwnProperty,i=Object.defineProperty||function(t,e,r){t[e]=r.value},a="function"==typeof Symbol?Symbol:{},u=a.iterator||"@@iterator",c=a.asyncIterator||"@@asyncIterator",s=a.toStringTag||"@@toStringTag";function h(t,e,r){return Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}),t[e]}try{h({},"")}catch(t){h=function(t,e,r){return t[e]=r}}function f(t,e,r,n){var o=Object.create((e&&e.prototype instanceof g?e:g).prototype),a=new N(n||[]);return i(o,"_invoke",{value:k(t,r,a)}),o}function l(t,e,r){try{return{type:"normal",arg:t.call(e,r)}}catch(t){return{type:"throw",arg:t}}}e.wrap=f;var p="suspendedStart",d="executing",v="completed",y={};function g(){}function m(){}function w(){}var x={};h(x,u,(function(){return this}));var b=Object.getPrototypeOf,L=b&&b(b(T([])));L&&L!==r&&o.call(L,u)&&(x=L);var E=w.prototype=g.prototype=Object.create(x);function _(t){["next","throw","return"].forEach((function(e){h(t,e,(function(t){return this._invoke(e,t)}))}))}function j(t,e){function r(n,i,a,u){var c=l(t[n],t,i);if("throw"!==c.type){var s=c.arg,h=s.value;return h&&"object"==typeof h&&o.call(h,"__await")?e.resolve(h.__await).then((function(t){r("next",t,a,u)}),(function(t){r("throw",t,a,u)})):e.resolve(h).then((function(t){s.value=t,a(s)}),(function(t){return r("throw",t,a,u)}))}u(c.arg)}var n;i(this,"_invoke",{value:function(t,o){function i(){return new e((function(e,n){r(t,o,e,n)}))}return n=n?n.then(i,i):i()}})}function k(e,r,n){var o=p;return function(i,a){if(o===d)throw new Error("Generator is already running");if(o===v){if("throw"===i)throw a;return{value:t,done:!0}}for(n.method=i,n.arg=a;;){var u=n.delegate;if(u){var c=O(u,n);if(c){if(c===y)continue;return c}}if("next"===n.method)n.sent=n._sent=n.arg;else if("throw"===n.method){if(o===p)throw o=v,n.arg;n.dispatchException(n.arg)}else"return"===n.method&&n.abrupt("return",n.arg);o=d;var s=l(e,r,n);if("normal"===s.type){if(o=n.done?v:"suspendedYield",s.arg===y)continue;return{value:s.arg,done:n.done}}"throw"===s.type&&(o=v,n.method="throw",n.arg=s.arg)}}}function O(e,r){var n=r.method,o=e.iterator[n];if(o===t)return r.delegate=null,"throw"===n&&e.iterator.return&&(r.method="return",r.arg=t,O(e,r),"throw"===r.method)||"return"!==n&&(r.method="throw",r.arg=new TypeError("The iterator does not provide a '"+n+"' method")),y;var i=l(o,e.iterator,r.arg);if("throw"===i.type)return r.method="throw",r.arg=i.arg,r.delegate=null,y;var a=i.arg;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)}function P(t){var e={tryLoc:t[0]};1 in t&&(e.catchLoc=t[1]),2 in t&&(e.finallyLoc=t[2],e.afterLoc=t[3]),this.tryEntries.push(e)}function G(t){var e=t.completion||{};e.type="normal",delete e.arg,t.completion=e}function N(t){this.tryEntries=[{tryLoc:"root"}],t.forEach(P,this),this.reset(!0)}function T(e){if(e||""===e){var r=e[u];if(r)return r.call(e);if("function"==typeof e.next)return e;if(!isNaN(e.length)){var n=-1,i=function r(){for(;++n<e.length;)if(o.call(e,n))return r.value=e[n],r.done=!1,r;return r.value=t,r.done=!0,r};return i.next=i}}throw new TypeError(typeof e+" is not iterable")}return m.prototype=w,i(E,"constructor",{value:w,configurable:!0}),i(w,"constructor",{value:m,configurable:!0}),m.displayName=h(w,s,"GeneratorFunction"),e.isGeneratorFunction=function(t){var e="function"==typeof t&&t.constructor;return!!e&&(e===m||"GeneratorFunction"===(e.displayName||e.name))},e.mark=function(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,w):(t.__proto__=w,h(t,s,"GeneratorFunction")),t.prototype=Object.create(E),t},e.awrap=function(t){return{__await:t}},_(j.prototype),h(j.prototype,c,(function(){return this})),e.AsyncIterator=j,e.async=function(t,r,n,o,i){void 0===i&&(i=Promise);var a=new j(f(t,r,n,o),i);return e.isGeneratorFunction(r)?a:a.next().then((function(t){return t.done?t.value:a.next()}))},_(E),h(E,s,"Generator"),h(E,u,(function(){return this})),h(E,"toString",(function(){return"[object Generator]"})),e.keys=function(t){var e=Object(t),r=[];for(var n in e)r.push(n);return r.reverse(),function t(){for(;r.length;){var n=r.pop();if(n in e)return t.value=n,t.done=!1,t}return t.done=!0,t}},e.values=T,N.prototype={constructor:N,reset:function(e){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(G),!e)for(var r in this)"t"===r.charAt(0)&&o.call(this,r)&&!isNaN(+r.slice(1))&&(this[r]=t)},stop:function(){this.done=!0;var t=this.tryEntries[0].completion;if("throw"===t.type)throw t.arg;return this.rval},dispatchException:function(e){if(this.done)throw e;var r=this;function n(n,o){return u.type="throw",u.arg=e,r.next=n,o&&(r.method="next",r.arg=t),!!o}for(var i=this.tryEntries.length-1;i>=0;--i){var a=this.tryEntries[i],u=a.completion;if("root"===a.tryLoc)return n("end");if(a.tryLoc<=this.prev){var c=o.call(a,"catchLoc"),s=o.call(a,"finallyLoc");if(c&&s){if(this.prev<a.catchLoc)return n(a.catchLoc,!0);if(this.prev<a.finallyLoc)return n(a.finallyLoc)}else if(c){if(this.prev<a.catchLoc)return n(a.catchLoc,!0)}else{if(!s)throw new Error("try statement without catch or finally");if(this.prev<a.finallyLoc)return n(a.finallyLoc)}}}},abrupt:function(t,e){for(var r=this.tryEntries.length-1;r>=0;--r){var n=this.tryEntries[r];if(n.tryLoc<=this.prev&&o.call(n,"finallyLoc")&&this.prev<n.finallyLoc){var i=n;break}}i&&("break"===t||"continue"===t)&&i.tryLoc<=e&&e<=i.finallyLoc&&(i=null);var a=i?i.completion:{};return a.type=t,a.arg=e,i?(this.method="next",this.next=i.finallyLoc,y):this.complete(a)},complete:function(t,e){if("throw"===t.type)throw t.arg;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},finish:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var r=this.tryEntries[e];if(r.finallyLoc===t)return this.complete(r.completion,r.afterLoc),G(r),y}},catch:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var r=this.tryEntries[e];if(r.tryLoc===t){var n=r.completion;if("throw"===n.type){var o=n.arg;G(r)}return o}}throw new Error("illegal catch attempt")},delegateYield:function(e,r,n){return this.delegate={iterator:T(e),resultName:r,nextLoc:n},"next"===this.method&&(this.arg=t),y}},e}function o(t,e,r,n,o,i,a){try{var u=t[i](a),c=u.value}catch(t){return void r(t)}u.done?e(c):Promise.resolve(c).then(n,o)}function i(t){return function(){var e=this,r=arguments;return new Promise((function(n,i){var a=t.apply(e,r);function u(t){o(a,n,i,u,c,"next",t)}function c(t){o(a,n,i,u,c,"throw",t)}u(void 0)}))}}function a(t){return u.apply(this,arguments)}function u(){return(u=i(n().mark((function t(e){var o,i;return n().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return o={method:"GET",headers:{Authorization:e,"Content-Type":"application/json"}},t.next=3,r("http://localhost:4012/api/v1/get-tenant-user/easymediacloud",o);case 3:return i=t.sent,t.next=6,i.json();case 6:return t.abrupt("return",{response:i,data:t.sent});case 8:case"end":return t.stop()}}),t)})))).apply(this,arguments)}exports.dauth=function(){var t=i(n().mark((function t(r){var o;return n().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return o=r.ssid,t.abrupt("return",(function(t,r,n){if(!t.headers.authorization)return r.status(403).send({status:"token-not-found",mdKey:"ensure_auth"});var i=t.headers.authorization.replace(/['"]+/g,"");try{var u=e.verify(i,o);return t.user=u,a(i).then((function(e){return 404===e.response.status?r.status(404).send({status:"domain-not-found",message:"Dauth domain does not exist"}):500===e.response.status?r.status(500).send({status:"error",message:"Dauth server error"}):void(200===e.response.status&&(t.user=e.data,console.log("node-fetch npm",t.user)))})).catch((function(t){console.log("getDauthUser error",t)})),n()}catch(t){return t&&"jwt expired"===(null==t?void 0:t.message)?r.status(500).send({status:"token-expired",message:"El token ha expirado",error:t,mdKey:"ensure_auth"}):r.status(500).send({status:"token-invalid",message:"El token no es válido",error:t,mdKey:"ensure_auth"})}}));case 2:case"end":return t.stop()}}),t)})));return function(e){return t.apply(this,arguments)}}();
|
|
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\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
|
|
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';\nimport fetch from 'node-fetch';\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 user: 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\nasync function getUser(token: string) {\n const params = {\n method: 'GET',\n headers: {\n Authorization: token,\n 'Content-Type': 'application/json',\n },\n };\n const response = await fetch(\n `http://localhost:4012/api/v1/get-tenant-user/easymediacloud`,\n params\n );\n const data = await response.json();\n return { response, data };\n}\n\n// async function getDauthUser() {\n// const getUserFetch = await getUser()\n// if (getUserFetch.response.status === 404) {\n// return 404\n// // return res.status(404).send({ status: 'domain-not-found', message: 'Dauth domain does not exist' });\n// }\n// if (getUserFetch.response.status === 500) {\n// return 500\n// // return res.status(500).send({ status: 'error', message: 'Dauth server error' });\n// }\n// if (getUserFetch.response.status === 200) {\n// // req.user = getUserFetch.data as any\n// // console.log('node-fetch', req.user);\n// // next()\n// return getUserFetch.data\n// }\n// return null\n// }\n\nexport const dauth = async ({ ssid }: { ssid: string }) => {\n // const getUser = await getDauthUser()\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.user = payload;\n getUser(token)\n .then((getUserFetch: any) => {\n if (getUserFetch.response.status === 404) {\n return res.status(404).send({\n status: 'domain-not-found',\n message: 'Dauth domain does not exist',\n });\n }\n if (getUserFetch.response.status === 500) {\n return res\n .status(500)\n .send({ status: 'error', message: 'Dauth server error' });\n }\n if (getUserFetch.response.status === 200) {\n req.user = getUserFetch.data;\n console.log('node-fetch npm', req.user);\n }\n })\n .catch((error: any) => {\n console.log('getDauthUser error', error);\n });\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":["getUser","_x","_getUser","apply","arguments","_asyncToGenerator","_regeneratorRuntime","mark","_callee2","token","params","response","wrap","_context2","prev","next","method","headers","Authorization","Content-Type","fetch","sent","json","abrupt","data","stop","_ref2","_callee","_ref","ssid","_context","req","res","authorization","status","send","mdKey","replace","payload","jwt","verify","user","then","getUserFetch","message","console","log","error","_x2"],"mappings":"82NAQ+B,SA6BhBA,EAAOC,GAAA,OAAAC,EAAAC,WAAAC,WAiCtB,SAAAF,IAnBC,OAmBDA,EAAAG,EAAAC,IAAAC,MAjCA,SAAAC,EAAuBC,GAAa,IAAAC,EAAAC,EAAA,OAAAL,IAAAM,eAAAC,GAAA,cAAAA,EAAAC,KAAAD,EAAAE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,QAAS,uBACTG,MAAOA,EACPX,MAAO,gBAGJJ,EAAIE,OAAO,KAAKC,KAAK,CAC1BD,OAAQ,gBACRU,QAAS,wBACTG,MAAOA,EACPX,MAAO,oBAGZ,OAAA,UAAA,OAAAN,EAAAL,UAAAE,OACF,gBAvDiBqB,GAAA,OAAAtB,EAAAvB,WAAAC"}
|
|
@@ -1,37 +1,457 @@
|
|
|
1
1
|
import jwt from 'jsonwebtoken';
|
|
2
|
+
import fetch from 'node-fetch';
|
|
2
3
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
4
|
+
function _regeneratorRuntime() {
|
|
5
|
+
_regeneratorRuntime = function () {
|
|
6
|
+
return e;
|
|
7
|
+
};
|
|
8
|
+
var t,
|
|
9
|
+
e = {},
|
|
10
|
+
r = Object.prototype,
|
|
11
|
+
n = r.hasOwnProperty,
|
|
12
|
+
o = Object.defineProperty || function (t, e, r) {
|
|
13
|
+
t[e] = r.value;
|
|
14
|
+
},
|
|
15
|
+
i = "function" == typeof Symbol ? Symbol : {},
|
|
16
|
+
a = i.iterator || "@@iterator",
|
|
17
|
+
c = i.asyncIterator || "@@asyncIterator",
|
|
18
|
+
u = i.toStringTag || "@@toStringTag";
|
|
19
|
+
function define(t, e, r) {
|
|
20
|
+
return Object.defineProperty(t, e, {
|
|
21
|
+
value: r,
|
|
22
|
+
enumerable: !0,
|
|
23
|
+
configurable: !0,
|
|
24
|
+
writable: !0
|
|
25
|
+
}), t[e];
|
|
26
|
+
}
|
|
27
|
+
try {
|
|
28
|
+
define({}, "");
|
|
29
|
+
} catch (t) {
|
|
30
|
+
define = function (t, e, r) {
|
|
31
|
+
return t[e] = r;
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
function wrap(t, e, r, n) {
|
|
35
|
+
var i = e && e.prototype instanceof Generator ? e : Generator,
|
|
36
|
+
a = Object.create(i.prototype),
|
|
37
|
+
c = new Context(n || []);
|
|
38
|
+
return o(a, "_invoke", {
|
|
39
|
+
value: makeInvokeMethod(t, r, c)
|
|
40
|
+
}), a;
|
|
41
|
+
}
|
|
42
|
+
function tryCatch(t, e, r) {
|
|
13
43
|
try {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
44
|
+
return {
|
|
45
|
+
type: "normal",
|
|
46
|
+
arg: t.call(e, r)
|
|
47
|
+
};
|
|
48
|
+
} catch (t) {
|
|
49
|
+
return {
|
|
50
|
+
type: "throw",
|
|
51
|
+
arg: t
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
e.wrap = wrap;
|
|
56
|
+
var h = "suspendedStart",
|
|
57
|
+
l = "suspendedYield",
|
|
58
|
+
f = "executing",
|
|
59
|
+
s = "completed",
|
|
60
|
+
y = {};
|
|
61
|
+
function Generator() {}
|
|
62
|
+
function GeneratorFunction() {}
|
|
63
|
+
function GeneratorFunctionPrototype() {}
|
|
64
|
+
var p = {};
|
|
65
|
+
define(p, a, function () {
|
|
66
|
+
return this;
|
|
67
|
+
});
|
|
68
|
+
var d = Object.getPrototypeOf,
|
|
69
|
+
v = d && d(d(values([])));
|
|
70
|
+
v && v !== r && n.call(v, a) && (p = v);
|
|
71
|
+
var g = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(p);
|
|
72
|
+
function defineIteratorMethods(t) {
|
|
73
|
+
["next", "throw", "return"].forEach(function (e) {
|
|
74
|
+
define(t, e, function (t) {
|
|
75
|
+
return this._invoke(e, t);
|
|
76
|
+
});
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
function AsyncIterator(t, e) {
|
|
80
|
+
function invoke(r, o, i, a) {
|
|
81
|
+
var c = tryCatch(t[r], t, o);
|
|
82
|
+
if ("throw" !== c.type) {
|
|
83
|
+
var u = c.arg,
|
|
84
|
+
h = u.value;
|
|
85
|
+
return h && "object" == typeof h && n.call(h, "__await") ? e.resolve(h.__await).then(function (t) {
|
|
86
|
+
invoke("next", t, i, a);
|
|
87
|
+
}, function (t) {
|
|
88
|
+
invoke("throw", t, i, a);
|
|
89
|
+
}) : e.resolve(h).then(function (t) {
|
|
90
|
+
u.value = t, i(u);
|
|
91
|
+
}, function (t) {
|
|
92
|
+
return invoke("throw", t, i, a);
|
|
24
93
|
});
|
|
25
94
|
}
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
95
|
+
a(c.arg);
|
|
96
|
+
}
|
|
97
|
+
var r;
|
|
98
|
+
o(this, "_invoke", {
|
|
99
|
+
value: function (t, n) {
|
|
100
|
+
function callInvokeWithMethodAndArg() {
|
|
101
|
+
return new e(function (e, r) {
|
|
102
|
+
invoke(t, n, e, r);
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
return r = r ? r.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg();
|
|
106
|
+
}
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
function makeInvokeMethod(e, r, n) {
|
|
110
|
+
var o = h;
|
|
111
|
+
return function (i, a) {
|
|
112
|
+
if (o === f) throw new Error("Generator is already running");
|
|
113
|
+
if (o === s) {
|
|
114
|
+
if ("throw" === i) throw a;
|
|
115
|
+
return {
|
|
116
|
+
value: t,
|
|
117
|
+
done: !0
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
for (n.method = i, n.arg = a;;) {
|
|
121
|
+
var c = n.delegate;
|
|
122
|
+
if (c) {
|
|
123
|
+
var u = maybeInvokeDelegate(c, n);
|
|
124
|
+
if (u) {
|
|
125
|
+
if (u === y) continue;
|
|
126
|
+
return u;
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) {
|
|
130
|
+
if (o === h) throw o = s, n.arg;
|
|
131
|
+
n.dispatchException(n.arg);
|
|
132
|
+
} else "return" === n.method && n.abrupt("return", n.arg);
|
|
133
|
+
o = f;
|
|
134
|
+
var p = tryCatch(e, r, n);
|
|
135
|
+
if ("normal" === p.type) {
|
|
136
|
+
if (o = n.done ? s : l, p.arg === y) continue;
|
|
137
|
+
return {
|
|
138
|
+
value: p.arg,
|
|
139
|
+
done: n.done
|
|
140
|
+
};
|
|
141
|
+
}
|
|
142
|
+
"throw" === p.type && (o = s, n.method = "throw", n.arg = p.arg);
|
|
143
|
+
}
|
|
144
|
+
};
|
|
145
|
+
}
|
|
146
|
+
function maybeInvokeDelegate(e, r) {
|
|
147
|
+
var n = r.method,
|
|
148
|
+
o = e.iterator[n];
|
|
149
|
+
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;
|
|
150
|
+
var i = tryCatch(o, e.iterator, r.arg);
|
|
151
|
+
if ("throw" === i.type) return r.method = "throw", r.arg = i.arg, r.delegate = null, y;
|
|
152
|
+
var a = i.arg;
|
|
153
|
+
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);
|
|
154
|
+
}
|
|
155
|
+
function pushTryEntry(t) {
|
|
156
|
+
var e = {
|
|
157
|
+
tryLoc: t[0]
|
|
158
|
+
};
|
|
159
|
+
1 in t && (e.catchLoc = t[1]), 2 in t && (e.finallyLoc = t[2], e.afterLoc = t[3]), this.tryEntries.push(e);
|
|
160
|
+
}
|
|
161
|
+
function resetTryEntry(t) {
|
|
162
|
+
var e = t.completion || {};
|
|
163
|
+
e.type = "normal", delete e.arg, t.completion = e;
|
|
164
|
+
}
|
|
165
|
+
function Context(t) {
|
|
166
|
+
this.tryEntries = [{
|
|
167
|
+
tryLoc: "root"
|
|
168
|
+
}], t.forEach(pushTryEntry, this), this.reset(!0);
|
|
169
|
+
}
|
|
170
|
+
function values(e) {
|
|
171
|
+
if (e || "" === e) {
|
|
172
|
+
var r = e[a];
|
|
173
|
+
if (r) return r.call(e);
|
|
174
|
+
if ("function" == typeof e.next) return e;
|
|
175
|
+
if (!isNaN(e.length)) {
|
|
176
|
+
var o = -1,
|
|
177
|
+
i = function next() {
|
|
178
|
+
for (; ++o < e.length;) if (n.call(e, o)) return next.value = e[o], next.done = !1, next;
|
|
179
|
+
return next.value = t, next.done = !0, next;
|
|
180
|
+
};
|
|
181
|
+
return i.next = i;
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
throw new TypeError(typeof e + " is not iterable");
|
|
185
|
+
}
|
|
186
|
+
return GeneratorFunction.prototype = GeneratorFunctionPrototype, o(g, "constructor", {
|
|
187
|
+
value: GeneratorFunctionPrototype,
|
|
188
|
+
configurable: !0
|
|
189
|
+
}), o(GeneratorFunctionPrototype, "constructor", {
|
|
190
|
+
value: GeneratorFunction,
|
|
191
|
+
configurable: !0
|
|
192
|
+
}), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, u, "GeneratorFunction"), e.isGeneratorFunction = function (t) {
|
|
193
|
+
var e = "function" == typeof t && t.constructor;
|
|
194
|
+
return !!e && (e === GeneratorFunction || "GeneratorFunction" === (e.displayName || e.name));
|
|
195
|
+
}, e.mark = function (t) {
|
|
196
|
+
return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, define(t, u, "GeneratorFunction")), t.prototype = Object.create(g), t;
|
|
197
|
+
}, e.awrap = function (t) {
|
|
198
|
+
return {
|
|
199
|
+
__await: t
|
|
200
|
+
};
|
|
201
|
+
}, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, c, function () {
|
|
202
|
+
return this;
|
|
203
|
+
}), e.AsyncIterator = AsyncIterator, e.async = function (t, r, n, o, i) {
|
|
204
|
+
void 0 === i && (i = Promise);
|
|
205
|
+
var a = new AsyncIterator(wrap(t, r, n, o), i);
|
|
206
|
+
return e.isGeneratorFunction(r) ? a : a.next().then(function (t) {
|
|
207
|
+
return t.done ? t.value : a.next();
|
|
208
|
+
});
|
|
209
|
+
}, defineIteratorMethods(g), define(g, u, "Generator"), define(g, a, function () {
|
|
210
|
+
return this;
|
|
211
|
+
}), define(g, "toString", function () {
|
|
212
|
+
return "[object Generator]";
|
|
213
|
+
}), e.keys = function (t) {
|
|
214
|
+
var e = Object(t),
|
|
215
|
+
r = [];
|
|
216
|
+
for (var n in e) r.push(n);
|
|
217
|
+
return r.reverse(), function next() {
|
|
218
|
+
for (; r.length;) {
|
|
219
|
+
var t = r.pop();
|
|
220
|
+
if (t in e) return next.value = t, next.done = !1, next;
|
|
221
|
+
}
|
|
222
|
+
return next.done = !0, next;
|
|
223
|
+
};
|
|
224
|
+
}, e.values = values, Context.prototype = {
|
|
225
|
+
constructor: Context,
|
|
226
|
+
reset: function (e) {
|
|
227
|
+
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);
|
|
228
|
+
},
|
|
229
|
+
stop: function () {
|
|
230
|
+
this.done = !0;
|
|
231
|
+
var t = this.tryEntries[0].completion;
|
|
232
|
+
if ("throw" === t.type) throw t.arg;
|
|
233
|
+
return this.rval;
|
|
234
|
+
},
|
|
235
|
+
dispatchException: function (e) {
|
|
236
|
+
if (this.done) throw e;
|
|
237
|
+
var r = this;
|
|
238
|
+
function handle(n, o) {
|
|
239
|
+
return a.type = "throw", a.arg = e, r.next = n, o && (r.method = "next", r.arg = t), !!o;
|
|
240
|
+
}
|
|
241
|
+
for (var o = this.tryEntries.length - 1; o >= 0; --o) {
|
|
242
|
+
var i = this.tryEntries[o],
|
|
243
|
+
a = i.completion;
|
|
244
|
+
if ("root" === i.tryLoc) return handle("end");
|
|
245
|
+
if (i.tryLoc <= this.prev) {
|
|
246
|
+
var c = n.call(i, "catchLoc"),
|
|
247
|
+
u = n.call(i, "finallyLoc");
|
|
248
|
+
if (c && u) {
|
|
249
|
+
if (this.prev < i.catchLoc) return handle(i.catchLoc, !0);
|
|
250
|
+
if (this.prev < i.finallyLoc) return handle(i.finallyLoc);
|
|
251
|
+
} else if (c) {
|
|
252
|
+
if (this.prev < i.catchLoc) return handle(i.catchLoc, !0);
|
|
253
|
+
} else {
|
|
254
|
+
if (!u) throw new Error("try statement without catch or finally");
|
|
255
|
+
if (this.prev < i.finallyLoc) return handle(i.finallyLoc);
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
},
|
|
260
|
+
abrupt: function (t, e) {
|
|
261
|
+
for (var r = this.tryEntries.length - 1; r >= 0; --r) {
|
|
262
|
+
var o = this.tryEntries[r];
|
|
263
|
+
if (o.tryLoc <= this.prev && n.call(o, "finallyLoc") && this.prev < o.finallyLoc) {
|
|
264
|
+
var i = o;
|
|
265
|
+
break;
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
i && ("break" === t || "continue" === t) && i.tryLoc <= e && e <= i.finallyLoc && (i = null);
|
|
269
|
+
var a = i ? i.completion : {};
|
|
270
|
+
return a.type = t, a.arg = e, i ? (this.method = "next", this.next = i.finallyLoc, y) : this.complete(a);
|
|
271
|
+
},
|
|
272
|
+
complete: function (t, e) {
|
|
273
|
+
if ("throw" === t.type) throw t.arg;
|
|
274
|
+
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;
|
|
275
|
+
},
|
|
276
|
+
finish: function (t) {
|
|
277
|
+
for (var e = this.tryEntries.length - 1; e >= 0; --e) {
|
|
278
|
+
var r = this.tryEntries[e];
|
|
279
|
+
if (r.finallyLoc === t) return this.complete(r.completion, r.afterLoc), resetTryEntry(r), y;
|
|
280
|
+
}
|
|
281
|
+
},
|
|
282
|
+
catch: function (t) {
|
|
283
|
+
for (var e = this.tryEntries.length - 1; e >= 0; --e) {
|
|
284
|
+
var r = this.tryEntries[e];
|
|
285
|
+
if (r.tryLoc === t) {
|
|
286
|
+
var n = r.completion;
|
|
287
|
+
if ("throw" === n.type) {
|
|
288
|
+
var o = n.arg;
|
|
289
|
+
resetTryEntry(r);
|
|
290
|
+
}
|
|
291
|
+
return o;
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
throw new Error("illegal catch attempt");
|
|
295
|
+
},
|
|
296
|
+
delegateYield: function (e, r, n) {
|
|
297
|
+
return this.delegate = {
|
|
298
|
+
iterator: values(e),
|
|
299
|
+
resultName: r,
|
|
300
|
+
nextLoc: n
|
|
301
|
+
}, "next" === this.method && (this.arg = t), y;
|
|
32
302
|
}
|
|
303
|
+
}, e;
|
|
304
|
+
}
|
|
305
|
+
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
|
|
306
|
+
try {
|
|
307
|
+
var info = gen[key](arg);
|
|
308
|
+
var value = info.value;
|
|
309
|
+
} catch (error) {
|
|
310
|
+
reject(error);
|
|
311
|
+
return;
|
|
312
|
+
}
|
|
313
|
+
if (info.done) {
|
|
314
|
+
resolve(value);
|
|
315
|
+
} else {
|
|
316
|
+
Promise.resolve(value).then(_next, _throw);
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
function _asyncToGenerator(fn) {
|
|
320
|
+
return function () {
|
|
321
|
+
var self = this,
|
|
322
|
+
args = arguments;
|
|
323
|
+
return new Promise(function (resolve, reject) {
|
|
324
|
+
var gen = fn.apply(self, args);
|
|
325
|
+
function _next(value) {
|
|
326
|
+
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
|
|
327
|
+
}
|
|
328
|
+
function _throw(err) {
|
|
329
|
+
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
|
|
330
|
+
}
|
|
331
|
+
_next(undefined);
|
|
332
|
+
});
|
|
333
|
+
};
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
function getUser(_x) {
|
|
337
|
+
return _getUser.apply(this, arguments);
|
|
338
|
+
} // async function getDauthUser() {
|
|
339
|
+
// const getUserFetch = await getUser()
|
|
340
|
+
// if (getUserFetch.response.status === 404) {
|
|
341
|
+
// return 404
|
|
342
|
+
// // return res.status(404).send({ status: 'domain-not-found', message: 'Dauth domain does not exist' });
|
|
343
|
+
// }
|
|
344
|
+
// if (getUserFetch.response.status === 500) {
|
|
345
|
+
// return 500
|
|
346
|
+
// // return res.status(500).send({ status: 'error', message: 'Dauth server error' });
|
|
347
|
+
// }
|
|
348
|
+
// if (getUserFetch.response.status === 200) {
|
|
349
|
+
// // req.user = getUserFetch.data as any
|
|
350
|
+
// // console.log('node-fetch', req.user);
|
|
351
|
+
// // next()
|
|
352
|
+
// return getUserFetch.data
|
|
353
|
+
// }
|
|
354
|
+
// return null
|
|
355
|
+
// }
|
|
356
|
+
function _getUser() {
|
|
357
|
+
_getUser = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(token) {
|
|
358
|
+
var params, response, data;
|
|
359
|
+
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
360
|
+
while (1) switch (_context2.prev = _context2.next) {
|
|
361
|
+
case 0:
|
|
362
|
+
params = {
|
|
363
|
+
method: 'GET',
|
|
364
|
+
headers: {
|
|
365
|
+
Authorization: token,
|
|
366
|
+
'Content-Type': 'application/json'
|
|
367
|
+
}
|
|
368
|
+
};
|
|
369
|
+
_context2.next = 3;
|
|
370
|
+
return fetch("http://localhost:4012/api/v1/get-tenant-user/easymediacloud", params);
|
|
371
|
+
case 3:
|
|
372
|
+
response = _context2.sent;
|
|
373
|
+
_context2.next = 6;
|
|
374
|
+
return response.json();
|
|
375
|
+
case 6:
|
|
376
|
+
data = _context2.sent;
|
|
377
|
+
return _context2.abrupt("return", {
|
|
378
|
+
response: response,
|
|
379
|
+
data: data
|
|
380
|
+
});
|
|
381
|
+
case 8:
|
|
382
|
+
case "end":
|
|
383
|
+
return _context2.stop();
|
|
384
|
+
}
|
|
385
|
+
}, _callee2);
|
|
386
|
+
}));
|
|
387
|
+
return _getUser.apply(this, arguments);
|
|
388
|
+
}
|
|
389
|
+
var dauth = /*#__PURE__*/function () {
|
|
390
|
+
var _ref2 = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(_ref) {
|
|
391
|
+
var ssid;
|
|
392
|
+
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
393
|
+
while (1) switch (_context.prev = _context.next) {
|
|
394
|
+
case 0:
|
|
395
|
+
ssid = _ref.ssid;
|
|
396
|
+
return _context.abrupt("return", function (req, res, next) {
|
|
397
|
+
if (!req.headers.authorization) {
|
|
398
|
+
return res.status(403).send({
|
|
399
|
+
status: 'token-not-found',
|
|
400
|
+
mdKey: 'ensure_auth'
|
|
401
|
+
});
|
|
402
|
+
}
|
|
403
|
+
var token = req.headers.authorization.replace(/['"]+/g, '');
|
|
404
|
+
try {
|
|
405
|
+
var payload = jwt.verify(token, ssid);
|
|
406
|
+
req.user = payload;
|
|
407
|
+
getUser(token).then(function (getUserFetch) {
|
|
408
|
+
if (getUserFetch.response.status === 404) {
|
|
409
|
+
return res.status(404).send({
|
|
410
|
+
status: 'domain-not-found',
|
|
411
|
+
message: 'Dauth domain does not exist'
|
|
412
|
+
});
|
|
413
|
+
}
|
|
414
|
+
if (getUserFetch.response.status === 500) {
|
|
415
|
+
return res.status(500).send({
|
|
416
|
+
status: 'error',
|
|
417
|
+
message: 'Dauth server error'
|
|
418
|
+
});
|
|
419
|
+
}
|
|
420
|
+
if (getUserFetch.response.status === 200) {
|
|
421
|
+
req.user = getUserFetch.data;
|
|
422
|
+
console.log('node-fetch npm', req.user);
|
|
423
|
+
}
|
|
424
|
+
})["catch"](function (error) {
|
|
425
|
+
console.log('getDauthUser error', error);
|
|
426
|
+
});
|
|
427
|
+
return next();
|
|
428
|
+
} catch (error) {
|
|
429
|
+
if (error && (error == null ? void 0 : error.message) === 'jwt expired') {
|
|
430
|
+
return res.status(500).send({
|
|
431
|
+
status: 'token-expired',
|
|
432
|
+
message: 'El token ha expirado',
|
|
433
|
+
error: error,
|
|
434
|
+
mdKey: 'ensure_auth'
|
|
435
|
+
});
|
|
436
|
+
}
|
|
437
|
+
return res.status(500).send({
|
|
438
|
+
status: 'token-invalid',
|
|
439
|
+
message: 'El token no es válido',
|
|
440
|
+
error: error,
|
|
441
|
+
mdKey: 'ensure_auth'
|
|
442
|
+
});
|
|
443
|
+
}
|
|
444
|
+
});
|
|
445
|
+
case 2:
|
|
446
|
+
case "end":
|
|
447
|
+
return _context.stop();
|
|
448
|
+
}
|
|
449
|
+
}, _callee);
|
|
450
|
+
}));
|
|
451
|
+
return function dauth(_x2) {
|
|
452
|
+
return _ref2.apply(this, arguments);
|
|
33
453
|
};
|
|
34
|
-
};
|
|
454
|
+
}();
|
|
35
455
|
|
|
36
456
|
export { dauth };
|
|
37
457
|
//# 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\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
|
|
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';\nimport fetch from 'node-fetch';\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 user: 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\nasync function getUser(token: string) {\n const params = {\n method: 'GET',\n headers: {\n Authorization: token,\n 'Content-Type': 'application/json',\n },\n };\n const response = await fetch(\n `http://localhost:4012/api/v1/get-tenant-user/easymediacloud`,\n params\n );\n const data = await response.json();\n return { response, data };\n}\n\n// async function getDauthUser() {\n// const getUserFetch = await getUser()\n// if (getUserFetch.response.status === 404) {\n// return 404\n// // return res.status(404).send({ status: 'domain-not-found', message: 'Dauth domain does not exist' });\n// }\n// if (getUserFetch.response.status === 500) {\n// return 500\n// // return res.status(500).send({ status: 'error', message: 'Dauth server error' });\n// }\n// if (getUserFetch.response.status === 200) {\n// // req.user = getUserFetch.data as any\n// // console.log('node-fetch', req.user);\n// // next()\n// return getUserFetch.data\n// }\n// return null\n// }\n\nexport const dauth = async ({ ssid }: { ssid: string }) => {\n // const getUser = await getDauthUser()\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.user = payload;\n getUser(token)\n .then((getUserFetch: any) => {\n if (getUserFetch.response.status === 404) {\n return res.status(404).send({\n status: 'domain-not-found',\n message: 'Dauth domain does not exist',\n });\n }\n if (getUserFetch.response.status === 500) {\n return res\n .status(500)\n .send({ status: 'error', message: 'Dauth server error' });\n }\n if (getUserFetch.response.status === 200) {\n req.user = getUserFetch.data;\n console.log('node-fetch npm', req.user);\n }\n })\n .catch((error: any) => {\n console.log('getDauthUser error', error);\n });\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":["getUser","_x","_getUser","apply","arguments","_asyncToGenerator","_regeneratorRuntime","mark","_callee2","token","params","response","data","wrap","_callee2$","_context2","prev","next","method","headers","Authorization","fetch","sent","json","abrupt","stop","dauth","_ref2","_callee","_ref","ssid","_callee$","_context","req","res","authorization","status","send","mdKey","replace","payload","jwt","verify","user","then","getUserFetch","message","console","log","error","_x2"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAQ+B,SA6BhBA,OAAOA,CAAAC,EAAA;EAAA,OAAAC,QAAA,CAAAC,KAAA,OAAAC,SAAA;AAAA;AAiBtB;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAAA,SAAAF;EAAAA,QAAA,GAAAG,iBAAA,eAAAC,mBAAA,GAAAC,IAAA,CAjCA,SAAAC,SAAuBC,KAAa;IAAA,IA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,IAAI,CAAC;kBAC1BD,MAAM,EAAE,eAAe;kBACvBU,OAAO,EAAE,sBAAsB;kBAC/BG,KAAK,EAAEA,KAAK;kBACZX,KAAK,EAAE;iBACR,CAAC;;cAEJ,OAAOJ,GAAG,CAACE,MAAM,CAAC,GAAG,CAAC,CAACC,IAAI,CAAC;gBAC1BD,MAAM,EAAE,eAAe;gBACvBU,OAAO,EAAE,uBAAuB;gBAChCG,KAAK,EAAEA,KAAK;gBACZX,KAAK,EAAE;eACR,CAAC;;WAEL;QAAA;QAAA;UAAA,OAAAN,QAAA,CAAAP,IAAA;;OAAAG,OAAA;GACF;EAAA,gBAvDYF,KAAKA,CAAAwB,GAAA;IAAA,OAAAvB,KAAA,CAAAxB,KAAA,OAAAC,SAAA;;AAAA;;;;"}
|
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
|
+
user: 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
|
-
}) => (req: IRequestUser, res: TCustomResponse, next: NextFunction) => Handler | void
|
|
33
|
+
}) => Promise<(req: IRequestUser, res: TCustomResponse, next: NextFunction) => Handler | void>;
|
|
34
34
|
export {};
|
package/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "0.1.
|
|
2
|
+
"version": "0.1.62",
|
|
3
3
|
"license": "MIT",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"typings": "dist/index.d.ts",
|
|
@@ -56,6 +56,7 @@
|
|
|
56
56
|
"dependencies": {
|
|
57
57
|
"express": "^4.18.2",
|
|
58
58
|
"jsonwebtoken": "^9.0.2",
|
|
59
|
-
"mongoose": "^8.1.2"
|
|
59
|
+
"mongoose": "^8.1.2",
|
|
60
|
+
"node-fetch": "^3.3.2"
|
|
60
61
|
}
|
|
61
62
|
}
|
package/src/index.ts
CHANGED
|
@@ -6,6 +6,7 @@ import {
|
|
|
6
6
|
} from 'express';
|
|
7
7
|
import mongoose from 'mongoose';
|
|
8
8
|
import jwt from 'jsonwebtoken';
|
|
9
|
+
import fetch from 'node-fetch';
|
|
9
10
|
|
|
10
11
|
export interface IAccessToken {
|
|
11
12
|
_id: string | mongoose.Types.ObjectId;
|
|
@@ -19,7 +20,7 @@ export interface IAccessToken {
|
|
|
19
20
|
}
|
|
20
21
|
|
|
21
22
|
interface IRequestUser extends Request {
|
|
22
|
-
|
|
23
|
+
user: IAccessToken;
|
|
23
24
|
files: {
|
|
24
25
|
image: { path: string };
|
|
25
26
|
avatar: { path: string };
|
|
@@ -34,7 +35,43 @@ interface TCustomResponse extends ExpressResponse {
|
|
|
34
35
|
send(body?: any): any;
|
|
35
36
|
}
|
|
36
37
|
|
|
37
|
-
|
|
38
|
+
async function getUser(token: string) {
|
|
39
|
+
const params = {
|
|
40
|
+
method: 'GET',
|
|
41
|
+
headers: {
|
|
42
|
+
Authorization: token,
|
|
43
|
+
'Content-Type': 'application/json',
|
|
44
|
+
},
|
|
45
|
+
};
|
|
46
|
+
const response = await fetch(
|
|
47
|
+
`http://localhost:4012/api/v1/get-tenant-user/easymediacloud`,
|
|
48
|
+
params
|
|
49
|
+
);
|
|
50
|
+
const data = await response.json();
|
|
51
|
+
return { response, data };
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// async function getDauthUser() {
|
|
55
|
+
// const getUserFetch = await getUser()
|
|
56
|
+
// if (getUserFetch.response.status === 404) {
|
|
57
|
+
// return 404
|
|
58
|
+
// // return res.status(404).send({ status: 'domain-not-found', message: 'Dauth domain does not exist' });
|
|
59
|
+
// }
|
|
60
|
+
// if (getUserFetch.response.status === 500) {
|
|
61
|
+
// return 500
|
|
62
|
+
// // return res.status(500).send({ status: 'error', message: 'Dauth server error' });
|
|
63
|
+
// }
|
|
64
|
+
// if (getUserFetch.response.status === 200) {
|
|
65
|
+
// // req.user = getUserFetch.data as any
|
|
66
|
+
// // console.log('node-fetch', req.user);
|
|
67
|
+
// // next()
|
|
68
|
+
// return getUserFetch.data
|
|
69
|
+
// }
|
|
70
|
+
// return null
|
|
71
|
+
// }
|
|
72
|
+
|
|
73
|
+
export const dauth = async ({ ssid }: { ssid: string }) => {
|
|
74
|
+
// const getUser = await getDauthUser()
|
|
38
75
|
return (
|
|
39
76
|
req: IRequestUser,
|
|
40
77
|
res: TCustomResponse,
|
|
@@ -48,7 +85,28 @@ export const dauth = ({ ssid }: { ssid: string }) => {
|
|
|
48
85
|
const token = req.headers.authorization.replace(/['"]+/g, '');
|
|
49
86
|
try {
|
|
50
87
|
const payload = jwt.verify(token, ssid as string) as IAccessToken;
|
|
51
|
-
req.
|
|
88
|
+
req.user = payload;
|
|
89
|
+
getUser(token)
|
|
90
|
+
.then((getUserFetch: any) => {
|
|
91
|
+
if (getUserFetch.response.status === 404) {
|
|
92
|
+
return res.status(404).send({
|
|
93
|
+
status: 'domain-not-found',
|
|
94
|
+
message: 'Dauth domain does not exist',
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
if (getUserFetch.response.status === 500) {
|
|
98
|
+
return res
|
|
99
|
+
.status(500)
|
|
100
|
+
.send({ status: 'error', message: 'Dauth server error' });
|
|
101
|
+
}
|
|
102
|
+
if (getUserFetch.response.status === 200) {
|
|
103
|
+
req.user = getUserFetch.data;
|
|
104
|
+
console.log('node-fetch npm', req.user);
|
|
105
|
+
}
|
|
106
|
+
})
|
|
107
|
+
.catch((error: any) => {
|
|
108
|
+
console.log('getDauthUser error', error);
|
|
109
|
+
});
|
|
52
110
|
return next();
|
|
53
111
|
} catch (error) {
|
|
54
112
|
if (error && error?.message === 'jwt expired') {
|