Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

hawk

Package Overview
Dependencies
Maintainers
1
Versions
85
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

hawk

HTTP Hawk Authentication Scheme

  • 4.0.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
940K
decreased by-29.31%
Maintainers
1
Weekly downloads
 
Created

What is hawk?

The 'hawk' npm package is a security-oriented library that provides HTTP authentication using the Hawk protocol. It is designed to help developers implement secure communication between clients and servers by ensuring message integrity and authenticity.

What are hawk's main functionalities?

Message Authentication

This feature allows you to generate an HTTP Authorization header for a request, ensuring that the request is authenticated and has not been tampered with. The code sample demonstrates how to create a Hawk client header using provided credentials.

const Hawk = require('hawk');

const credentials = {
  id: 'dh37fgj492je',
  key: 'aoijedoaijsdlaksjdl',
  algorithm: 'sha256'
};

const header = Hawk.client.header('http://example.com/resource/1?b=1&a=2', 'GET', { credentials: credentials, ext: 'some-app-data' });
console.log(header.field);

Server Authentication

This feature allows you to authenticate incoming HTTP requests on the server side. The code sample demonstrates how to set up a simple HTTP server that uses Hawk to authenticate requests.

const Hawk = require('hawk');

const credentialsFunc = function (id, callback) {
  const credentials = {
    id: id,
    key: 'aoijedoaijsdlaksjdl',
    algorithm: 'sha256'
  };
  return callback(null, credentials);
};

const server = require('http').createServer((req, res) => {
  Hawk.server.authenticate(req, credentialsFunc, {}, (err, credentials, artifacts) => {
    if (err) {
      res.writeHead(401);
      res.end('Unauthorized');
      return;
    }
    res.writeHead(200, { 'Content-Type': 'text/plain' });
    res.end('Hello ' + credentials.user);
  });
});

server.listen(8000);

Bewit (URL) Authentication

This feature allows you to generate a 'bewit' token for URL-based authentication. The code sample demonstrates how to create a bewit token that can be appended to a URL for temporary access.

const Hawk = require('hawk');

const credentials = {
  id: 'dh37fgj492je',
  key: 'aoijedoaijsdlaksjdl',
  algorithm: 'sha256'
};

const bewit = Hawk.uri.getBewit('http://example.com/resource/1?b=1&a=2', { credentials: credentials, ttlSec: 60 });
console.log(bewit);

Other packages similar to hawk

Keywords

FAQs

Package last updated on 06 Nov 2015

Did you know?

Socket

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
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc