{"id":13716392,"url":"https://github.com/kandros/micro-jwt-auth","last_synced_at":"2025-05-07T05:32:54.676Z","repository":{"id":17494758,"uuid":"82102674","full_name":"kandros/micro-jwt-auth","owner":"kandros","description":"jwt authorization wrapper for https://github.com/zeit/micro","archived":false,"fork":false,"pushed_at":"2022-01-15T01:25:20.000Z","size":245,"stargazers_count":94,"open_issues_count":12,"forks_count":30,"subscribers_count":4,"default_branch":"master","last_synced_at":"2024-04-15T07:27:17.910Z","etag":null,"topics":["authorization","jwt","micro","microservice"],"latest_commit_sha":null,"homepage":"","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/kandros.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":"2017-02-15T20:20:21.000Z","updated_at":"2024-02-03T12:22:36.000Z","dependencies_parsed_at":"2022-08-07T08:16:02.855Z","dependency_job_id":null,"html_url":"https://github.com/kandros/micro-jwt-auth","commit_stats":null,"previous_names":[],"tags_count":17,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kandros%2Fmicro-jwt-auth","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kandros%2Fmicro-jwt-auth/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kandros%2Fmicro-jwt-auth/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kandros%2Fmicro-jwt-auth/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kandros","download_url":"https://codeload.github.com/kandros/micro-jwt-auth/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":224160207,"owners_count":17265943,"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":["authorization","jwt","micro","microservice"],"created_at":"2024-08-03T00:01:10.037Z","updated_at":"2024-11-14T04:31:30.366Z","avatar_url":"https://github.com/kandros.png","language":"JavaScript","funding_links":[],"categories":["Modules","micro"],"sub_categories":["Wrappers"],"readme":"[![Build Status](https://travis-ci.org/kandros/micro-jwt-auth.svg?branch=master)](https://travis-ci.org/kandros/micro-jwt-auth)\n[![npm](https://img.shields.io/npm/v/micro-jwt-auth.svg)](https://www.npmjs.com/package/micro-jwt-auth)\n# micro-jwt-auth\n[json web token(jwt)](https://jwt.io/introduction/) authorization wrapper for [Micro](https://github.com/zeit/micro)\n\n\u003e An `Authorization` header with value `Bearer MY_TOKEN_HERE` is expected\n\n## examples\n\n#### with no other wrappers\n```javascript\n'use strict'\n\nconst jwtAuth = require('micro-jwt-auth')\n\n/*\n    if Authorization Bearer is not present or not valid, return 401\n*/\n\nmodule.exports = jwtAuth('my_jwt_secret')(async(req, res) =\u003e {\n  return `Ciaone ${req.jwt.username}!`\n})\n```\n\n#### with multiple wrappers\n\n```javascript\n'use strict'\n\nconst jwtAuth = require('micro-jwt-auth')\n\nconst compose = (...fns) =\u003e fns.reduce((f, g) =\u003e (...args) =\u003e f(g(...args)))\n\nconst handle = async(req, res) =\u003e {\n  return `Ciaone ${req.jwt.username}!`\n}\n\nmodule.exports = compose(\n    jwtAuth(process.env.jwt_secret),\n    anotherWrapper,\n    analitycsWrapper,\n    redirectWrapper,\n    yetAnotherWrapper\n)(handle)\n```\n\n#### with whitelist of paths\nWhitelisted paths make JWT token *optional*. However if valid token is provided it will be  decoded.\n\n```javascript\n'use strict'\n\nconst jwtAuth = require('micro-jwt-auth')\n\n/*\n    Bypass authentication for login route\n*/\n\nmodule.exports = jwtAuth('my_jwt_secret', [ 'api/login' ])(async(req, res) =\u003e {\n  return `Ciaone ${req.jwt.username}!`\n})\n```\n\n#### with custom responses\n\n```javascript\n'use strict'\n\nconst jwtAuth = require('micro-jwt-auth')\n\n/*\n    You can overwrite the default response with the optional config object\n*/\n\nmodule.exports = jwtAuth('my_jwt_secret', ['api/login'], {\n  resAuthInvalid: 'Error: Invalid authentication token',\n  resAuthMissing: 'Error: Missing authentication token'\n})(async(req, res) =\u003e {\n  return `Ciaone ${req.jwt.username}!`\n})\n\n/*\n  You may skip the whitelist if unnecessary\n*/\n\nmodule.exports = jwtAuth('my_jwt_secret', {\n  resAuthInvalid: 'Error: Invalid authentication token',\n  resAuthMissing: 'Error: Missing authentication token'\n})(async(req, res) =\u003e {\n  return `Ciaone ${req.jwt.username}!`\n})\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkandros%2Fmicro-jwt-auth","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkandros%2Fmicro-jwt-auth","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkandros%2Fmicro-jwt-auth/lists"}