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

sessionistheader

v0.1.14

Published

Parsing and creating the Authorization header for Sessionist HTTP authorization.

Downloads

23

Readme

Sessionist Authorization HTTP Header

Build Status

This JavaScript module creates and verifies the Sessionist Authorization HTTP Header.

How to create a valid header

const sessionistHeader = require('sessionistheader');

let myKeyId = '4bc0093d';
let mySecretKey = '3485eac0182ef8123c116fc8392b34e817268e292';
let theHttpMethod = 'PUT';
let theHttpPath = '/api/v1/myservice?cool=very';
let theBodyPayload = '{ "whatever": "is in the body of the http request" }';
let theHttpDate = 'Thu, 06 Oct 2016 22:27:21 GMT';

// myKeyId is an identifier for your secret key.
// mySecretKey is the secret key.
// theHttpMethod is an uppercase string with the method, like "GET" or "POST"
// theHttpPath is the path (including querystring) for the request.
// theBodyPayload is the raw body content of the request.
// theHttpDate is the current time in RFC2616 format.

sessionistHeader(myKeyId, mySecretKey, theHttpMethod, theHttpPath, theBodyPayload, theHttpDate, (err, auth) => {
	// The proper header string is now in the auth variable
	req.setHeader('Authorization', auth);
	req.setHeader('Date', theHttpDate); // Must also be set!
});

How to use the Promise interface

sessionistHeader(myKeyId, mySecretKey, theHttpMethod, theHttpPath, theBodyPayload, theHttpDate)
.then(auth => req.setHeader('Authorization', auth);

How to verify an Authorization header

const keyfn = (keyid, callback) => {
	// This function should find the corresponding secret key to
	// the given keyid, and then call the callback function, which
	// take two parameters: err and secretkey:
	callback(null, 'the topsecret key');
};

verify(headerStr, theHttpMethod, theHttpPath, theBodyPayload, theHttpDate, keyfn)
.then(() => {
	// Yes, verified successfully!
})
.catch(err => {
	// Nope. Not verified.
});

Some principles regarding the Sessionist Authorization HTTP Header

  • This is a custom RFC2617 Authorization header.
  • The scheme identifier is ss1, where "ss" is short for "Sessionist" and "1" tells this is version 1 of the Sessionist format.
  • Clients should be assigned a "secret key" and a "key id" identifying the secret key. The secret key should be kept secret and only be used for making hashes/checksums. The key id, however, can be sent in clear text in the header.
  • All requests to the server must include a Date: HTTP header with the current time in RFC2616 format. The server should not accept times older/newer than 24h from the current time.

Header format

The Sessionist Authorization HTTP Header is used for both authorization and verifying the body payload (checksum) of API requests.

Format is:

Authorization: ss1 keyid=<keyid>, hash=<hash>, nonce=<nonce>

keyid

See more info about the "key id" in the "Principles" section above.

hash

The hash is a SHA-512 HMAC (RFC2104) in lower case hex format, created like this:

HMAC(secret_key, nonce || method || path || payload || date)

Where:

  • || means concatination.
  • secret_key is the assigned to the client (and identified by the keyid).
  • nonce is the nonce in binary format (not in hex).
  • method is the HTTP method for the request, in uppercase letters.
  • path is the path of the request (including query string, if there is one).
  • payload is the HTTP body payload.
  • date is the content of the Date: HTTP header, i.e. the current time of the client in RFC2616 format.

nonce

A random 512 bit value in lower case hex format. Should be generated on every request using some good random generator.