dauth-md-node 0.1.65 → 0.1.67
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 -61
- 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 -61
- package/dist/dauth-md-node.esm.js.map +1 -1
- package/package.json +2 -4
- package/src/index.ts +29 -30
|
@@ -338,11 +338,19 @@ function _asyncToGenerator(fn) {
|
|
|
338
338
|
};
|
|
339
339
|
}
|
|
340
340
|
|
|
341
|
-
//
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
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() {
|
|
346
354
|
// const getUserFetch = await getUser()
|
|
347
355
|
// if (getUserFetch.response.status === 404) {
|
|
348
356
|
// return 404
|
|
@@ -360,39 +368,6 @@ function getUser(_x) {
|
|
|
360
368
|
// }
|
|
361
369
|
// return null
|
|
362
370
|
// }
|
|
363
|
-
function _getUser() {
|
|
364
|
-
_getUser = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(token) {
|
|
365
|
-
var params, response, data;
|
|
366
|
-
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
367
|
-
while (1) switch (_context2.prev = _context2.next) {
|
|
368
|
-
case 0:
|
|
369
|
-
params = {
|
|
370
|
-
method: "GET",
|
|
371
|
-
headers: {
|
|
372
|
-
Authorization: token,
|
|
373
|
-
"Content-Type": "application/json"
|
|
374
|
-
}
|
|
375
|
-
};
|
|
376
|
-
_context2.next = 3;
|
|
377
|
-
return fetch("http://localhost:4012/api/v1/get-tenant-user/easymediacloud", params);
|
|
378
|
-
case 3:
|
|
379
|
-
response = _context2.sent;
|
|
380
|
-
_context2.next = 6;
|
|
381
|
-
return response.json();
|
|
382
|
-
case 6:
|
|
383
|
-
data = _context2.sent;
|
|
384
|
-
return _context2.abrupt("return", {
|
|
385
|
-
response: response,
|
|
386
|
-
data: data
|
|
387
|
-
});
|
|
388
|
-
case 8:
|
|
389
|
-
case "end":
|
|
390
|
-
return _context2.stop();
|
|
391
|
-
}
|
|
392
|
-
}, _callee2);
|
|
393
|
-
}));
|
|
394
|
-
return _getUser.apply(this, arguments);
|
|
395
|
-
}
|
|
396
371
|
var dauth = /*#__PURE__*/function () {
|
|
397
372
|
var _ref2 = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(_ref) {
|
|
398
373
|
var ssid;
|
|
@@ -411,28 +386,22 @@ var dauth = /*#__PURE__*/function () {
|
|
|
411
386
|
try {
|
|
412
387
|
var payload = jwt.verify(token, ssid);
|
|
413
388
|
req.user = payload;
|
|
414
|
-
getUser(token).then(
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
}
|
|
431
|
-
return next();
|
|
432
|
-
})["catch"](function (error) {
|
|
433
|
-
console.log('getDauthUser error', error);
|
|
434
|
-
return next();
|
|
435
|
-
});
|
|
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
|
+
// })
|
|
436
405
|
return next();
|
|
437
406
|
} catch (error) {
|
|
438
407
|
if (error && (error == null ? void 0 : error.message) === 'jwt expired') {
|
|
@@ -457,7 +426,7 @@ var dauth = /*#__PURE__*/function () {
|
|
|
457
426
|
}
|
|
458
427
|
}, _callee);
|
|
459
428
|
}));
|
|
460
|
-
return function dauth(
|
|
429
|
+
return function dauth(_x) {
|
|
461
430
|
return _ref2.apply(this, arguments);
|
|
462
431
|
};
|
|
463
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';\n// import fetch from 'node-fetch';\
|
|
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,kBAAAA,QAAA,CAAAC,IAAA,GAAAD,QAAA,CAAAE,IAAA;QAAA;UAASL,IAAI,GAAAD,IAAA,CAAJC,IAAI;UAAA,OAAAG,QAAA,CAAAG,MAAA,WAEzB,UACLC,GAAiB,EACjBC,GAAoB,EACpBH,IAAkB;YAElB,IAAI,CAACE,GAAG,CAACE,OAAO,CAACC,aAAa,EAAE;cAC9B,OAAOF,GAAG,CACPG,MAAM,CAAC,GAAG,CAAC,CACXC,IAAI,CAAC;gBAAED,MAAM,EAAE,iBAAiB;gBAAEE,KAAK,EAAE;eAAe,CAAC;;YAE9D,IAAMC,KAAK,GAAGP,GAAG,CAACE,OAAO,CAACC,aAAa,CAACK,OAAO,CAAC,QAAQ,EAAE,EAAE,CAAC;YAC7D,IAAI;cACF,IAAMC,OAAO,GAAGC,GAAG,CAACC,MAAM,CAACJ,KAAK,EAAEd,IAAc,CAAiB;cACjEO,GAAG,CAACY,IAAI,GAAGH,OAAO;;;;;;;;;;;;;;;;;cAiBlB,OAAOX,IAAI,EAAE;aACd,CAAC,OAAOe,KAAK,EAAE;cACd,IAAIA,KAAK,IAAI,CAAAA,KAAK,oBAALA,KAAK,CAAEC,OAAO,MAAK,aAAa,EAAE;gBAC7C,OAAOb,GAAG,CAACG,MAAM,CAAC,GAAG,CAAC,CAACC,IAAI,CAAC;kBAC1BD,MAAM,EAAE,eAAe;kBACvBU,OAAO,EAAE,sBAAsB;kBAC/BD,KAAK,EAAEA,KAAK;kBACZP,KAAK,EAAE;iBACR,CAAC;;cAEJ,OAAOL,GAAG,CAACG,MAAM,CAAC,GAAG,CAAC,CAACC,IAAI,CAAC;gBAC1BD,MAAM,EAAE,eAAe;gBACvBU,OAAO,EAAE,uBAAuB;gBAChCD,KAAK,EAAEA,KAAK;gBACZP,KAAK,EAAE;eACR,CAAC;;WAEL;QAAA;QAAA;UAAA,OAAAV,QAAA,CAAAmB,IAAA;;OAAAxB,OAAA;GACF;EAAA,gBAlDYL,KAAKA,CAAA8B,EAAA;IAAA,OAAA7B,KAAA,CAAA8B,KAAA,OAAAC,SAAA;;AAAA;;;;"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t,
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var 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';\n// import fetch from 'node-fetch';\
|
|
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"}
|
|
@@ -332,11 +332,19 @@ function _asyncToGenerator(fn) {
|
|
|
332
332
|
};
|
|
333
333
|
}
|
|
334
334
|
|
|
335
|
-
//
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
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() {
|
|
340
348
|
// const getUserFetch = await getUser()
|
|
341
349
|
// if (getUserFetch.response.status === 404) {
|
|
342
350
|
// return 404
|
|
@@ -354,39 +362,6 @@ function getUser(_x) {
|
|
|
354
362
|
// }
|
|
355
363
|
// return null
|
|
356
364
|
// }
|
|
357
|
-
function _getUser() {
|
|
358
|
-
_getUser = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(token) {
|
|
359
|
-
var params, response, data;
|
|
360
|
-
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
361
|
-
while (1) switch (_context2.prev = _context2.next) {
|
|
362
|
-
case 0:
|
|
363
|
-
params = {
|
|
364
|
-
method: "GET",
|
|
365
|
-
headers: {
|
|
366
|
-
Authorization: token,
|
|
367
|
-
"Content-Type": "application/json"
|
|
368
|
-
}
|
|
369
|
-
};
|
|
370
|
-
_context2.next = 3;
|
|
371
|
-
return fetch("http://localhost:4012/api/v1/get-tenant-user/easymediacloud", params);
|
|
372
|
-
case 3:
|
|
373
|
-
response = _context2.sent;
|
|
374
|
-
_context2.next = 6;
|
|
375
|
-
return response.json();
|
|
376
|
-
case 6:
|
|
377
|
-
data = _context2.sent;
|
|
378
|
-
return _context2.abrupt("return", {
|
|
379
|
-
response: response,
|
|
380
|
-
data: data
|
|
381
|
-
});
|
|
382
|
-
case 8:
|
|
383
|
-
case "end":
|
|
384
|
-
return _context2.stop();
|
|
385
|
-
}
|
|
386
|
-
}, _callee2);
|
|
387
|
-
}));
|
|
388
|
-
return _getUser.apply(this, arguments);
|
|
389
|
-
}
|
|
390
365
|
var dauth = /*#__PURE__*/function () {
|
|
391
366
|
var _ref2 = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(_ref) {
|
|
392
367
|
var ssid;
|
|
@@ -405,28 +380,22 @@ var dauth = /*#__PURE__*/function () {
|
|
|
405
380
|
try {
|
|
406
381
|
var payload = jwt.verify(token, ssid);
|
|
407
382
|
req.user = payload;
|
|
408
|
-
getUser(token).then(
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
}
|
|
425
|
-
return next();
|
|
426
|
-
})["catch"](function (error) {
|
|
427
|
-
console.log('getDauthUser error', error);
|
|
428
|
-
return next();
|
|
429
|
-
});
|
|
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
|
+
// })
|
|
430
399
|
return next();
|
|
431
400
|
} catch (error) {
|
|
432
401
|
if (error && (error == null ? void 0 : error.message) === 'jwt expired') {
|
|
@@ -451,7 +420,7 @@ var dauth = /*#__PURE__*/function () {
|
|
|
451
420
|
}
|
|
452
421
|
}, _callee);
|
|
453
422
|
}));
|
|
454
|
-
return function dauth(
|
|
423
|
+
return function dauth(_x) {
|
|
455
424
|
return _ref2.apply(this, arguments);
|
|
456
425
|
};
|
|
457
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';\n// import fetch from 'node-fetch';\
|
|
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;UAAA,OAAAG,QAAA,CAAAG,MAAA,WAEzB,UACLC,GAAiB,EACjBC,GAAoB,EACpBH,IAAkB;YAElB,IAAI,CAACE,GAAG,CAACE,OAAO,CAACC,aAAa,EAAE;cAC9B,OAAOF,GAAG,CACPG,MAAM,CAAC,GAAG,CAAC,CACXC,IAAI,CAAC;gBAAED,MAAM,EAAE,iBAAiB;gBAAEE,KAAK,EAAE;eAAe,CAAC;;YAE9D,IAAMC,KAAK,GAAGP,GAAG,CAACE,OAAO,CAACC,aAAa,CAACK,OAAO,CAAC,QAAQ,EAAE,EAAE,CAAC;YAC7D,IAAI;cACF,IAAMC,OAAO,GAAGC,GAAG,CAACC,MAAM,CAACJ,KAAK,EAAEd,IAAc,CAAiB;cACjEO,GAAG,CAACY,IAAI,GAAGH,OAAO;;;;;;;;;;;;;;;;;cAiBlB,OAAOX,IAAI,EAAE;aACd,CAAC,OAAOe,KAAK,EAAE;cACd,IAAIA,KAAK,IAAI,CAAAA,KAAK,oBAALA,KAAK,CAAEC,OAAO,MAAK,aAAa,EAAE;gBAC7C,OAAOb,GAAG,CAACG,MAAM,CAAC,GAAG,CAAC,CAACC,IAAI,CAAC;kBAC1BD,MAAM,EAAE,eAAe;kBACvBU,OAAO,EAAE,sBAAsB;kBAC/BD,KAAK,EAAEA,KAAK;kBACZP,KAAK,EAAE;iBACR,CAAC;;cAEJ,OAAOL,GAAG,CAACG,MAAM,CAAC,GAAG,CAAC,CAACC,IAAI,CAAC;gBAC1BD,MAAM,EAAE,eAAe;gBACvBU,OAAO,EAAE,uBAAuB;gBAChCD,KAAK,EAAEA,KAAK;gBACZP,KAAK,EAAE;eACR,CAAC;;WAEL;QAAA;QAAA;UAAA,OAAAV,QAAA,CAAAmB,IAAA;;OAAAxB,OAAA;GACF;EAAA,gBAlDYL,KAAKA,CAAA8B,EAAA;IAAA,OAAA7B,KAAA,CAAA8B,KAAA,OAAAC,SAAA;;AAAA;;;;"}
|
package/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "0.1.
|
|
2
|
+
"version": "0.1.67",
|
|
3
3
|
"license": "MIT",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"typings": "dist/index.d.ts",
|
|
@@ -47,7 +47,6 @@
|
|
|
47
47
|
"@size-limit/preset-small-lib": "^11.0.2",
|
|
48
48
|
"@types/express": "^4.17.21",
|
|
49
49
|
"@types/jsonwebtoken": "^9.0.5",
|
|
50
|
-
"@types/node-fetch": "^2.6.11",
|
|
51
50
|
"husky": "^9.0.11",
|
|
52
51
|
"size-limit": "^11.0.2",
|
|
53
52
|
"tsdx": "^0.14.1",
|
|
@@ -57,7 +56,6 @@
|
|
|
57
56
|
"dependencies": {
|
|
58
57
|
"express": "^4.18.2",
|
|
59
58
|
"jsonwebtoken": "^9.0.2",
|
|
60
|
-
"mongoose": "^8.1.2"
|
|
61
|
-
"node-fetch": "^2.6.1"
|
|
59
|
+
"mongoose": "^8.1.2"
|
|
62
60
|
}
|
|
63
61
|
}
|
package/src/index.ts
CHANGED
|
@@ -7,7 +7,7 @@ import {
|
|
|
7
7
|
import mongoose from 'mongoose';
|
|
8
8
|
import jwt from 'jsonwebtoken';
|
|
9
9
|
// import fetch from 'node-fetch';
|
|
10
|
-
const fetch = require('node-fetch');
|
|
10
|
+
// const fetch = require('node-fetch');
|
|
11
11
|
|
|
12
12
|
export interface IAccessToken {
|
|
13
13
|
_id: string | mongoose.Types.ObjectId;
|
|
@@ -36,18 +36,18 @@ interface TCustomResponse extends ExpressResponse {
|
|
|
36
36
|
send(body?: any): any;
|
|
37
37
|
}
|
|
38
38
|
|
|
39
|
-
async function getUser(token: string) {
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
}
|
|
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
|
+
// }
|
|
51
51
|
|
|
52
52
|
// async function getDauthUser() {
|
|
53
53
|
// const getUserFetch = await getUser()
|
|
@@ -84,22 +84,22 @@ export const dauth = async ({ ssid }: { ssid: string }) => {
|
|
|
84
84
|
try {
|
|
85
85
|
const payload = jwt.verify(token, ssid as string) as IAccessToken;
|
|
86
86
|
req.user = payload;
|
|
87
|
-
getUser(token).then((getUserFetch: any) => {
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
}).catch((error: any) => {
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
})
|
|
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
|
+
// })
|
|
103
103
|
return next();
|
|
104
104
|
} catch (error) {
|
|
105
105
|
if (error && error?.message === 'jwt expired') {
|
|
@@ -117,6 +117,5 @@ export const dauth = async ({ ssid }: { ssid: string }) => {
|
|
|
117
117
|
mdKey: 'ensure_auth',
|
|
118
118
|
});
|
|
119
119
|
}
|
|
120
|
-
|
|
121
120
|
};
|
|
122
121
|
};
|