{"_id":"@diegoti/simple-jwt-authentication-util","_rev":"1-571de0ce88783717084013442c34a810","name":"@diegoti/simple-jwt-authentication-util","dist-tags":{"latest":"1.0.1"},"versions":{"1.0.0":{"name":"@diegoti/simple-jwt-authentication-util","version":"1.0.0","description":"Validates the token and adds authenticated user information to the express request object","main":"index.js","scripts":{"test":"echo \"Error: no test specified\" && exit 1"},"repository":{"type":"git","url":"git+https://github.com/DiegoTorres/simple-jwt-authentication-util.git"},"keywords":["authenticated","use","express"],"author":{"email":"diegotorres.rj@gmail.com"},"license":"ISC","bugs":{"url":"https://github.com/DiegoTorres/simple-jwt-authentication-util/issues"},"homepage":"https://github.com/DiegoTorres/simple-jwt-authentication-util#readme","dependencies":{"@diegoti/simple-error-handler-for-express":"^1.0.1","jsonwebtoken":"8.5.1"},"gitHead":"9629c0b858ced202c2d10ebb38a176e3bf97d731","_id":"@diegoti/simple-jwt-authentication-util@1.0.0","_nodeVersion":"16.15.1","_npmVersion":"9.6.2","dist":{"integrity":"sha512-pGMr/v9mBUZzlf6GH98Nu7WCtcntvJnd20tX5GGTnhZmbE6IAh4D84lzQHbZwdvbNqFHe/MI8Bq59TDn/IgUUQ==","shasum":"120b8f43ed6d835a3c60c9ddfb67019dc0a35224","tarball":"https://registry.npmjs.org/@diegoti/simple-jwt-authentication-util/-/simple-jwt-authentication-util-1.0.0.tgz","fileCount":4,"unpackedSize":39577,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQC9dwe13Wl2BfxrmegQKihnqfEBGZfIqeT1Z1uXusSFBwIgRwJPOfpyQRiWMXrjmtNu5Q7FqrGPn+l4EAz1nP5rgfs="}]},"_npmUser":{"name":"diego_torres_iglesias","email":"diegotorres.rj@gmail.com"},"directories":{},"maintainers":[{"name":"diego_torres_iglesias","email":"diegotorres.rj@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/simple-jwt-authentication-util_1.0.0_1694537008444_0.7644936324094962"},"_hasShrinkwrap":false},"1.0.1":{"name":"@diegoti/simple-jwt-authentication-util","version":"1.0.1","description":"Validates the token and adds authenticated user information to the express request object","main":"index.js","scripts":{"test":"echo \"Error: no test specified\" && exit 1"},"repository":{"type":"git","url":"git+https://github.com/DiegoTorres/simple-jwt-authentication-util.git"},"keywords":["authenticated","use","express"],"author":{"email":"diegotorres.rj@gmail.com"},"license":"ISC","bugs":{"url":"https://github.com/DiegoTorres/simple-jwt-authentication-util/issues"},"homepage":"https://github.com/DiegoTorres/simple-jwt-authentication-util#readme","dependencies":{"@diegoti/simple-error-handler-for-express":"^1.0.1","jsonwebtoken":"9.0.2"},"gitHead":"a993fc98a9b51265ab76f371151fab097a2fbb85","_id":"@diegoti/simple-jwt-authentication-util@1.0.1","_nodeVersion":"16.15.1","_npmVersion":"9.6.2","dist":{"integrity":"sha512-9AH95Vk62UNDQK2kfVljDpRKSNvG+HWOiAVGcBEr5ZdEeJhkgOe4BTH0UOGgTBSykHI0kRYahldqMA/tKMQOlw==","shasum":"48ae32f7a3459ef1c5808ef116199ef1c481f3f2","tarball":"https://registry.npmjs.org/@diegoti/simple-jwt-authentication-util/-/simple-jwt-authentication-util-1.0.1.tgz","fileCount":4,"unpackedSize":39577,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQCwGcKvWc0kf9TfnknDtz4r39SmT4ioYDudzIuSr5zLrAIgCNgtZK3Q3YVWE9n5PYkkuIjwdQ6ulqMLntDJfDTu7WI="}]},"_npmUser":{"name":"diego_torres_iglesias","email":"diegotorres.rj@gmail.com"},"directories":{},"maintainers":[{"name":"diego_torres_iglesias","email":"diegotorres.rj@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/simple-jwt-authentication-util_1.0.1_1694540411538_0.4259505059170767"},"_hasShrinkwrap":false}},"time":{"created":"2023-09-12T16:43:28.345Z","1.0.0":"2023-09-12T16:43:28.687Z","modified":"2023-09-12T17:40:12.018Z","1.0.1":"2023-09-12T17:40:11.802Z"},"maintainers":[{"name":"diego_torres_iglesias","email":"diegotorres.rj@gmail.com"}],"description":"Validates the token and adds authenticated user information to the express request object","homepage":"https://github.com/DiegoTorres/simple-jwt-authentication-util#readme","keywords":["authenticated","use","express"],"repository":{"type":"git","url":"git+https://github.com/DiegoTorres/simple-jwt-authentication-util.git"},"author":{"email":"diegotorres.rj@gmail.com"},"bugs":{"url":"https://github.com/DiegoTorres/simple-jwt-authentication-util/issues"},"license":"ISC","readme":"# simple-jwt-authentication-util\n\n## Getting Started\n\nInstall it using [`npm`](https://www.npmjs.com/package/@diegoti/simple-jwt-authentication-util):\n\n```bash\nnpm i @diegoti/simple-jwt-authentication-util\n```\n## USAGE\n\nBefore use, set these two environment variables.\\\nThis package uses [`jsonwebtoken`](https://www.npmjs.com/package/jsonwebtoken), see the [`docs`](https://github.com/auth0/node-jsonwebtoken#readme) here.\n\n```javascript\nprocess.env.TOKEN_SECRET_KEY = \"SOME SECRETE KEY\";\nprocess.env.TOKEN_EXPIRES_IN = \"10m\"; // default is 5m\n```\n\nThere are four functions, import as it follows .\n\n```javascript\nconst {\n  getBasicCredentialsFromAuthorizationHeader,\n  getBearerTokenFromAuthorizationHeader,\n  createToken,\n  checkTokenAndSetDataToRequest\n} = require('@diegoti/simple-jwt-authentication-util');\n```\n\nYou can use getBasicCredentialsFromAuthorizationHeader to get credentials that are inside authorization header [Basic YWRtaW758QGFkbWluQB==], check the credentials, if credentials are valid, you can call createToken. See example bellow\n\n```javascript\nrouter.post('/login', function (req, res, next) {\n  \n  let token;\n  const { username, password } = getBasicCredentialsFromAuthorizationHeader(req.headers);\n\n  if (validateCredentials(username, password)) {\n    token = createToken({ username });\n  }\n\n  res.status(200).json({ token });\n});\n```\n\nAdd checkTokenAndSetDataToRequest to your route, this function will validates bearer token and if it is valid, the decoded data will be add to express req object as 'authenticatedUser' .\nExample of route\n\n```javascript\nrouter.post('/users', checkTokenAndSetDataToRequest, function (req, res, next) {\n  console.log('User data from token ', req.authenticatedUser);\n\n  res.status(200).json({ message: 'ok' });\n});\n```","readmeFilename":"README.md"}