dauth-md-node 0.1.63 → 0.1.66
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 +30 -58
- 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 +30 -58
- package/dist/dauth-md-node.esm.js.map +1 -1
- package/package.json +1 -1
- package/src/index.ts +30 -37
|
@@ -5,7 +5,6 @@ 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'));
|
|
9
8
|
|
|
10
9
|
function _regeneratorRuntime() {
|
|
11
10
|
_regeneratorRuntime = function () {
|
|
@@ -339,9 +338,19 @@ function _asyncToGenerator(fn) {
|
|
|
339
338
|
};
|
|
340
339
|
}
|
|
341
340
|
|
|
342
|
-
function getUser(
|
|
343
|
-
|
|
344
|
-
|
|
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() {
|
|
345
354
|
// const getUserFetch = await getUser()
|
|
346
355
|
// if (getUserFetch.response.status === 404) {
|
|
347
356
|
// return 404
|
|
@@ -359,39 +368,6 @@ function getUser(_x) {
|
|
|
359
368
|
// }
|
|
360
369
|
// return null
|
|
361
370
|
// }
|
|
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
371
|
var dauth = /*#__PURE__*/function () {
|
|
396
372
|
var _ref2 = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(_ref) {
|
|
397
373
|
var ssid;
|
|
@@ -410,26 +386,22 @@ var dauth = /*#__PURE__*/function () {
|
|
|
410
386
|
try {
|
|
411
387
|
var payload = jwt.verify(token, ssid);
|
|
412
388
|
req.user = payload;
|
|
413
|
-
getUser(token).then(
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
}
|
|
430
|
-
})["catch"](function (error) {
|
|
431
|
-
console.log('getDauthUser error', error);
|
|
432
|
-
});
|
|
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
|
+
// })
|
|
433
405
|
return next();
|
|
434
406
|
} catch (error) {
|
|
435
407
|
if (error && (error == null ? void 0 : error.message) === 'jwt expired') {
|
|
@@ -454,7 +426,7 @@ var dauth = /*#__PURE__*/function () {
|
|
|
454
426
|
}
|
|
455
427
|
}, _callee);
|
|
456
428
|
}));
|
|
457
|
-
return function dauth(
|
|
429
|
+
return function dauth(_x) {
|
|
458
430
|
return _ref2.apply(this, arguments);
|
|
459
431
|
};
|
|
460
432
|
}();
|
|
@@ -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';\
|
|
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// import fetch from 'node-fetch';\n// const fetch = require('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\n// async 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(`http://localhost:4012/api/v1/get-tenant-user/easymediacloud`, params)\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).then((getUserFetch: any) => {\n // if (getUserFetch.response.status === 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 res.status(500).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 // return next();\n // }).catch((error: any) => {\n // console.log('getDauthUser error', error);\n // return next();\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":["dauth","_ref2","_asyncToGenerator","_regeneratorRuntime","mark","_callee","_ref","ssid","wrap","_callee$","_context","prev","next","abrupt","req","res","headers","authorization","status","send","mdKey","token","replace","payload","jwt","verify","user","error","message","stop","_x","apply","arguments"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAsCA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;IAEaA,KAAK;EAAA,IAAAC,KAAA,gBAAAC,iBAAA,eAAAC,mBAAA,GAAAC,IAAA,CAAG,SAAAC,QAAAC,IAAA;IAAA,IAAAC,IAAA;IAAA,OAAAJ,mBAAA,GAAAK,IAAA,UAAAC,SAAAC,QAAA;MAAA,kBA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AAA,OAAA7B,KAAA,CAAA8B,KAAA,OAAAC,SAAA;;AAAA;;;;"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t,r=(t=require("jsonwebtoken"))&&"object"==typeof t&&"default"in t?t.default:t;function e(){e=function(){return r};var t,r={},n=Object.prototype,o=n.hasOwnProperty,i=Object.defineProperty||function(t,r,e){t[r]=e.value},a="function"==typeof Symbol?Symbol:{},u=a.iterator||"@@iterator",c=a.asyncIterator||"@@asyncIterator",s=a.toStringTag||"@@toStringTag";function h(t,r,e){return Object.defineProperty(t,r,{value:e,enumerable:!0,configurable:!0,writable:!0}),t[r]}try{h({},"")}catch(t){h=function(t,r,e){return t[r]=e}}function f(t,r,e,n){var o=Object.create((r&&r.prototype instanceof g?r:g).prototype),a=new N(n||[]);return i(o,"_invoke",{value:k(t,e,a)}),o}function l(t,r,e){try{return{type:"normal",arg:t.call(r,e)}}catch(t){return{type:"throw",arg:t}}}r.wrap=f;var p="suspendedStart",y="executing",v="completed",d={};function g(){}function m(){}function w(){}var x={};h(x,u,(function(){return this}));var b=Object.getPrototypeOf,L=b&&b(b(S([])));L&&L!==n&&o.call(L,u)&&(x=L);var E=w.prototype=g.prototype=Object.create(x);function _(t){["next","throw","return"].forEach((function(r){h(t,r,(function(t){return this._invoke(r,t)}))}))}function j(t,r){function e(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")?r.resolve(h.__await).then((function(t){e("next",t,a,u)}),(function(t){e("throw",t,a,u)})):r.resolve(h).then((function(t){s.value=t,a(s)}),(function(t){return e("throw",t,a,u)}))}u(c.arg)}var n;i(this,"_invoke",{value:function(t,o){function i(){return new r((function(r,n){e(t,o,r,n)}))}return n=n?n.then(i,i):i()}})}function k(r,e,n){var o=p;return function(i,a){if(o===y)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===d)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=y;var s=l(r,e,n);if("normal"===s.type){if(o=n.done?v:"suspendedYield",s.arg===d)continue;return{value:s.arg,done:n.done}}"throw"===s.type&&(o=v,n.method="throw",n.arg=s.arg)}}}function O(r,e){var n=e.method,o=r.iterator[n];if(o===t)return e.delegate=null,"throw"===n&&r.iterator.return&&(e.method="return",e.arg=t,O(r,e),"throw"===e.method)||"return"!==n&&(e.method="throw",e.arg=new TypeError("The iterator does not provide a '"+n+"' method")),d;var i=l(o,r.iterator,e.arg);if("throw"===i.type)return e.method="throw",e.arg=i.arg,e.delegate=null,d;var a=i.arg;return a?a.done?(e[r.resultName]=a.value,e.next=r.nextLoc,"return"!==e.method&&(e.method="next",e.arg=t),e.delegate=null,d):a:(e.method="throw",e.arg=new TypeError("iterator result is not an object"),e.delegate=null,d)}function P(t){var r={tryLoc:t[0]};1 in t&&(r.catchLoc=t[1]),2 in t&&(r.finallyLoc=t[2],r.afterLoc=t[3]),this.tryEntries.push(r)}function G(t){var r=t.completion||{};r.type="normal",delete r.arg,t.completion=r}function N(t){this.tryEntries=[{tryLoc:"root"}],t.forEach(P,this),this.reset(!0)}function S(r){if(r||""===r){var e=r[u];if(e)return e.call(r);if("function"==typeof r.next)return r;if(!isNaN(r.length)){var n=-1,i=function e(){for(;++n<r.length;)if(o.call(r,n))return e.value=r[n],e.done=!1,e;return e.value=t,e.done=!0,e};return i.next=i}}throw new TypeError(typeof r+" 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"),r.isGeneratorFunction=function(t){var r="function"==typeof t&&t.constructor;return!!r&&(r===m||"GeneratorFunction"===(r.displayName||r.name))},r.mark=function(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,w):(t.__proto__=w,h(t,s,"GeneratorFunction")),t.prototype=Object.create(E),t},r.awrap=function(t){return{__await:t}},_(j.prototype),h(j.prototype,c,(function(){return this})),r.AsyncIterator=j,r.async=function(t,e,n,o,i){void 0===i&&(i=Promise);var a=new j(f(t,e,n,o),i);return r.isGeneratorFunction(e)?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]"})),r.keys=function(t){var r=Object(t),e=[];for(var n in r)e.push(n);return e.reverse(),function t(){for(;e.length;){var n=e.pop();if(n in r)return t.value=n,t.done=!1,t}return t.done=!0,t}},r.values=S,N.prototype={constructor:N,reset:function(r){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),!r)for(var e in this)"t"===e.charAt(0)&&o.call(this,e)&&!isNaN(+e.slice(1))&&(this[e]=t)},stop:function(){this.done=!0;var t=this.tryEntries[0].completion;if("throw"===t.type)throw t.arg;return this.rval},dispatchException:function(r){if(this.done)throw r;var e=this;function n(n,o){return u.type="throw",u.arg=r,e.next=n,o&&(e.method="next",e.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,r){for(var e=this.tryEntries.length-1;e>=0;--e){var n=this.tryEntries[e];if(n.tryLoc<=this.prev&&o.call(n,"finallyLoc")&&this.prev<n.finallyLoc){var i=n;break}}i&&("break"===t||"continue"===t)&&i.tryLoc<=r&&r<=i.finallyLoc&&(i=null);var a=i?i.completion:{};return a.type=t,a.arg=r,i?(this.method="next",this.next=i.finallyLoc,d):this.complete(a)},complete:function(t,r){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&&r&&(this.next=r),d},finish:function(t){for(var r=this.tryEntries.length-1;r>=0;--r){var e=this.tryEntries[r];if(e.finallyLoc===t)return this.complete(e.completion,e.afterLoc),G(e),d}},catch:function(t){for(var r=this.tryEntries.length-1;r>=0;--r){var e=this.tryEntries[r];if(e.tryLoc===t){var n=e.completion;if("throw"===n.type){var o=n.arg;G(e)}return o}}throw new Error("illegal catch attempt")},delegateYield:function(r,e,n){return this.delegate={iterator:S(r),resultName:e,nextLoc:n},"next"===this.method&&(this.arg=t),d}},r}function n(t,r,e,n,o,i,a){try{var u=t[i](a),c=u.value}catch(t){return void e(t)}u.done?r(c):Promise.resolve(c).then(n,o)}function o(t){return function(){var r=this,e=arguments;return new Promise((function(o,i){var a=t.apply(r,e);function u(t){n(a,o,i,u,c,"next",t)}function c(t){n(a,o,i,u,c,"throw",t)}u(void 0)}))}}exports.dauth=function(){var t=o(e().mark((function t(n){var o;return e().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return o=n.ssid,t.abrupt("return",(function(t,e,n){if(!t.headers.authorization)return e.status(403).send({status:"token-not-found",mdKey:"ensure_auth"});var i=t.headers.authorization.replace(/['"]+/g,"");try{var a=r.verify(i,o);return t.user=a,n()}catch(t){return t&&"jwt expired"===(null==t?void 0:t.message)?e.status(500).send({status:"token-expired",message:"El token ha expirado",error:t,mdKey:"ensure_auth"}):e.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(r){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';\
|
|
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// import fetch from 'node-fetch';\n// const fetch = require('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\n// async 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(`http://localhost:4012/api/v1/get-tenant-user/easymediacloud`, params)\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).then((getUserFetch: any) => {\n // if (getUserFetch.response.status === 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 res.status(500).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 // return next();\n // }).catch((error: any) => {\n // console.log('getDauthUser error', error);\n // return next();\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":["_ref2","_asyncToGenerator","_regeneratorRuntime","mark","_callee","_ref","ssid","wrap","_context","prev","next","abrupt","req","res","headers","authorization","status","send","mdKey","token","replace","payload","jwt","verify","user","error","message","stop","_x","apply","arguments"],"mappings":"w1NAsEkB,IAAAA,EAAAC,EAAAC,IAAAC,MAAG,SAAAC,EAAAC,GAAA,IAAAC,EAAA,OAAAJ,IAAAK,eAAAC,GAAA,cAAAA,EAAAC,KAAAD,EAAAE,MAAA,OAAa,OAAJJ,EAAID,EAAJC,KAAIE,EAAAG,iBAEzB,SACLC,EACAC,EACAH,GAEA,IAAKE,EAAIE,QAAQC,cACf,OAAOF,EACJG,OAAO,KACPC,KAAK,CAAED,OAAQ,kBAAmBE,MAAO,gBAE9C,IAAMC,EAAQP,EAAIE,QAAQC,cAAcK,QAAQ,SAAU,IAC1D,IACE,IAAMC,EAAUC,EAAIC,OAAOJ,EAAOb,GAkBlC,OAjBAM,EAAIY,KAAOH,EAiBJX,IACP,MAAOe,GACP,OAAIA,GAA4B,uBAAnBA,SAAAA,EAAOC,SACXb,EAAIG,OAAO,KAAKC,KAAK,CAC1BD,OAAQ,gBACRU,QAAS,uBACTD,MAAOA,EACPP,MAAO,gBAGJL,EAAIG,OAAO,KAAKC,KAAK,CAC1BD,OAAQ,gBACRU,QAAS,wBACTD,MAAOA,EACPP,MAAO,oBAGZ,OAAA,UAAA,OAAAV,EAAAmB,UAAAvB,OACF,gBAlDiBwB,GAAA,OAAA5B,EAAA6B,WAAAC"}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import jwt from 'jsonwebtoken';
|
|
2
|
-
import fetch from 'node-fetch';
|
|
3
2
|
|
|
4
3
|
function _regeneratorRuntime() {
|
|
5
4
|
_regeneratorRuntime = function () {
|
|
@@ -333,9 +332,19 @@ function _asyncToGenerator(fn) {
|
|
|
333
332
|
};
|
|
334
333
|
}
|
|
335
334
|
|
|
336
|
-
function getUser(
|
|
337
|
-
|
|
338
|
-
|
|
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() {
|
|
339
348
|
// const getUserFetch = await getUser()
|
|
340
349
|
// if (getUserFetch.response.status === 404) {
|
|
341
350
|
// return 404
|
|
@@ -353,39 +362,6 @@ function getUser(_x) {
|
|
|
353
362
|
// }
|
|
354
363
|
// return null
|
|
355
364
|
// }
|
|
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
365
|
var dauth = /*#__PURE__*/function () {
|
|
390
366
|
var _ref2 = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(_ref) {
|
|
391
367
|
var ssid;
|
|
@@ -404,26 +380,22 @@ var dauth = /*#__PURE__*/function () {
|
|
|
404
380
|
try {
|
|
405
381
|
var payload = jwt.verify(token, ssid);
|
|
406
382
|
req.user = payload;
|
|
407
|
-
getUser(token).then(
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
}
|
|
424
|
-
})["catch"](function (error) {
|
|
425
|
-
console.log('getDauthUser error', error);
|
|
426
|
-
});
|
|
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
|
+
// })
|
|
427
399
|
return next();
|
|
428
400
|
} catch (error) {
|
|
429
401
|
if (error && (error == null ? void 0 : error.message) === 'jwt expired') {
|
|
@@ -448,7 +420,7 @@ var dauth = /*#__PURE__*/function () {
|
|
|
448
420
|
}
|
|
449
421
|
}, _callee);
|
|
450
422
|
}));
|
|
451
|
-
return function dauth(
|
|
423
|
+
return function dauth(_x) {
|
|
452
424
|
return _ref2.apply(this, arguments);
|
|
453
425
|
};
|
|
454
426
|
}();
|
|
@@ -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';\
|
|
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// import fetch from 'node-fetch';\n// const fetch = require('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\n// async 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(`http://localhost:4012/api/v1/get-tenant-user/easymediacloud`, params)\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).then((getUserFetch: any) => {\n // if (getUserFetch.response.status === 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 res.status(500).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 // return next();\n // }).catch((error: any) => {\n // console.log('getDauthUser error', error);\n // return next();\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":["dauth","_ref2","_asyncToGenerator","_regeneratorRuntime","mark","_callee","_ref","ssid","wrap","_callee$","_context","prev","next","abrupt","req","res","headers","authorization","status","send","mdKey","token","replace","payload","jwt","verify","user","error","message","stop","_x","apply","arguments"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAsCA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;IAEaA,KAAK;EAAA,IAAAC,KAAA,gBAAAC,iBAAA,eAAAC,mBAAA,GAAAC,IAAA,CAAG,SAAAC,QAAAC,IAAA;IAAA,IAAAC,IAAA;IAAA,OAAAJ,mBAAA,GAAAK,IAAA,UAAAC,SAAAC,QAAA;MAAA,kBAAAA,QAAA,CAAAC,IAAA,GAAAD,QAAA,CAAAE,IAAA;QAAA;UAASL,IAAI,GAAAD,IAAA,CAAJC,IAAI;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
|
@@ -6,7 +6,8 @@ import {
|
|
|
6
6
|
} from 'express';
|
|
7
7
|
import mongoose from 'mongoose';
|
|
8
8
|
import jwt from 'jsonwebtoken';
|
|
9
|
-
import fetch from 'node-fetch';
|
|
9
|
+
// import fetch from 'node-fetch';
|
|
10
|
+
// const fetch = require('node-fetch');
|
|
10
11
|
|
|
11
12
|
export interface IAccessToken {
|
|
12
13
|
_id: string | mongoose.Types.ObjectId;
|
|
@@ -35,21 +36,18 @@ interface TCustomResponse extends ExpressResponse {
|
|
|
35
36
|
send(body?: any): any;
|
|
36
37
|
}
|
|
37
38
|
|
|
38
|
-
async function getUser(token: string) {
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
const data = await response.json();
|
|
51
|
-
return { response, data };
|
|
52
|
-
}
|
|
39
|
+
// async function getUser(token: string) {
|
|
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
|
+
// }
|
|
53
51
|
|
|
54
52
|
// async function getDauthUser() {
|
|
55
53
|
// const getUserFetch = await getUser()
|
|
@@ -86,27 +84,22 @@ export const dauth = async ({ ssid }: { ssid: string }) => {
|
|
|
86
84
|
try {
|
|
87
85
|
const payload = jwt.verify(token, ssid as string) as IAccessToken;
|
|
88
86
|
req.user = payload;
|
|
89
|
-
getUser(token)
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
}
|
|
106
|
-
})
|
|
107
|
-
.catch((error: any) => {
|
|
108
|
-
console.log('getDauthUser error', error);
|
|
109
|
-
});
|
|
87
|
+
// getUser(token).then((getUserFetch: any) => {
|
|
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
|
+
// })
|
|
110
103
|
return next();
|
|
111
104
|
} catch (error) {
|
|
112
105
|
if (error && error?.message === 'jwt expired') {
|