{"_id":"x-auth-service","_rev":"4-9e63f9316346006b7ad62c56370403e0","name":"x-auth-service","dist-tags":{"latest":"1.0.2"},"versions":{"1.0.0":{"name":"x-auth-service","version":"1.0.0","author":{"name":"Francois J. Aouad"},"license":"MIT","_id":"x-auth-service@1.0.0","maintainers":[{"name":"francoisaouad","email":"francois.j.aouad@gmail.com"}],"homepage":"https://github.com/FrancoisAouad/X-Auth#readme","bugs":{"url":"https://github.com/FrancoisAouad/X-Auth/issues"},"dist":{"shasum":"e24aeb8e50fc4ef297a064097182609c7f2772a2","tarball":"https://registry.npmjs.org/x-auth-service/-/x-auth-service-1.0.0.tgz","fileCount":26,"integrity":"sha512-f6W2IKVHtopfcHnbiz9ZfVC7YW9n490mKR6C5/ttvsWbPS1+ysulTqpIs537hoAATVV+2wSmkj1efQcl0jxzpg==","signatures":[{"sig":"MEUCICmkpDspjdQUGpimwmZ4l3zRiDD4pqpsFU5KWI1sTbq6AiEA+2mQ7XN7575JCcwWiH45X34zOkqKJomWZcEnNmRPzgU=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":45450,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJjMbp6ACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2Vmo/HRAAoYrfF8Mq5VvwFKj62KoMWFwHF1pL0iaQK8gBk193+VIL5i6c\r\nEENo4eg1VxAebes5tET45aBJQqEk4yBsXbF7zvrTgDK1T3t8KAHuqhVuliHy\r\n1+0z6X9QAP0Agitwh/tt+Qk9DiCYrXt9jbQk92AxF1DVA0SeWm7th/dbSwzk\r\ntXbXMMnzP8jcLOG2b4yhltfC3scWVYPbo9jXeTmdQ4rf7nSatV+zO+mBfvpr\r\nTfV9l9agVrP8AjILHyCa5Ghi8Ermoc9QeT4FRF/p2WNo9e24HyApBzr6dViN\r\nuus74aIbRmkzgaox3dBbFZNath/hiBxvi3m9UUr05WWcvB7uTU2NoZdTQfb1\r\nUvuo07RNLcfn3lZSFCoirLR17CGsQQMRBJ4T6us9snbWoGCbvGANCHzrGjlg\r\nXJ8zsCqvY7xQFIWE29wI+vjiZXfNO2X56rFZfpYzJkjWa8NhdyAu20u1V4rC\r\nhvHfAZXov5rfUjnGkrlKMUoNQbfpMZdFLSFE6FS6fTCF07aVGRxVfr5J6Vza\r\n2LURpHTjONjEg6fNh9iR2mMfPvxC+GJLxNKFf2Q97jxWR8XrWeyYifkCh2kg\r\nlSgNgAtKtrPTBapcduEw0f1QjVGTfYUMbnRn5tGLUTjtWtAbVtvLucJPrQNw\r\nE6OEKAR4zk//0FJJnhRcsF1IsEX5P4iq8EM=\r\n=pCY4\r\n-----END PGP SIGNATURE-----\r\n"},"main":"dist/index.js","scripts":{"build":"tsc -p tsconfig.json","clean":"rm -r node_modules && package-lock.json","mongo":"mongod","redis":"redis-server","start":"nodemon","install-dev":"npm i"},"_npmUser":{"name":"francoisaouad","email":"francois.j.aouad@gmail.com"},"repository":{"url":"git+https://github.com/FrancoisAouad/X-Auth.git","type":"git"},"_npmVersion":"8.18.0","description":"Simple Auth library for REST APIs using expressJS","directories":{},"_nodeVersion":"18.8.0","dependencies":{"joi":"^17.6.0","cors":"^2.8.5","redis":"^3.1.2","dotenv":"^16.0.2","helmet":"^6.0.0","express":"^4.18.1","ts-node":"^10.9.1","bcryptjs":"^2.4.3","mongoose":"^6.6.1","crypto-js":"^4.1.1","nodemailer":"^6.7.8","typescript":"^4.8.3","compression":"^1.7.4","http-errors":"^2.0.0","jsonwebtoken":"^8.5.1","express-form-data":"^2.0.18","express-validation":"^4.1.0"},"_hasShrinkwrap":false,"devDependencies":{"colors":"^1.4.0","morgan":"^1.10.0","nodemon":"^2.0.20","@types/morgan":"^1.9.3","@types/bcryptjs":"^2.4.2","@types/crypto-js":"^4.1.1","@types/nodemailer":"^6.4.6","@types/compression":"^1.7.2","@types/http-errors":"^1.8.2","@types/jsonwebtoken":"^8.5.9","@types/express-form-data":"^2.0.2"},"_npmOperationalInternal":{"tmp":"tmp/x-auth-service_1.0.0_1664203386229_0.8420106260127247","host":"s3://npm-registry-packages"},"deprecated":"Package no longer supported. Contact Support at https://www.npmjs.com/support for more info."},"1.0.1":{"name":"x-auth-service","version":"1.0.1","keywords":["nodejs","typescript","mongodb","express","redis","jwt"],"author":{"name":"Francois J. Aouad"},"license":"MIT","_id":"x-auth-service@1.0.1","maintainers":[{"name":"francoisaouad","email":"francois.j.aouad@gmail.com"}],"homepage":"https://github.com/FrancoisAouad/X-Auth#readme","bugs":{"url":"https://github.com/FrancoisAouad/X-Auth/issues"},"dist":{"shasum":"5e2f91721cf8433ed27180e0428d5b834d34c65b","tarball":"https://registry.npmjs.org/x-auth-service/-/x-auth-service-1.0.1.tgz","fileCount":26,"integrity":"sha512-d3l6RnRTxQlHmgEZ/BPeo7N5vAde2mRid+XioaagfgO4dEtXvLMqSWP1wKda4a1A42blIq5Uyz7nFASbnh1AIg==","signatures":[{"sig":"MEUCIQC4QRqZQPT/d5Ys8uy/mrGM1JnR1OgD/o/qJz0HDfRmXAIgUu/bmPLKTyAcgoyuHdd3excsBp9jIJ3ffvh3KWY1IHs=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":49394,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJjMqM8ACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2Vmrosg/8D1o9XH48K3c9mRXCtOe0bGShuugMEbROk8W9f/4ESDYjqadM\r\nOHOyBFbzxcE7Zucebk0UrjjkLNFsc9zTb4XgX6MmwXXwJrFBCFgg8AGpCa4Z\r\n7/LVgQkpL5utKV7misZfR1kaSZFM2Nksq9Z06hZWDK77LzGEJF2jXHtojbdL\r\nKB7pXK6hYTuuS5R0tkRGjeaNsPsCMq7+uUOafXgZs/OWo1iUJkKvKpYT8nA3\r\n8b5VQji/vjmSLwwI7yEoIP8SfqMWa7PBx/Duq/kzZeQmi7hCwE5be0wqeiC7\r\n9Wz4amfNFGtizPkvVo10OVo9eYNt/onzAiQA3La+9eUn29xkQFGgaprMxlQj\r\nJ4zN5jqeCC3mte8TEBeblV9QHukn51LEw3LvVz5Ckx48JOjed0HhM0UDTgYZ\r\nnp8iBUveS6tban9kPy+inS7ZBuiQPbVm9Tb/Cv4A1Q+Wyzc1enRnoU4WILt6\r\nzb/JW5iq1+4TZDN/LCpQ68HVaVpAqszK5bw5SbQO4lGRSPZ1XqxbTctKLB6G\r\n0/I33sCCZHzpH1GJjc0At+qhpeoQMVCyAXjURyVdkE88kPuq0JoRG5i49Oql\r\neTaXJpeoIi9nOxWrxC+BW+EjiLibOBh4v6wta7FC+821rPq3gAoXRdVWVSBw\r\nGdW6Qm14Pt4M1YN9ovIsEfPykOeN1/G5Pfo=\r\n=P5V/\r\n-----END PGP SIGNATURE-----\r\n"},"main":"dist/index.js","gitHead":"cbefe80a194508a1ce64c5508912df6faeabee63","scripts":{"build":"tsc -p tsconfig.json","clean":"rm -r node_modules && package-lock.json","mongo":"mongod","redis":"redis-server","start":"nodemon","install-dev":"npm i"},"_npmUser":{"name":"francoisaouad","email":"francois.j.aouad@gmail.com"},"repository":{"url":"git+https://github.com/FrancoisAouad/X-Auth.git","type":"git"},"_npmVersion":"8.18.0","description":"Simple Auth library for REST APIs using expressJS","directories":{},"_nodeVersion":"18.8.0","dependencies":{"joi":"^17.6.0","cors":"^2.8.5","redis":"^3.1.2","dotenv":"^16.0.2","helmet":"^6.0.0","express":"^4.18.1","ts-node":"^10.9.1","bcryptjs":"^2.4.3","mongoose":"^6.6.1","crypto-js":"^4.1.1","nodemailer":"^6.7.8","typescript":"^4.8.3","compression":"^1.7.4","http-errors":"^2.0.0","jsonwebtoken":"^8.5.1","express-form-data":"^2.0.18","express-validation":"^4.1.0"},"_hasShrinkwrap":false,"devDependencies":{"colors":"^1.4.0","morgan":"^1.10.0","nodemon":"^2.0.20","@types/node":"^18.7.23","@types/morgan":"^1.9.3","@types/bcryptjs":"^2.4.2","@types/crypto-js":"^4.1.1","@types/nodemailer":"^6.4.6","@types/compression":"^1.7.2","@types/http-errors":"^1.8.2","@types/jsonwebtoken":"^8.5.9","@types/express-form-data":"^2.0.2"},"_npmOperationalInternal":{"tmp":"tmp/x-auth-service_1.0.1_1664262972193_0.9695670996890884","host":"s3://npm-registry-packages"},"deprecated":"Package no longer supported. Contact Support at https://www.npmjs.com/support for more info."},"1.0.2":{"name":"x-auth-service","version":"1.0.2","keywords":["nodejs","typescript","mongodb","express","redis","jwt"],"author":{"name":"Francois J. Aouad"},"license":"MIT","_id":"x-auth-service@1.0.2","maintainers":[{"name":"francoisaouad","email":"francois.j.aouad@gmail.com"}],"homepage":"https://github.com/FrancoisAouad/X-Auth#readme","bugs":{"url":"https://github.com/FrancoisAouad/X-Auth/issues"},"dist":{"shasum":"20dcbc6b7d2e5a8b16489edf775ccfe8b5ff67c8","tarball":"https://registry.npmjs.org/x-auth-service/-/x-auth-service-1.0.2.tgz","fileCount":26,"integrity":"sha512-gkR7Htnbq9TfHqCe3ohBzcvIRarbr7hLQBTK5L2HcDSN8O58Ars3DU++gTXrTnxHdIZ3DVR3yHL1nvpiwdxd5Q==","signatures":[{"sig":"MEUCIQDz6+jZvO20e7ws7fW+5FtIV3n6h0H4LXGret0Oj5oIoQIgJZjaJ2vf5MC6tR1Xoxrg3wCEUW3CXxTt3VwZiBcxdDU=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":49394,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJjMqbXACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2Vmp6wA/+PiIMTE+38gq5uRMQ4Z2RBXxsznMITsmgx9UqlkzvCXfQgGEo\r\n9/LuzH8cZPmKdcySeTb+kFc07RUv7xGDXvrHR2A6urBKuDLkOjHDBgFayxn4\r\nFnwhq0J08P3KGauA+kZ1q4pzc1pgDewG/1GNw5glJ8k5kJ9/Q+KXaxbAL4VE\r\nyGhHPxoF4601U2UXhyv1OsLTnoo9hVGAM5T8hxIcaEKvpcmqoJ8uyieR7vhb\r\nsNqXdnR7s8lv5Cd6R86aiLQU0kTpcKMjSxt8ESuUOblSoS6c5frhhF5IHWA+\r\nq9TdJDCJZVTkTOPYAqgL9lNms+9GK4MOTzqFsByGhFd3haXwM3Zvwr2BXIgR\r\n2I9tJYKOs+zh095ae5kj93jM/7ehKeXHLOir9aoos4ygTZI9g/w2LrqYVGjE\r\ndgrbLqkeqYQfXZtWPS9PUMQxueFU6f6J7WTO8dxh+jQL8w9VuV90CPx0FlBH\r\ni+kIc1jwUxKzwbR2TzKg71McYb02IDPn/d93O4kkh9hhBNUU4ZVQ7Rjxw4Vc\r\nAxK1YQS7P6cHeioZsPols+qGN+r10Q0xJyyvc+HT96Amj8j+zZGPechWrzTG\r\nqtFS0HDn/K4a6iLGL1UCL6n9qFPQ2XTkJXo9t/54uyPFsXnqvc+xmT1RGbTR\r\n9mblgYj588evOK36V59nsEA/RtNfEJFFDwc=\r\n=dUhN\r\n-----END PGP SIGNATURE-----\r\n"},"main":"dist/index.js","gitHead":"c125fcc7032d793f902468950b85af82a9cc6947","scripts":{"build":"tsc -p tsconfig.json","clean":"rm -r node_modules && package-lock.json","mongo":"mongod","redis":"redis-server","start":"nodemon","install-dev":"npm i"},"_npmUser":{"name":"francoisaouad","email":"francois.j.aouad@gmail.com"},"repository":{"url":"git+https://github.com/FrancoisAouad/X-Auth.git","type":"git"},"_npmVersion":"8.18.0","description":"Simple Auth library for REST APIs using expressJS","directories":{},"_nodeVersion":"18.8.0","dependencies":{"joi":"^17.6.0","cors":"^2.8.5","redis":"^3.1.2","dotenv":"^16.0.2","helmet":"^6.0.0","express":"^4.18.1","ts-node":"^10.9.1","bcryptjs":"^2.4.3","mongoose":"^6.6.1","crypto-js":"^4.1.1","nodemailer":"^6.7.8","typescript":"^4.8.3","compression":"^1.7.4","http-errors":"^2.0.0","jsonwebtoken":"^8.5.1","express-form-data":"^2.0.18","express-validation":"^4.1.0"},"_hasShrinkwrap":false,"devDependencies":{"colors":"^1.4.0","morgan":"^1.10.0","nodemon":"^2.0.20","@types/node":"^18.7.23","@types/morgan":"^1.9.3","@types/bcryptjs":"^2.4.2","@types/crypto-js":"^4.1.1","@types/nodemailer":"^6.4.6","@types/compression":"^1.7.2","@types/http-errors":"^1.8.2","@types/jsonwebtoken":"^8.5.9","@types/express-form-data":"^2.0.2"},"_npmOperationalInternal":{"tmp":"tmp/x-auth-service_1.0.2_1664263895027_0.055013130462055804","host":"s3://npm-registry-packages"},"deprecated":"Package no longer supported. Contact Support at https://www.npmjs.com/support for more info."}},"time":{"created":"2022-09-26T14:43:06.228Z","modified":"2025-05-25T14:07:00.639Z","1.0.0":"2022-09-26T14:43:06.410Z","1.0.1":"2022-09-27T07:16:12.396Z","1.0.2":"2022-09-27T07:31:35.216Z"},"bugs":{"url":"https://github.com/FrancoisAouad/X-Auth/issues"},"author":{"name":"Francois J. Aouad"},"license":"MIT","homepage":"https://github.com/FrancoisAouad/X-Auth#readme","keywords":["nodejs","typescript","mongodb","express","redis","jwt"],"repository":{"url":"git+https://github.com/FrancoisAouad/X-Auth.git","type":"git"},"description":"Simple Auth library for REST APIs using expressJS","maintainers":[{"name":"francoisaouad","email":"francois.j.aouad@gmail.com"}],"readme":"# Introduction\r\n\r\nThis library was created in order to have a simple and reusable authentication service while building REST APIs.\r\n\r\n## Install & Setup\r\n\r\nThe project uses 17 different dependencies. It also uses the redis 3.1.2 ver which doesn't support async/await. The windows version can be downloaded from [here](https://github.com/microsoftarchive/redis/releases/tag/win-3.0.504).\r\n\r\nTo use the library add it to your project:\r\n\r\n```bash\r\nconst xauth = require('x-auth-service')\r\n\r\nimport xauth from 'x-auth-service'\r\n```\r\n\r\n## Auth Methods\r\n\r\n**login**\r\n\r\nThe login method is used to check if the user's credentials are found inside our database. If the user is found, then we create JWT access and refresh Tokens that are valid for this user as a response.\r\n\r\n```bash\r\n   const result = await xauth.authService.login(req.body);\r\n```\r\n\r\n**signup**\r\n\r\nThe signup method is used to add the credentials of a new user into our backend system. The function would then return the JWT tokens as a response, and an email in order for the user to verify their account.\r\n\r\n```bash\r\nconst result = await xauth.authService.signup(req.body,req.headers);\r\n```\r\n\r\n**logout**\r\n\r\nThe logout method makes sure to delete and blacklist the refresh from the server side which will in turn make sure that the user is logged out of the app. The tokens must also be deleted from the client side.\r\n\r\n```bash\r\nawait xauth.authService.logout(req.body);\r\n```\r\n\r\n**refreshToken**\r\n\r\nThis method renews access to the user to the system by checking the validity of the token and sending back two new pairs of JWT.\r\n\r\n```bash\r\nconst result = await xauth.authService.refreshToken(req.body.refreshToken);\r\n```\r\n\r\n**forgotPassword**\r\n\r\nThis function sends an email with a url that contains a JWT token that is valid only for 10min in order to reset their credentials.\r\n\r\n```bash\r\n const result: any = await xauth.authService.forgotPassword(req.headers);\r\n```\r\n\r\n**resetPassword**\r\n\r\nChecks the old password and updates the database with the new inserted one.\r\n\r\n```bash\r\nconst result = await xauth.authService.resetPassword(req.params, req.body, req.headers.authorization);\r\n```\r\n\r\n**verifyEmail**\r\n\r\nVerifies the that the token in the url matches with the userId.\r\n\r\n```bash\r\n await xauth.authService.verifyEmail(req.headers.authorization);\r\n```\r\n\r\n**hashPassword**\r\n\r\nHelper function that encrypts the user password using the bcryptjs library\r\n\r\n```bash\r\n const hashedPassword = await hashPassword(req.body.password);\r\n```\r\n\r\n**isValidPassword**\r\n\r\nA helper function that returns true if the decrypted hash and the plain text password match\r\n\r\n```bash\r\nconst isMatch = await isValidPassword(req.body.password, hashedPassword);\r\n```\r\n\r\n## JWT Methods\r\n\r\n**setAccessToken**\r\n\r\nGenerates a temporary access Token that will be used to give access to users\r\n\r\n```bash\r\nconst accessToken = xauth.setTokens.setAccessToken(userId);\r\n```\r\n\r\n**setRefreshToken**\r\n\r\nGenerates a refresh Token that will be used to send back 2 pairs of JWT tokens\r\n\r\n```bash\r\nconst refreshToken = await xauth.setTokens.setRefreshToken(userId);\r\n```\r\n\r\n**setResetPasswordToken**\r\n\r\nGenerates a token valid for 10min that will be used to verify that the url belongs to the user\r\n\r\n```bash\r\n const resetPasswordToken = await xauth.setTokens.setResetPasswordToken(userId);\r\n```\r\n\r\n**verifyAccessToken**\r\n\r\nVerifies that the token is valid. Usually used as middleware for router protection.\r\n\r\n```bash\r\n router.get('/', xauth.verifyTokens.verifyAccessToken , function)\r\n```\r\n\r\n**verifyRefreshToken**\r\n\r\nVerifies that the token is valid\r\n\r\n```bash\r\nconst isValid: any = await xauth.verifyTokens.verifyRefreshToken(token);\r\n```\r\n\r\n**verifyResetPasswordToken**\r\n\r\nUsed inside the resetPassword function ro return userId and make sure it is valid.\r\n\r\n```bash\r\nconst isValid: any = await xauth.verifyTokens.verifyResetPasswordToken(token);\r\n```\r\n","readmeFilename":"README.md"}