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

tokies

v0.0.3

Published

A JWT token jar that partially mimics the API of the 'cookies' module, for easy drop in replacement

Downloads

15

Readme

Tokies

A cookies mimicking API for JSON Web Tokens (hash tokens that can be decoded to an object)

See jwt-simple module

API

var Tokies = require('tokies');
var tokens = new Tokies(request, response, secret)

This creates a tokens jar corresponding to the current request and response, the secret is important for creating unique hashes on your server (if someone has this secret they can decode your users tokens - which is bad)

tokens.get(name)

Returns a value from the payload of a token (e.g. any values that have been set), will return undefined if the token has been encoded.

tokens.set(name, [value])

Sets a value on the tokens payload, if called without a value it mimics the cookies API and clears the key from the store. For better semantics, the clear method is also supplied.

tokens.payload

A pseudo private value (available mainly for inspection purposes mainly) The object containing the keys and values is known as the payload.

tokens.encode()

Returns a token hash of the payload, clears the internal payload object. At this point the tokens is an unusable shell, until decode is called with a token hash.

tokens.decode(hash)

Populates the internal payload by decoding the hash into an object, at this point .get and .set can be used again.

tokens.clear(name)

Clears a value from the store.

Middleware

Tokies also supplies ready-to-go middleware go decoding incoming tokens

Example usage:

var app = express();
app.use(require('tokies').middleware(opts))

The middleware parses an expected Authorization header, containing Bearer <token>. If the auth header isn't found it then attempts to obtain a token from query string params, but only if a key is provided.

Options

{
  tokens: {}, // the tokens object, required unless using path instead
  path: [], // alternative to tokens, provide a path to the tokens
  		   // object as stored on on the request object, e.g. ['token'],
  		   // refers to req.token or ['state', 'jar'] would be req.state.jar
  key: '', //required if tokens are being passed by query params, we need to 
  		   //know the key referencing the token. 
}