{"_id":"@aeroline_1025/otzi","_rev":"2-8f885549450ef5d35c214d5ee83a0aeb","name":"@aeroline_1025/otzi","dist-tags":{"latest":"1.1.0"},"versions":{"1.0.0":{"name":"@aeroline_1025/otzi","version":"1.0.0","description":"Authorization plugin for Seneca. Based on CASBIN library","main":"lib/otzi.js","scripts":{"test":"lab"},"author":{"name":"Grégory DELPU","url":"gdelpu@gmail.com"},"license":"ISC","dependencies":{"@hapi/hoek":"^8.5.0","@hapi/joi":"^16.1.7","casbin":"^3.0.5"},"devDependencies":{"@hapi/code":"^7.0.0","@hapi/lab":"^21.0.0","bluebird":"^3.7.1","eslint-config-hapi":"^12.0.0","eslint-plugin-hapi":"^4.1.0","rewire":"^4.0.1","seneca":"^3.17.0","sinon":"^7.5.0"},"gitHead":"34d8c1683637f0870f1426048bbc29ba859dcf06","_id":"@aeroline_1025/otzi@1.0.0","_nodeVersion":"12.13.0","_npmVersion":"6.12.0","dist":{"integrity":"sha512-afZQFByVlRJ1zauiStY/0Vr2lYzEie8bgCVt5+gxU/vN0AD4A2A2T8jQnXl4oha0xpo1ut4SGtC5m9QtriwiSw==","shasum":"2642d162621e804c517a6197d0ad547ad232b029","tarball":"https://registry.npmjs.org/@aeroline_1025/otzi/-/otzi-1.0.0.tgz","fileCount":7,"unpackedSize":23406,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJd1R90CRA9TVsSAnZWagAAntcQAI0ZcztxcJJuehyc48Ki\n5J7HdZQOPjHpUSv2R43Uc9q75s0eMluuOlnsmchg+ufcDp9uS6grG+Jx86aa\nCRg3ZFXY9RLgc/862lU8HNjkbN+46D7lqnxJNQuU/dmtE6v55aHcaVsIWrc5\n7jVSHW6oxQ42nlqRHqqL+APwghGB4Lwy64LDudLSHuChTKw3fReMCX0PY0Ik\nAi5F+/TCXH9SEs9q5k6nl+RH8hI3zIePCIZ4rcWKweghn7KK38n6a+iS5iGe\nxHsWat8lx7RpewUxmz10A/nfJ17B/1XfQEvTXGjeADsg12dT3SfQm1aIFndq\naSpxv3OXBnm26WEhLbCQQKLJtV9j6ijeBSEoFImFZeeRCPOYVZfLAFh4+agy\n1N2AnBnL8VgrjAbo5+9SxkFO33/ZR+ECMDGu1eyt5JVTWVjF1WaHqGNNUkep\nyCje6In8SgcWMeSYnEB4ZHDeX/l9U3Apw9vvke0cTzj6vrePl0vFCJiW0GlI\nmisbmZypaxVKT4nJsyW5ztRlun9r8nUUScvvNq/IiW0Krl2x3VegVwelQ++4\nv8PeC8/1OV9sX0ng+/1LywEHPg13bjfOJJ62CZFwu0+HMzRpTDDv9Y8vFnzT\nhlwTg766KIhlZr7q/L6Njnr1YCGo18MQPbE+xkakp4W0GGzdLQxX64OCYwt1\nEncT\r\n=vsXe\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIACw9itqG5yOwWFGXrjvE8agu4RYe0yPiRnDUErZAYGrAiEAz/65UMLhZzxl3sF0CXdLVKncEXYw8fyM5O0lVT2gN70="}]},"maintainers":[{"name":"nmeurot","email":"nicolas.meurot@soprasteria.com"},{"name":"gregory.delpu","email":"gdelpu@gmail.com"}],"_npmUser":{"name":"gregory.delpu","email":"gdelpu@gmail.com"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/otzi_1.0.0_1574248307610_0.7367119055890279"},"_hasShrinkwrap":false},"1.1.0":{"name":"@aeroline_1025/otzi","version":"1.1.0","description":"Authorization plugin for Seneca. Based on CASBIN library","main":"lib/otzi.js","scripts":{"test":"lab"},"author":{"name":"Grégory DELPU","url":"gdelpu@gmail.com"},"license":"ISC","dependencies":{"@hapi/hoek":"^8.5.0","@hapi/joi":"^16.1.7","casbin":"^3.0.5"},"devDependencies":{"@hapi/code":"^7.0.0","@hapi/lab":"^21.0.0","bluebird":"^3.7.1","eslint-config-hapi":"^12.0.0","eslint-plugin-hapi":"^4.1.0","rewire":"^4.0.1","seneca":"^3.17.0","sinon":"^7.5.0"},"gitHead":"0d7d58eabb46faa59cce2995b3c939084b9ffdaa","_id":"@aeroline_1025/otzi@1.1.0","_nodeVersion":"12.13.0","_npmVersion":"6.12.0","dist":{"integrity":"sha512-Yi/72I7TlZ8UtrYalM+bQloHFvB8/RrJ8TcwGEU+JUZCNIEU45cMTiZAaqSiFiHQ3A2PShH3jVv1OPh7uR7o1A==","shasum":"acd42443c162e6a6968ef0497768a62cd72296a5","tarball":"https://registry.npmjs.org/@aeroline_1025/otzi/-/otzi-1.1.0.tgz","fileCount":8,"unpackedSize":24645,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJd1UubCRA9TVsSAnZWagAAdE0P/jxaHdMIxCGb/wl94xTK\neFgpvx5ZXOzr5nQ71k4/poRULn8TPRyPLWQhLo/cbHpC4S3FBKDSrMQiUgsF\n6g1s/4m82sRJDwK/5oHJoOTBeJikeEyJRuIYJ483XV8dfmreAcPzRnqYG17x\ntAp1EP6ovqFKn9hdTdPLgdLjmVZxKU6pVEVplr8yrMddtOQ3dIFjR8o5ULSv\nFIVYE17TbYSk6ur4zBFhG+MTjpog0lFRZiCQ0yrMyiupLIvDbx9pdN4Ajr5F\nOyeo3xahKAff2Du+LI4+5ZZVf1rde6QgxkX0yMh+xk4i9iL7XbL2MDnD2L5S\nLDP0NGYNU6Dlz60/bojGC6syEwB+2oduGj7AQKvGhHVvbtnvaM8ohf0wcQry\nIxYVDLLdhD2hrWbjAhsoargKUT1qobEzvIZ4iKGKesPEzHtqbzJSi0Hf3gm8\nim6VA/2lWCubCoxjyYxckv7Sc0z/zUU9WrikCbYTDF4dvbXyc7gDdxyovdHi\nN+tIrRbzkwNbwjDqpkOMx8mTHifr+wfKkKsyFRDHzX7+dnviF2OlnZDLVIkY\nAXrRrxLWSvoo8oRpvYwLpJgZpTA+m3vmcOcF6T6XPKClogvSJivGkpSZaL5Q\n17C/HEJAxFt0/3QasOge0ZpbGZDDpt3VkZc3OduqFIZRHTRMChQY9/rQPVjX\nuKdb\r\n=rkfV\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQCENH6tRFW0prGo0skSHPGLnM+yuokrNjNLF2t5y4SeggIgEwiAQV9apih8C0I0NcS7DjWnClV3B7WSO7ChnsSZXKY="}]},"maintainers":[{"name":"gregory.delpu","email":"gdelpu@gmail.com"},{"name":"nmeurot","email":"nicolas.meurot@soprasteria.com"}],"_npmUser":{"name":"gregory.delpu","email":"gdelpu@gmail.com"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/otzi_1.1.0_1574259611163_0.1911196323556097"},"_hasShrinkwrap":false}},"time":{"created":"2019-11-20T11:11:47.358Z","1.0.0":"2019-11-20T11:11:47.745Z","modified":"2022-04-04T11:49:25.817Z","1.1.0":"2019-11-20T14:20:11.348Z"},"maintainers":[{"name":"gregory.delpu","email":"gdelpu@gmail.com"},{"name":"nmeurot","email":"nicolas.meurot@soprasteria.com"}],"description":"Authorization plugin for Seneca. Based on CASBIN library","author":{"name":"Grégory DELPU","url":"gdelpu@gmail.com"},"license":"ISC","readme":"# Otzi (Authorization module for SenecaJS)\r\n\r\nOtzi is based on the Casbin library to provide a flexible way to handle authorizations in SenecaJS actions\r\n\r\n## In a Nutshell\r\nBy registering the plugin in a Seneca instance, each pattern **_already_** added to the Seneca instance is override by a new \"authorization\" action.\r\n\r\nThis action evaluates the user's authorizations and call the prior (aka parent) action if access is granted.\r\n\r\nAs Seneca plugins are registered in a deterministic order, it is important to register Otzi after all the patterns to protect have been declared in the Seneca instance.\r\n\r\n## Installation \r\n    > npm i @aeroline_1025/otzi\r\n    \r\n## Quick start\r\nIn order to configure Otzi you should prepare a Casbin model and policies, they will be needed to initialize the plugin\r\n\r\n```javascript\r\nconst Seneca = require('seneca')();\r\nconst Otzi = require('@aeroline_1025/Otzi');\r\n\r\nconst options = {\r\n    adapter: './tests/fixtures/casbin_policy.txt',\r\n    model: './tests/fixtures/casbin_model.txt',\r\n    pins: [{ role: 'test' }]\r\n};\r\n\r\n\r\nSeneca\r\n    .add({ role: 'test', cmd: 'doSomething' }, (msg, done) => {\r\n\r\n        console.log(`handler ${msg.value}`);\r\n        done(null, { status: true });\r\n    })\r\n    .use(Otzi, options)\r\n    .ready(function() {\r\n        // Call seneca command\r\n        Seneca\r\n            .listen()\r\n            .act({ role: 'test', cmd: 'list' }, { value: 456 });\r\n    });\r\n``` \r\n## How it works\r\nUpon initialization, **Otzi** plugin override every patterns registered earlier that matched one of the \"pins\" options.\r\n\r\nWhen an overrode action is executed, **Otzi** action is run first, it passes the return of the injector function to casbin enforcer parameters.\r\n Casbin enforcer evaluates user's authorizations and grant (or not) execution of the action. if access is granted, prior action is called.\r\n \r\n### Policy evaluation\r\nWhen evaluating the authorization, Otzi injects message's attributes in Casbin enforcer's request. You can change the default injector function in Otzi's options.\r\n\r\n## Options\r\n### model\r\n**String**: Passed directly to the casbin enforcer. Check [casbin documentation](https://github.com/casbin/node-casbin) for more information\r\n### adapter\r\n**String | Object**: if **string**, it is the path to the file containing the policies, will be used by the default _FileAdapter_. If **object**, it is an adapter that will be directly passed to casbin enforcer.\r\n### pins\r\n**Array**: An array of patterns to protect with a casbin policy, items could be:\r\n- A Jsonic string of a Seneca pattern [(more information)](https://github.com/rjrodger/jsonic)\r\n- The pattern as a JSON object.\r\n- A JSON object with following keys:\r\n    - pattern (Jsonic | Object): This key is required.\r\n    - inject (function): An injector function with signature (message), this key is optional.\r\n### inject\r\n**function**: function using the signature **async function(msg)** where:\r\n- **msg** is the message passed to the seneca action.\r\n\r\nThis function overrides the default injector for Casbin enforcer. It shall return the parameters for Casbin enforcer as an **array**.\r\n\r\nThe default inject function is:\r\n ```js\r\nconst inject = function(userId, msg){\r\n\r\n    return [userId, msg.role, msg.cmd]\r\n}\r\n```\r\n\r\n","readmeFilename":"README.md"}