All Projects → Ethan-Arrowood → fastify-jwt-authz

Ethan-Arrowood / fastify-jwt-authz

Licence: MIT license
Verify authenticated user scope

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to fastify-jwt-authz

fastify-file-upload
Fastify plugin for uploading files
Stars: ✭ 68 (+385.71%)
Mutual labels:  fastify, fastifyjs-plugin
fastify-nodemailer
Fastify nodemailer plugin
Stars: ✭ 23 (+64.29%)
Mutual labels:  fastify, fastifyjs-plugin
fastify-angular-universal
Angular Universal integration to Fastify for rendering Angular apps on the server
Stars: ✭ 20 (+42.86%)
Mutual labels:  fastify, fastifyjs-plugin
Express Mongodb Rest Api Boilerplate
A boilerplate for Node.js apps / Rest API / Authentication from scratch - express, mongodb (mongoose).
Stars: ✭ 153 (+992.86%)
Mutual labels:  jwt-authentication
React Jwt Authentication Example
React - JWT Authentication Tutorial & Example
Stars: ✭ 170 (+1114.29%)
Mutual labels:  jwt-authentication
Api on rails
Learn best practices to build an API using Ruby on Rails 5/6
Stars: ✭ 236 (+1585.71%)
Mutual labels:  jwt-authentication
Quasar-JWT
Quasar - JWT Authentication Starter Kit
Stars: ✭ 38 (+171.43%)
Mutual labels:  jwt-authentication
Spring Boot Angular4 Boilerplate
Quickstart for spring boot + angular 4 projects
Stars: ✭ 151 (+978.57%)
Mutual labels:  jwt-authentication
FRDP
Boilerplate code for quick docker implementation of REST API with JWT Authentication using FastAPI, PostgreSQL and PgAdmin ⭐
Stars: ✭ 55 (+292.86%)
Mutual labels:  jwt-authentication
Php Jwt
Ultra lightweight, dependency free and standalone JSON web token (JWT) library for PHP5.6 to PHP8.0. This library makes JWT a cheese.
Stars: ✭ 214 (+1428.57%)
Mutual labels:  jwt-authentication
Jwt Spring Security Jpa
Backend MVP showcasing JWT (Json Web Token) authentication with multiple login, timeout / refresh / logout (with in memory invalidation) using Spring Security & MySQL JPA.
Stars: ✭ 202 (+1342.86%)
Mutual labels:  jwt-authentication
Go Vue Starter
Starter project - Golang api, Vue.js client with user management and jwt authentication
Stars: ✭ 176 (+1157.14%)
Mutual labels:  jwt-authentication
MyAPI
A template to create awesome APIs easily ⚡️
Stars: ✭ 117 (+735.71%)
Mutual labels:  jwt-authentication
Fake Api Jwt Json Server
A Fake API with JWT Authentication using json-server and jsonwebtoken
Stars: ✭ 151 (+978.57%)
Mutual labels:  jwt-authentication
gatsby-starter-redux-saas
An Gatsby starter for Saas products. Uses redux and apollo and a graphql token auth backend.
Stars: ✭ 18 (+28.57%)
Mutual labels:  jwt-authentication
Jose2go
Golang (GO) implementation of Javascript Object Signing and Encryption specification
Stars: ✭ 150 (+971.43%)
Mutual labels:  jwt-authentication
laravel-vue-spa-boilerplate
Laravel Vue Spa BoilerPlate
Stars: ✭ 36 (+157.14%)
Mutual labels:  jwt-authentication
Angular Symfony
Project Bootstrap for an Angular + Symfony project
Stars: ✭ 196 (+1300%)
Mutual labels:  jwt-authentication
Spring Webflux Security Jwt
A JWT authorization and authentication implementation with Spring Reactive Webflux, Spring Boot 2 and Spring Security 5
Stars: ✭ 190 (+1257.14%)
Mutual labels:  jwt-authentication
Laravel Jwt
Dead simple, plug and play JWT API Authentication for Laravel (5.4+)
Stars: ✭ 225 (+1507.14%)
Mutual labels:  jwt-authentication

Fastify JWT Authz

Created by Ethan Arrowood

js-standard-style Build Status

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.

const fastify = require('fastify')()
const jwt = require('fastify-jwt')
const jwtAuthz = require('fastify-jwt-authz')

fastify.register(jwt, {
  secret: 'superSecretCode'
})
fastify.register(jwtAuthz)

fastify.get('/api', {
  beforeHandler: [
    function(request, reply, done) {
      request.jwtVerify(done)
      /* The user's JWT auth token is
       * connected to the request object 
       * under `headers.authentication`.
       * 
       * The jwtVerify method will verify 
       * the JWT token with the secret.
       * 
       * If it verifies, the user object is 
       * populated onto the request object 
       * which is passed to the next function.
       * */
    }, 
    function(request, reply, done) {
      request.jwtAuthz(['read:data', 'write:data'], done)
      /* jwtAuthz will read the verified user's
       * scope off of the request object. It will 
       * then compare the scopes defined above to
       * the user's scopes aquired by the JWT verification
       * method.
       * */
    },
  ],
}, (request, reply) => {
  fastify.log.info('reached API endpoint')
  reply.send({ userVerified: true })
})

jwtAuthz takes a list of scopes for verification. Additionally, it takes an optional callback parameter. It returns a promise otherwise.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].