{"_id":"@autotelic/fastify-oso","_rev":"3-f543e2828d60b3f706363444d2241863","name":"@autotelic/fastify-oso","dist-tags":{"latest":"0.3.0"},"versions":{"0.1.0":{"name":"@autotelic/fastify-oso","version":"0.1.0","description":"Plugin for fastify","main":"index.js","directories":{"test":"test"},"scripts":{"test":"tap --100 -j1 -R classic","example":"echo no example provided","lint":"standard","fix":"npm run lint -- --fix","validate":"npm run lint && npm run test"},"repository":{"type":"git","url":"git+https://github.com/autotelic/fastify-plugin-template.git"},"keywords":[],"author":{"name":"Autotelic Development Ltd","email":"info@autotelic.com"},"license":"MIT","bugs":{"url":"https://github.com/autotelic/fastify-plugin-template/issues"},"homepage":"https://github.com/autotelic/fastify-plugin-template#readme","dependencies":{"fastify-plugin":"^3.0.0","oso":"^0.24.0"},"devDependencies":{"tap":"^15.0.6","fastify":"^3.0.0","fastify-cli":"^2.5.1","standard":"^16.0.3","lint-staged":"^12.1.2"},"lint-staged":{"*.{js,jsx}":["npm run fix"]},"gitHead":"b68a27470c2caf9d411a3e6772abd4d5099f4275","_id":"@autotelic/fastify-oso@0.1.0","_nodeVersion":"14.18.1","_npmVersion":"6.14.15","dist":{"integrity":"sha512-xpgk9YSvMSDW12mRz9HWYpLPUhgfdpjFaMlDYIOkjhXuH8H9OSX+yzOhPOH0FLEzeauzLdfjG8Kl/MDCoXdsMQ==","shasum":"c581959d8c5b6acbab86255859b5564ded681c64","tarball":"https://registry.npmjs.org/@autotelic/fastify-oso/-/fastify-oso-0.1.0.tgz","fileCount":8,"unpackedSize":4472,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJhqEkdCRA9TVsSAnZWagAAQYUP/0laZVwFdTRmxm7ezuMH\n5+NiwuetEQHMGR4x4snt41XEWU3y3Fw0J+rbOI9HXq3dm5qrq8yvODuqquHU\ndX82/7Oq2Zj+6uIOx3x4UoNB1Ky2ixKTp4o40GBE9qiVWq+zWY7pK6YZV44g\nlTkoHedn1IMDNRgt6VcG0K/QuTpKaRUQxxuc9xt4zSyQzO3U0D156BcY6ND2\nlezeChwWldoo/ZTVFKL6LMd5MT6MGUIIjdxv/kTnlauPfx6nzXpO++bmXwAz\nyKQg9gWEPYSYus0gkLsDATK7qWQfRnz9FIIH5WS+dgONaPnvilfkzy1qbCbn\nbnjPEIA+iSzaR3NmFF3UrpngFupvGNVPXTa/N9P2LnZycS7XtmzCMuT2Oa1Q\n4cuA9mivHtW7fDeEa9DNYR9qPpuEBgCkSwJWT5Fn6ZhO27RObvH9XA8fKCkj\nGBt7sDpMpUXLZ+cgO1kYwbzUcKWouA/0h4hQZ32aMFzg2obpl8SU0Z9mTd4i\nPGM+hQc0HHsEWMWpt5MxofaussUEzrGZhEFn3DIczX39q+EfJ8xGgwsGoz38\nMPZGKSpJ95jd9kLl4jyUn8iYhOMWd5mWpMeSWGxTpobr5MLYwRTu7AEz1+6x\nRTgUWqUETidIJ5s2jnqTZzreg9VHl/MR8ITQbt5zrbrX1FyPkpJShtD81qTr\nbdX4\r\n=iFVW\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIB5z9fHQXPvyokFUcI7LEFsdKuaVnD96ZAcBkHhbJtMmAiEA09xbfqrxvhLoxEcm5/3bujNrV+uL09/EsTwyqV+PssU="}]},"_npmUser":{"name":"autotelic","email":"info+npm@autotelic.com"},"maintainers":[{"name":"autotelic","email":"info+npm@autotelic.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/fastify-oso_0.1.0_1638418717293_0.5399520036749592"},"_hasShrinkwrap":false},"0.2.2":{"name":"@autotelic/fastify-oso","version":"0.2.2","description":"Plugin for fastify","main":"index.js","directories":{"test":"test"},"scripts":{"test":"c8 --100 ava","lint":"standard","fix":"standard --fix","validate":"npm run lint && npm run test"},"repository":{"type":"git","url":"git+https://github.com/autotelic/fastify-oso.git"},"keywords":[],"author":{"name":"Autotelic Development Ltd","email":"info@autotelic.com"},"license":"MIT","bugs":{"url":"https://github.com/autotelic/fastify-oso/issues"},"homepage":"https://github.com/autotelic/fastify-oso#readme","dependencies":{"fastify-plugin":"^3.0.0","oso":"^0.26.0"},"devDependencies":{"ava":"^4.0.1","c8":"^7.10.0","fastify":"^3.0.0","fastify-cli":"^2.5.1","husky":"^7.0.4","lint-staged":"^12.1.2","standard":"^16.0.3"},"lint-staged":{"*.{js,jsx}":["npm run fix"]},"gitHead":"40083c20c72dc6ef7c5bf18d621b80bf7c1e5fa6","_id":"@autotelic/fastify-oso@0.2.2","_nodeVersion":"16.14.2","_npmVersion":"8.5.0","dist":{"integrity":"sha512-L4fo07M+kI2SjYYEvTgig/Wa/D/AbJIA1tLHjLovitq/b5Pa03QPfRJdaO5J75xUERyU89AkY8zaQx3PEpPQVA==","shasum":"fd33211fa0e3644b1c4be0ac5ffcb37cfc90a291","tarball":"https://registry.npmjs.org/@autotelic/fastify-oso/-/fastify-oso-0.2.2.tgz","fileCount":15,"unpackedSize":13548,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQCGQFLw17y51d2rSTBgv0jzH2HIBY0zmVnS4mRU+h8/0AIgDHwXjcx7mRWkyMkPmxgczXLOxOk8ag5zPzoycULAEyQ="}],"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJiXiO2ACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2VmoiFA/9G+7ZLMZXQ7eOnbtiMxzDohIcKJTTiQxwrhsoSkzl7HX7rgw3\r\nUD5K8YBwdjrP+B7ptvE8Vmd0Ix/oT4Pm/QRwt4nUc5onhzqurQy8pgGhqBWi\r\nCygfXpmyfPadrRqJQoRangu8raSg5CtM1HHxMj0S8VqSs6dEb0FPUXP6nRCO\r\nXfUNyZrMv6vwVOTcITGmdglBoHmoFnOQqoIWri0rbMKzjhaDK6KlhU5a/UNY\r\nPgBQfzAFlNmOnwpfzXLijuVcDpC82hI9nzIeXOOIqXzx8jTm1fUVsUqYPYiw\r\n+fqb/D/yRPymrhze5O4rMokW/LYKKML6qcKUpoY+NWzO2YjArTXgzP7cKmPP\r\nSrZYkax6ql1QcR+LnGGGJ++tqogpy2j0JknCYO4gQgC2VtzkA2ZeVE3OYftm\r\nRwQ1DXNybketRuR/WNVFVl6gvSkckZZMHK91kELNnldDXEMIYNB5EXAT5z9r\r\npyZvrFQT0ww0szqD5PHzTqDSx2rcf9zMmfrdXm61nLltWzMG5wXUho6wZfIo\r\nq74IHun/+jXwJoFffqIrRizwlLw3+yjhOsTwxQiDyDVODEnW7TcVfe51MoSF\r\nEb30VFYn8rSh/dDkwNzGI9m6PIUzr0GgM10b+rEAcF8lfh6OX1lbynLhxl1E\r\ny9sumU3eN3gUJlMl/eSFYKB82QoW0kpQSuU=\r\n=8I5P\r\n-----END PGP SIGNATURE-----\r\n"},"_npmUser":{"name":"autotelic","email":"info+npm@autotelic.com"},"maintainers":[{"name":"autotelic","email":"info+npm@autotelic.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/fastify-oso_0.2.2_1650336694026_0.9593763345672177"},"_hasShrinkwrap":false},"0.3.0":{"name":"@autotelic/fastify-oso","version":"0.3.0","description":"Plugin for fastify","main":"index.js","types":"types/index.d.ts","type":"module","engines":{"node":">=18"},"scripts":{"lint":"eslint .","test":"tap","test:types":"tsd","validate":"npm run lint && npm test && npm run test:types"},"repository":{"type":"git","url":"git+https://github.com/autotelic/fastify-oso.git"},"keywords":[],"author":{"name":"Autotelic Development Ltd","email":"info@autotelic.com"},"license":"MIT","bugs":{"url":"https://github.com/autotelic/fastify-oso/issues"},"homepage":"https://github.com/autotelic/fastify-oso#readme","dependencies":{"fastify-plugin":"^4.5.1","oso":"^0.27.3"},"devDependencies":{"@autotelic/eslint-config-js":"^0.2.1","@typescript-eslint/eslint-plugin":"^6.19.1","@typescript-eslint/parser":"^6.19.1","eslint":"^8.56.0","eslint-import-resolver-typescript":"^3.6.1","fastify":"^4.25.2","fastify-cli":"^6.0.1","tap":"^18.6.1","tsd":"^0.30.4","typescript":"^5.3.3"},"tsd":{"directory":"types"},"_id":"@autotelic/fastify-oso@0.3.0","gitHead":"145229a2920804c25c684ea3fc8aa0130a2070dc","_nodeVersion":"18.19.0","_npmVersion":"10.2.3","dist":{"integrity":"sha512-P9uVj96Q2eVYs+I6HOZ/6wRL3JI6QcGby/POsLNDj2yuXfDHT2vuU1qWARvxsei7kRREYWhep57c3+rjp3LgBg==","shasum":"00a7a12414ca32678ec0b9a192e7e328ac5b1227","tarball":"https://registry.npmjs.org/@autotelic/fastify-oso/-/fastify-oso-0.3.0.tgz","fileCount":5,"unpackedSize":6543,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQC0pM7B9Owmw6IKq4SyPwRaFQfvnOHvGuG+Rvlba2BdEwIhANZWc9+sIDW0BZl0wNRVrMxwif6D+6YQrc13dvpSLjgd"}]},"_npmUser":{"name":"autotelic","email":"info+npm@autotelic.com"},"directories":{},"maintainers":[{"name":"autotelic","email":"info+npm@autotelic.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/fastify-oso_0.3.0_1706124306655_0.8965049366949336"},"_hasShrinkwrap":false}},"time":{"created":"2021-12-02T04:18:37.242Z","0.1.0":"2021-12-02T04:18:37.421Z","modified":"2024-01-24T19:25:06.967Z","0.2.2":"2022-04-19T02:51:34.164Z","0.3.0":"2024-01-24T19:25:06.795Z"},"maintainers":[{"name":"autotelic","email":"info+npm@autotelic.com"}],"description":"Plugin for fastify","homepage":"https://github.com/autotelic/fastify-oso#readme","keywords":[],"repository":{"type":"git","url":"git+https://github.com/autotelic/fastify-oso.git"},"author":{"name":"Autotelic Development Ltd","email":"info@autotelic.com"},"bugs":{"url":"https://github.com/autotelic/fastify-oso/issues"},"license":"MIT","readme":"# fastify-oso\n\nA plugin for implementing [Oso](https://github.com/osohq/oso) authorization in fastify applications.\n\n## Install\n\n```sh\nnpm i @autotelic/fastify-oso\n```\n\n## Usage\n\n```js\nimport { fastifyOso } from '@autotelic/fastify-oso'\nimport fastify from 'fastify'\n\nconst app = fastify()\n\nconst PORT = process.env.PORT || 3000\n\nasync function setupOso (oso) {\n  const osoPolicy = `\n    # Anyone may access the '/public' endpoint\n    allow_request(_, request) if\n      request.url.startsWith(\"/public\");\n\n    # Admin users can access everything\n    allow(user, _, _) if\n      user.role = \"admin\";\n  `\n  // Setup the oso instance here.\n  // All side effects must occur before returning the oso instance.\n  await oso.loadStr(osoPolicy)\n  return oso\n}\n\n// Register the plugin\napp.register(fastifyOso, { setupOso })\n\n// Authorize access to your routes as an onRequest hook\nconst osoAuthorizeRequest = async (request, reply) => {\n  try {\n    await app.oso.authorizeRequest({}, request)\n  } catch (error) {\n    reply.status(403).send('Access Denied')\n  }\n}\n\n// Anyone is able to access this route.\napp.get('/public', { onRequest: [osoAuthorizeRequest] }, (request, response) => {\n  return 'public information'\n})\n\n\n// Only \"admin\" users may access this route.\napp.get('/private', async (request, reply) => {\n  const user = {\n    // Role and other identifying information could come from\n    // JWTs or other data sources.\n    role: request.headers.role || 'anonymous'\n  }\n  try {\n    await app.oso.authorize(user)\n  } catch (error) {\n    reply.status(403).send('Access Denied')\n  }\n  return 'super secret'\n})\n\napp.listen(PORT, (_, address) => {console.log(`Listening at: ${address}`)})\n\n```\n\n## Examples\n\nWe provide the following usage examples and recipes:\n\n- [basic](./examples/basic/README.md)\n- [onRequest hook](./examples/onRequestHook/README.md)\n\n## API\n\n### Plugin\n\n#### Options\n\nThe configuration object accepts the following fields\":\n\n##### - `setupOso: async (Oso) => Oso`\n\n  A function that receives the oso instance, applies some configuration to that\n  instance and then returns the configured oso class.\n\n#### Decorators\n\nThe oso instance is exposed as a decorator inside the `oso` namespace. For a list of the exposed oso methods refer to the [Oso API documentation](https://docs.osohq.com/node/reference/api/classes/oso.oso-1.html)\n\n#### requestDecorators\n\n##### - `authorizeRequest: (Actor, Request) => Promise`\n\nExposes the oso [authorizeRequest](https://docs.osohq.com/node/reference/api/classes/oso.oso-1.html#authorizerequest) method on the Request object.\n\nThis is useful for handling authorization within request lifecycle hooks.\n\n## Triggering a Release\n\n_Prerequisite: Update the repository access for the shared [NPM_PUBLISH_TOKEN](https://github.com/organizations/autotelic/settings/secrets/actions/NPM_PUBLISH_TOKEN) secret._\n\nTrigger the release workflow via a tag\n\n  ```sh\n  git checkout main && git pull\n  npm version { minor | major | path }\n  git push --follow-tags\n  ```\n\n## License\n\nThis project is covered under the [MIT](./LICENSE) license.\n","readmeFilename":"README.md"}