{"id":15896048,"url":"https://github.com/agconti/express-jwt-token","last_synced_at":"2025-03-20T15:32:10.734Z","repository":{"id":30967399,"uuid":"34525581","full_name":"agconti/express-jwt-token","owner":"agconti","description":"A lean and configurable implementation of jwt auth for Express.js","archived":false,"fork":false,"pushed_at":"2018-02-26T18:51:36.000Z","size":208,"stargazers_count":4,"open_issues_count":2,"forks_count":2,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-10-20T18:34:29.435Z","etag":null,"topics":["authentication","express-middleware","json-web-token","jwt","nodejs"],"latest_commit_sha":null,"homepage":"http://agconti.github.io/express-jwt-token/","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/agconti.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}},"created_at":"2015-04-24T15:12:22.000Z","updated_at":"2019-07-15T11:23:29.000Z","dependencies_parsed_at":"2022-09-18T03:11:43.630Z","dependency_job_id":null,"html_url":"https://github.com/agconti/express-jwt-token","commit_stats":null,"previous_names":["agconti/jwt-token-auth"],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/agconti%2Fexpress-jwt-token","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/agconti%2Fexpress-jwt-token/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/agconti%2Fexpress-jwt-token/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/agconti%2Fexpress-jwt-token/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/agconti","download_url":"https://codeload.github.com/agconti/express-jwt-token/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":221776117,"owners_count":16878490,"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":["authentication","express-middleware","json-web-token","jwt","nodejs"],"created_at":"2024-10-06T09:05:32.048Z","updated_at":"2024-10-28T04:01:47.734Z","avatar_url":"https://github.com/agconti.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# JWT token auth for express.js\n[![Build Status](https://travis-ci.org/agconti/express-jwt-token.svg?branch=master)](https://travis-ci.org/agconti/express-jwt-token)\n[![npm version](https://badge.fury.io/js/express-jwt-token.svg)](http://badge.fury.io/js/express-jwt-token)\n\nThis package provides [JSON Web Token Authentication](http://tools.ietf.org/html/draft-ietf-oauth-json-web-token) support for\n[Express](http://expressjs.com/). It conveniently sets `req.user` for authenticated requests. The authorization header is in the from of: \n```\nAuthorization JWT \u003c jwt token \u003e \n```\n\nNew to using JSON Web Tokens? Take a look at these resources:\n\n- [JWT.io](http://jwt.io/)\n- [JSON Web Token Abstract](http://self-issued.info/docs/draft-ietf-oauth-json-web-token.html)\n- [Token based authentication with Socket.io](https://auth0.com/blog/2014/01/15/auth-with-socket-io/)\n\n# Installation \n```bash\nnpm install express-jwt-token\n```\n\n# Usage\n```js\nvar express = require('express')\n  , auth = require('express-jwt-token')\n  , app = express()\n  , router = express.Router()\n\n\n// Require jwt authorization on all routes\nrouter.all('*', auth.jwtAuthProtected)\n\n// Require jwt authorization on only api routes\nrouter.all('/api/*', auth.jwtAuthProtected)\n\n// Require jwt auth on a specific route\nrouter.get('/auth-protected', auth.jwtAuthProtected, function(req, res){\n  res.send({'msg': 'Im jwt auth protected!'})\n})\n\napp.use('/', router)\napp.listen(3000)\n```\nNow your route(s) are protected and require an authorization header in the form of:\n\n```\nAuthorization JWT \u003c jwt token \u003e \n```\n\n# Configuration\nConfigure your JWT Secret. This must be changed for production. Default value is `'secret'`. \n```js\nprocess.env.JWT_SECRET_KEY = 'Your Secret'\n```\n\nConfigure the authorization header prefix. this is optional. Default is `'JWT'`.\n```js\nprocess.env.jwtAuthHeaderPrefix\n```\n\n# Provided Middleware\n\n## ensureAuthorizationHeader\nAn Express.js middleware that ensures that a request has supplied an authorization header.\n* @param {object} req\n* @param {object} res\n* @param {function} next\n\n## validateJWTAuth\nAn Express.js middleware validates a JWT token.\n * @param {object} req\n * @param {object} res\n * @param {function} next\n\n## ensureAuthorized \nAn Express.js middleware that ensures that a request has supplied an authorization header.\n* @param {object} req\n* @param {object} res\n* @param {function} next\n\n## jwtAuthProtected \nThe grouped middleware needed to enforce jwt Auth. Mounts the same as a single middleware.\n\n# Errors \nWhen authorization fails `express-jwt-token` will return an `UnauthorizedError` with some helpful details about what went wrong. \n \nThis implementation was based on the excellent [django-rest-framework-jwt library](https://github.com/GetBlimp/django-rest-framework-jwt).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fagconti%2Fexpress-jwt-token","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fagconti%2Fexpress-jwt-token","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fagconti%2Fexpress-jwt-token/lists"}