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

fastauth

v1.0.4

Published

A simple yet fast token authorization / authentication method. No need for bulky modules.

Downloads

5

Readme

Fast Auth

A simple yet fast Token Authorization / Authentication method. No need for bulky modules

This module is lightwight and simply gets straight to the point of creating and authorizing tokens with expiry built in.

Main functions & Features

| Features | Description | | ------------------------------- | ------------------------- | | createToken(payload,secret) | This simply encodes our payload *data* to base 64 and signs the token using hmac sha256 for productive security 2018* | | authToken(token, secret) | This will check the token is valid and that the data has not been tampered with. | | expiry default 9000000 2.5hrs | You can set your own expiry by using createToken(payload,secret,expiry) | | Authorization: Bearer | This currently works using tokens that contain Bearer, see examples to add this so it will also parse your token if not. |

Requires

  • Tested on Node.js v10.14+.
  • Uses crypto for the hmac sha256 token signing.

Installation

Install using NPM

npm i fastauth --save

Test example using

Make sure you are inside the fastauth directory and use

node example/app.js

Example Usage

Creating a token

// Require our module.
const auth = require('fastauth');

let secret = '3748238949jkfndkcvniwe733' // Please use a secure secret.
userID = '1',
userName = 'AdminTest',
email = '[email protected]',
custom = 'custom',
expiry = 3000000,

payload = `
    "user": {
        "_id":"${userID}",
        "username":"${userName}",
        "email":"${email}",
        "custom":"${custom}"
    }`;
let token = auth.createToken(payload, secret);
console.log(`Your token has been created: Bearer ${token}`);

Sample output

PAYLOAD IN BASE64 SEPREATED BY . WHICH IS THE SIGNATURE

ewogICAgInVzZXIiOiB7CiAgICAgICAgIl9pZCI6IjEiLAogICAgICAgICJ1c2VybmFtZSI6IkFkbWluVGVzdCIsCiAgICAgICAgImVtYWlsIjoiYWRtaW5AdGVzdC5jb20iLAogICAgICAgICJjdXN0b20iOiJjdXN0b20iCiAgICB9LCJpYXQiOjE1NDQ3OTU3NTY5MjYsCiAgICAgICAgICAgICAgICAgICAgICAgICAgICJleHAiOjE1NDQ3OTg3NTY5MjYKICAgICAgICB9.Hwv18Lpc7QSd/RVROVbWhIMnVDmsB+uPsepeLjbycTE=

Authenticating a token

// Require our module.
const auth = require('fastauth');

let token = req.headers['authorization']; // OR
// If the token has does not have Bearer use
let token = `Bearer ${token from req}`;

let isAuth = auth.authToken(checkToken, secret);
// If isAuth...
if(isAuth)
    // Do stuff after the token has been verified.
    console.log(`You're token is valid! Data: ${token}`);
else
    // Invalid token.
    console.log(`Invalid Token!`);

Updates

v1.0.4 -- This is the first stable release.

To do

Possibly improve some of the code Improve the readme / doc, to better undersand the function.

Feedback

Feedback and improvments are always appreciated and help us to improve so please leave some!

License

Licensed under MIT.