{"id":15022301,"url":"https://github.com/ethan-arrowood/fastify-jwt-authz","last_synced_at":"2025-04-12T13:03:27.001Z","repository":{"id":57233306,"uuid":"118166964","full_name":"Ethan-Arrowood/fastify-jwt-authz","owner":"Ethan-Arrowood","description":"Verify authenticated user scope","archived":false,"fork":false,"pushed_at":"2018-03-22T00:02:19.000Z","size":15,"stargazers_count":16,"open_issues_count":0,"forks_count":5,"subscribers_count":5,"default_branch":"master","last_synced_at":"2024-05-01T16:13:37.899Z","etag":null,"topics":["fastify","fastifyjs-plugin","javascript","jwt-authentication","nodejs"],"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/Ethan-Arrowood.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":"2018-01-19T19:11:31.000Z","updated_at":"2023-09-22T01:41:29.000Z","dependencies_parsed_at":"2022-08-31T18:33:50.995Z","dependency_job_id":null,"html_url":"https://github.com/Ethan-Arrowood/fastify-jwt-authz","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Ethan-Arrowood%2Ffastify-jwt-authz","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Ethan-Arrowood%2Ffastify-jwt-authz/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Ethan-Arrowood%2Ffastify-jwt-authz/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Ethan-Arrowood%2Ffastify-jwt-authz/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Ethan-Arrowood","download_url":"https://codeload.github.com/Ethan-Arrowood/fastify-jwt-authz/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":229088009,"owners_count":18018365,"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":["fastify","fastifyjs-plugin","javascript","jwt-authentication","nodejs"],"created_at":"2024-09-24T19:57:46.007Z","updated_at":"2024-12-10T15:33:25.571Z","avatar_url":"https://github.com/Ethan-Arrowood.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Fastify JWT Authz\n### Created by Ethan Arrowood\n\n[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat)](http://standardjs.com/) [![Build Status](https://travis-ci.org/Ethan-Arrowood/fastify-jwt-authz.svg?branch=master)](https://travis-ci.org/Ethan-Arrowood/fastify-jwt-authz)\n\n`fastifyJWTAuthz` is a fastify plugin for verifying an authenticated `request.user` scope. Registering the plugin binds the `jwtAuthz` method to the fastify `request` instance. See the demo below on how to use the plugin.\n\n```js\nconst fastify = require('fastify')()\nconst jwt = require('fastify-jwt')\nconst jwtAuthz = require('fastify-jwt-authz')\n\nfastify.register(jwt, {\n  secret: 'superSecretCode'\n})\nfastify.register(jwtAuthz)\n\nfastify.get('/api', {\n  beforeHandler: [\n    function(request, reply, done) {\n      request.jwtVerify(done)\n      /* The user's JWT auth token is\n       * connected to the request object \n       * under `headers.authentication`.\n       * \n       * The jwtVerify method will verify \n       * the JWT token with the secret.\n       * \n       * If it verifies, the user object is \n       * populated onto the request object \n       * which is passed to the next function.\n       * */\n    }, \n    function(request, reply, done) {\n      request.jwtAuthz(['read:data', 'write:data'], done)\n      /* jwtAuthz will read the verified user's\n       * scope off of the request object. It will \n       * then compare the scopes defined above to\n       * the user's scopes aquired by the JWT verification\n       * method.\n       * */\n    },\n  ],\n}, (request, reply) =\u003e {\n  fastify.log.info('reached API endpoint')\n  reply.send({ userVerified: true })\n})\n```\n\n`jwtAuthz` takes a list of scopes for verification. Additionally, it takes an optional callback parameter. It returns a promise otherwise.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fethan-arrowood%2Ffastify-jwt-authz","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fethan-arrowood%2Ffastify-jwt-authz","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fethan-arrowood%2Ffastify-jwt-authz/lists"}