{"id":21106444,"url":"https://github.com/nimitzdev/express-jwt-guard","last_synced_at":"2025-03-14T09:13:57.788Z","repository":{"id":79381515,"uuid":"128638175","full_name":"NimitzDEV/express-jwt-guard","owner":"NimitzDEV","description":"JWT guard middleware for Connect/Express","archived":false,"fork":false,"pushed_at":"2018-04-08T15:00:31.000Z","size":11,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-14T09:13:54.514Z","etag":null,"topics":["connectjs","expressjs","jsonwebtoken"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/NimitzDEV.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-04-08T12:20:09.000Z","updated_at":"2018-04-08T15:00:33.000Z","dependencies_parsed_at":null,"dependency_job_id":"ff1f723d-17d8-44d4-9352-2e7b401feb94","html_url":"https://github.com/NimitzDEV/express-jwt-guard","commit_stats":{"total_commits":3,"total_committers":2,"mean_commits":1.5,"dds":"0.33333333333333337","last_synced_commit":"d3e21ee410395d8c4928e32ea594a164bc579181"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NimitzDEV%2Fexpress-jwt-guard","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NimitzDEV%2Fexpress-jwt-guard/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NimitzDEV%2Fexpress-jwt-guard/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NimitzDEV%2Fexpress-jwt-guard/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/NimitzDEV","download_url":"https://codeload.github.com/NimitzDEV/express-jwt-guard/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243551328,"owners_count":20309300,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["connectjs","expressjs","jsonwebtoken"],"created_at":"2024-11-20T00:26:29.460Z","updated_at":"2025-03-14T09:13:57.725Z","avatar_url":"https://github.com/NimitzDEV.png","language":"JavaScript","readme":"# express-jwt-guard\n\nThis middleware is use for control JWT authorization checking in a more central way.\n\nThis middleware can be run on Connect/Express framework.\n\n## Installation\n\n`npm install express-jwt-guard` or `yarn install express-jwt-guard`\n\n## Basic Usage\n\n```javascript\nconst express = require('express');\nconst app = express();\nconst config = require('./config');\nconst guard = require('../index')({'/': {permissions: ['ADMIN']}}, 'secret', {}, {});\n\napp.use(guard.guard);\napp.get('/', (req, res, next) =\u003e {\n   // if the JWT header contains valid token that has ADMIN permission\n   // request can be proceed otherwise will get 401\n   res.send('success');\n});\n```\n\n## Configuring router map\n\nWhen initializing the JWTGuard class, you should pass 4 parameters.\n\nThe first one is the router map, it indicates which request and which method should be validated.\n\nFor instance: Add a user should only can be done by admin account.\n\n```javascript\nmodule.exports = {\n    '/user': {\n\t    methods: ['POST'],\n        permissions: ['ADMIN']\n    }\n}\n```\n\nWhen POST /user, the JWTGuard will check `permissions` in JWT data to see if current user is qualified to do this, if not, it will return 401. Or the current user only has a STUDENT permission, it will return 403.\n\nIf the `methods` is not presented, all the methods will be checked.\n\nFor the route like `/user/:id`, you can also write `/user/:id` in the router map. But you should explicitly place a JWTGuard middleware inside that route, because we don't know the current matched pattern in the app level, we can only know it when it actually matched.\n\n```javascript\napp.get('/user/:id', guard.guard, (req, res, next) =\u003e res.send('success'))\n```\n\n## JWT Options\n\nFor the second parameter, you should provide a JWT secret, and the third parameter is the JWT options, learn more on jsonwebtoken\n\n## JWTGuard Options\n\nIt supports a `header` options, tells the JWTGuard from which header field to retrieve the JWT token, defaults  to `JWT`","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnimitzdev%2Fexpress-jwt-guard","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnimitzdev%2Fexpress-jwt-guard","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnimitzdev%2Fexpress-jwt-guard/lists"}