Socket
Socket
Sign inDemoInstall

@mitmaro/http-authorization-header

Package Overview
Dependencies
1
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @mitmaro/http-authorization-header

Parse and create HTTP Authorization headers.


Version published
Weekly downloads
2.8K
increased by20.37%
Maintainers
1
Created
Weekly downloads
 

Changelog

Source

1.0.0 - 2018-01-28

Changed

  • Use a different error library

Added

  • TypeScript definition file

Readme

Source

Node HTTP Authorization Header Parser and Generator

Dependency Status Build Status Coverage Status NPM version GitHub license

Parses and generates HTTP Authorization and Proxy-Authorization headers strictly following RFC-7235. Supports legacy style auth-schemes (Basic, Digest, Bearer) as well as the more modern key-value auth params.

Install

npm install --save @mitmaro/http-authorization-header

Documentation

Usage

Parse Header

const http = require('http');
const {parse} = require('@mitmaro/http-authorization-header');

const httpServer = http.createServer((req, res) => {
    const authHeader = req.getHeader('Authorization');
    // authHeader => 'myscheme foo=bar, baz=foobar, buzz="quoted \"value!\""
    
    const authData = parse(authHeader);
    
    console.log(authData);
    /*
    {
        scheme: 'myscheme',
        values: [
            ['foo', 'bar'],
            ['baz', 'foobar],
            ['buzz', 'quotes "value!"']
        ]
    }
    */
}).listen();

Create Header

const {create, createToken68} = require('@mitmaro/http-authorization-header');

// legacy header value support (Basic, Digest, Bearer)
const basicAuthHeader = createToken68('Basic', Buffer.from('username:password').toString('base64'));
// Basic dXNlcm5hbWU6cGFzc3dvcmQ=

// modern form
const rfc7235Header = create('Custom', [['foo', 'bar'], ['foo', 'fuzz'], ['buzz', 'quoted "value!"']]);
// Custom foo=bar,foo=fuzz,buzz="quoted \"value!\""

All exports

const {
	create,
	createUnsafe,
	createToken68,
	createToken68Unsafe,
	parse,
	InvalidHeaderError,
	InvalidInputError,
} = require('@mitmaro/http-authorization-header');

Contributing

If the library is not in compliance with RFC-7235 then create an issue explaining the issue with sample data, or even better create a pull request that adds a test that fails.

Development

Development is done using Node 8 and NPM 5, and tested against both Node 6 and Node 8. To get started

  • Install Node 8 from NodeJS.org or using nvm
  • Clone the repository using git clone git@github.com:MitMaro/http-authorization-header.git
  • cd http-authorization-header
  • Install the dependencies npm install
  • Make changes, add tests, etc.
  • Run linting and test suite using npm run test

License

Based on auth-header which was licensed under CC0-1.0. This project is released under the ISC license.

Keywords

FAQs

Last updated on 28 Jan 2018

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc