{"repo":"cerbos/express-jwt-cerbos","free":true,"listed":false,"github":"https://github.com/cerbos/express-jwt-cerbos","clone":"git clone https://github.com/cerbos/express-jwt-cerbos.git","description":"An example application of integrating Cerbos with an Express server using JSON Web Tokens - via express-jwt - for authentication.","language":"JavaScript","stars":11,"topics":["express","node","jwt","cerbos","authorization","security"],"license":"Apache-2.0","category":"auth-billing-email","readme_excerpt":"express-jwt-cerbos An example application of integrating Cerbos with an Express server using JSON Web Tokens - via express-jwt - for authentication. Dependencies - Node.js - Docker for running the Cerbos Policy Decision Point (PDP) Getting Started 1. Start up the Cerbos PDP instance docker container. This will be called by the express app to check authorization. 2. Install node dependencies 3. Start the express server Policies This example has a simple CRUD policy in place for a resource kind of contact - like a CRM system would have. The policy file can be found in the cerbos/policies folder here. Should you wish to experiment with this policy, you can try it in the Cerbos Playground . The policy expects one of two roles to be set on the principal - admin and user . These roles are authorized as follows: Action User Admin ------ ---- ----- list Y Y read Y Y create N Y update N Y delete N Y JWT Structure For this example a JWT needs to be generated to be passed in the authorization header. The payload of the token contains an array of roles which are passed into Cerbos to use for authorization - the structure is as follows: JWT.io can be used generate a token for testing purposes - an example is here. Note: The secret is hardcoded in this example to yoursecret and the algorithm is HS256 - you will need to set these for the signature to be valid. Request Flow 1. HTTP request comes in and the express-jwt library validates the token and adds the payload to req.user . 2. The cont","default_branch":null,"files":null,"tree":[],"storefront":"/r/cerbos","claimed":false,"request_supported":{"post":"https://gitbuyer.com/r/cerbos/express-jwt-cerbos/request-supported","requests":0},"note":"indexed from public GitHub; nothing is for sale on this page. Clone it from GitHub. Paid listings live at /search."}