npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@wasc/jwt-middleware

v1.4.0

Published

Decodes and verifies the current an attached JWT Token and provides the result to the request context

Downloads

6

Readme

extract-authentication-middleware

extract-authentication-middleware

Overview

extract-authentication-middleware is an express middleware for getting the authorization header of a request and its embedded JWT Token and decoding its content.

Usage

Just like above:

import checkAuthentication from '@wasc/jwt-middleware'
import express from 'express';

const app = express();

app.use(checkAuthentication({
  secret: process.env.AUTHENTICATION_SECRET,
  error: pino.error,
});

Import the module, pass it the secret for verifying the token and use it. It works with CJS require as well.

Configuration

  • secret The secret for verifying the tokens signature
  • error A error logging function for logging any non expected errors [default: pino.error]

Data

If the authentication is successfull the middleware will create a few properties on the requets object:

// request
{
    // ...
    scope: String, // The scope of the authication token
    user: {}, // The encoded user object
    auth: {
        isAuthenticated: true // false
        scope: String, // The scope like above
    }
    // ...
}

If the authentication fails, because the token is faulty, not signing properly or if there's any other error, the middleware terminates the request and returns either one of the following three responses:

  1. If the token was used past its expiration:
// Status 401
{
    name: 'TokenExpired',
    message: 'The token cannot be used past its expiration',
}
  1. If the decoding of the token resulted in any errors, like untrusted signatures, malformed tokens or by providing an empty string as the token:
// Status 401
{
    name: 'BadCredentials',
    message: 'The provided token could not be verified.',
}
  1. And if any other error occured, it will be logged using the provided logger or pino and the response is the following:
// Status 400
{
    name: 'BadRequest',
    message: 'BadRequest',
}

This was made by Wasc