dauth-md-node 0.1.63 → 0.1.65
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 +6 -3
- 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 +6 -3
- package/dist/dauth-md-node.esm.js.map +1 -1
- package/package.json +1 -1
- package/src/index.ts +26 -32
|
@@ -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,6 +338,8 @@ function _asyncToGenerator(fn) {
|
|
|
339
338
|
};
|
|
340
339
|
}
|
|
341
340
|
|
|
341
|
+
// import fetch from 'node-fetch';
|
|
342
|
+
var fetch = /*#__PURE__*/require('node-fetch');
|
|
342
343
|
function getUser(_x) {
|
|
343
344
|
return _getUser.apply(this, arguments);
|
|
344
345
|
} // async function getDauthUser() {
|
|
@@ -366,10 +367,10 @@ function _getUser() {
|
|
|
366
367
|
while (1) switch (_context2.prev = _context2.next) {
|
|
367
368
|
case 0:
|
|
368
369
|
params = {
|
|
369
|
-
method:
|
|
370
|
+
method: "GET",
|
|
370
371
|
headers: {
|
|
371
372
|
Authorization: token,
|
|
372
|
-
|
|
373
|
+
"Content-Type": "application/json"
|
|
373
374
|
}
|
|
374
375
|
};
|
|
375
376
|
_context2.next = 3;
|
|
@@ -427,8 +428,10 @@ var dauth = /*#__PURE__*/function () {
|
|
|
427
428
|
req.user = getUserFetch.data;
|
|
428
429
|
console.log('node-fetch npm', req.user);
|
|
429
430
|
}
|
|
431
|
+
return next();
|
|
430
432
|
})["catch"](function (error) {
|
|
431
433
|
console.log('getDauthUser error', error);
|
|
434
|
+
return next();
|
|
432
435
|
});
|
|
433
436
|
return next();
|
|
434
437
|
} catch (error) {
|
|
@@ -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';\nconst 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\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(`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};\n"],"names":["fetch","require","getUser","_x","_getUser","apply","arguments","_asyncToGenerator","_regeneratorRuntime","mark","_callee2","token","params","response","data","wrap","_callee2$","_context2","prev","next","method","headers","Authorization","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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"default"in t?t.default:t;function r(){r=function(){return e};var t,e={},n=Object.prototype,o=n.hasOwnProperty,a=Object.defineProperty||function(t,e,r){t[e]=r.value},i="function"==typeof Symbol?Symbol:{},u=i.iterator||"@@iterator",c=i.asyncIterator||"@@asyncIterator",s=i.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),i=new N(n||[]);return a(o,"_invoke",{value:k(t,r,i)}),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!==n&&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,a,i,u){var c=l(t[n],t,a);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,i,u)}),(function(t){r("throw",t,i,u)})):e.resolve(h).then((function(t){s.value=t,i(s)}),(function(t){return r("throw",t,i,u)}))}u(c.arg)}var n;a(this,"_invoke",{value:function(t,o){function a(){return new e((function(e,n){r(t,o,e,n)}))}return n=n?n.then(a,a):a()}})}function k(e,r,n){var o=p;return function(a,i){if(o===d)throw new Error("Generator is already running");if(o===v){if("throw"===a)throw i;return{value:t,done:!0}}for(n.method=a,n.arg=i;;){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 a=l(o,e.iterator,r.arg);if("throw"===a.type)return r.method="throw",r.arg=a.arg,r.delegate=null,y;var i=a.arg;return i?i.done?(r[e.resultName]=i.value,r.next=e.nextLoc,"return"!==r.method&&(r.method="next",r.arg=t),r.delegate=null,y):i:(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,a=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 a.next=a}}throw new TypeError(typeof e+" is not iterable")}return m.prototype=w,a(E,"constructor",{value:w,configurable:!0}),a(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,a){void 0===a&&(a=Promise);var i=new j(f(t,r,n,o),a);return e.isGeneratorFunction(r)?i:i.next().then((function(t){return t.done?t.value:i.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 a=this.tryEntries.length-1;a>=0;--a){var i=this.tryEntries[a],u=i.completion;if("root"===i.tryLoc)return n("end");if(i.tryLoc<=this.prev){var c=o.call(i,"catchLoc"),s=o.call(i,"finallyLoc");if(c&&s){if(this.prev<i.catchLoc)return n(i.catchLoc,!0);if(this.prev<i.finallyLoc)return n(i.finallyLoc)}else if(c){if(this.prev<i.catchLoc)return n(i.catchLoc,!0)}else{if(!s)throw new Error("try statement without catch or finally");if(this.prev<i.finallyLoc)return n(i.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 a=n;break}}a&&("break"===t||"continue"===t)&&a.tryLoc<=e&&e<=a.finallyLoc&&(a=null);var i=a?a.completion:{};return i.type=t,i.arg=e,a?(this.method="next",this.next=a.finallyLoc,y):this.complete(i)},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 n(t,e,r,n,o,a,i){try{var u=t[a](i),c=u.value}catch(t){return void r(t)}u.done?e(c):Promise.resolve(c).then(n,o)}function o(t){return function(){var e=this,r=arguments;return new Promise((function(o,a){var i=t.apply(e,r);function u(t){n(i,o,a,u,c,"next",t)}function c(t){n(i,o,a,u,c,"throw",t)}u(void 0)}))}}var a=require("node-fetch");function i(t){return u.apply(this,arguments)}function u(){return(u=o(r().mark((function t(e){var n,o;return r().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return n={method:"GET",headers:{Authorization:e,"Content-Type":"application/json"}},t.next=3,a("http://localhost:4012/api/v1/get-tenant-user/easymediacloud",n);case 3:return o=t.sent,t.next=6,o.json();case 6:return t.abrupt("return",{response:o,data:t.sent});case 8:case"end":return t.stop()}}),t)})))).apply(this,arguments)}exports.dauth=function(){var t=o(r().mark((function t(n){var o;return r().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return o=n.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 a=t.headers.authorization.replace(/['"]+/g,"");try{var u=e.verify(a,o);return t.user=u,i(a).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"}):(200===e.response.status&&(t.user=e.data,console.log("node-fetch npm",t.user)),n())})).catch((function(t){return console.log("getDauthUser error",t),n()})),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';\
|
|
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';\nconst 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\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(`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};\n"],"names":["fetch","require","getUser","_x","_getUser","apply","arguments","_asyncToGenerator","_regeneratorRuntime","mark","_callee2","token","params","response","wrap","_context2","prev","next","method","headers","Authorization","Content-Type","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":"+zNASA,IAAMA,EAAQC,QAAQ,cAAc,SA6BrBC,EAAOC,GAAA,O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,iBAAkBf,EAAIU,OAE7BzB,eACA,SAAC+B,GAER,OADAF,QAAQC,IAAI,qBAAsBC,GAC3B/B,OAEFA,IACP,MAAO+B,GACP,OAAIA,GAA4B,uBAAnBA,SAAAA,EAAOH,SACXZ,EAAIE,OAAO,KAAKC,KAAK,CAC1BD,OAAQ,gBACRU,QAAS,uBACTG,MAAOA,EACPX,MAAO,gBAGJJ,EAAIE,OAAO,KAAKC,KAAK,CAC1BD,OAAQ,gBACRU,QAAS,wBACTG,MAAOA,EACPX,MAAO,oBAIZ,OAAA,UAAA,OAAAN,EAAAL,UAAAE,OACF,gBAnDiBqB,GAAA,OAAAtB,EAAAtB,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,6 +332,8 @@ function _asyncToGenerator(fn) {
|
|
|
333
332
|
};
|
|
334
333
|
}
|
|
335
334
|
|
|
335
|
+
// import fetch from 'node-fetch';
|
|
336
|
+
var fetch = /*#__PURE__*/require('node-fetch');
|
|
336
337
|
function getUser(_x) {
|
|
337
338
|
return _getUser.apply(this, arguments);
|
|
338
339
|
} // async function getDauthUser() {
|
|
@@ -360,10 +361,10 @@ function _getUser() {
|
|
|
360
361
|
while (1) switch (_context2.prev = _context2.next) {
|
|
361
362
|
case 0:
|
|
362
363
|
params = {
|
|
363
|
-
method:
|
|
364
|
+
method: "GET",
|
|
364
365
|
headers: {
|
|
365
366
|
Authorization: token,
|
|
366
|
-
|
|
367
|
+
"Content-Type": "application/json"
|
|
367
368
|
}
|
|
368
369
|
};
|
|
369
370
|
_context2.next = 3;
|
|
@@ -421,8 +422,10 @@ var dauth = /*#__PURE__*/function () {
|
|
|
421
422
|
req.user = getUserFetch.data;
|
|
422
423
|
console.log('node-fetch npm', req.user);
|
|
423
424
|
}
|
|
425
|
+
return next();
|
|
424
426
|
})["catch"](function (error) {
|
|
425
427
|
console.log('getDauthUser error', error);
|
|
428
|
+
return next();
|
|
426
429
|
});
|
|
427
430
|
return next();
|
|
428
431
|
} catch (error) {
|
|
@@ -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';\nconst 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\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(`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};\n"],"names":["fetch","require","getUser","_x","_getUser","apply","arguments","_asyncToGenerator","_regeneratorRuntime","mark","_callee2","token","params","response","data","wrap","_callee2$","_context2","prev","next","method","headers","Authorization","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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,IAAID,YAAY,CAACjC,QAAQ,CAACwB,MAAM,KAAK,GAAG,EAAE;kBACxCH,GAAG,CAACU,IAAI,GAAGE,YAAY,CAAChC,IAAI;kBAC5BkC,OAAO,CAACC,GAAG,CAAC,gBAAgB,EAAEf,GAAG,CAACU,IAAI,CAAC;;gBAEzC,OAAOzB,IAAI,EAAE;eACd,CAAC,SAAM,CAAC,UAAC+B,KAAU;gBAClBF,OAAO,CAACC,GAAG,CAAC,oBAAoB,EAAEC,KAAK,CAAC;gBACxC,OAAO/B,IAAI,EAAE;eACd,CAAC;cACF,OAAOA,IAAI,EAAE;aACd,CAAC,OAAO+B,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;;WAGL;QAAA;QAAA;UAAA,OAAAN,QAAA,CAAAP,IAAA;;OAAAG,OAAA;GACF;EAAA,gBAnDYF,KAAKA,CAAAwB,GAAA;IAAA,OAAAvB,KAAA,CAAAvB,KAAA,OAAAC,SAAA;;AAAA;;;;"}
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -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;
|
|
@@ -37,18 +38,15 @@ interface TCustomResponse extends ExpressResponse {
|
|
|
37
38
|
|
|
38
39
|
async function getUser(token: string) {
|
|
39
40
|
const params = {
|
|
40
|
-
method:
|
|
41
|
+
method: "GET",
|
|
41
42
|
headers: {
|
|
42
43
|
Authorization: token,
|
|
43
|
-
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
const response = await fetch(
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
);
|
|
50
|
-
const data = await response.json();
|
|
51
|
-
return { response, data };
|
|
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 }
|
|
52
50
|
}
|
|
53
51
|
|
|
54
52
|
// async function getDauthUser() {
|
|
@@ -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') {
|
|
@@ -124,5 +117,6 @@ export const dauth = async ({ ssid }: { ssid: string }) => {
|
|
|
124
117
|
mdKey: 'ensure_auth',
|
|
125
118
|
});
|
|
126
119
|
}
|
|
120
|
+
|
|
127
121
|
};
|
|
128
122
|
};
|