Hawk is a Node.js library implementing the HTTP Hawk Authentication Scheme, a robust mechanism for making authenticated HTTP requests with partial cryptographic verification. It uses a message authentication code (MAC) algorithm to cover the HTTP method, request URI, host, and optionally the request payload, providing an alternative to HTTP Digest access authentication. Developed by Mozilla, the package is currently at version 9.0.2. It is in a 'maintenance mode' where no new features are added, and only security-related bug fixes are applied, with v9.0.2 announced as the final release. Key differentiators include its focus on two-legged client-server authentication (not OAuth delegation) and its history of ownership by hueniverse, then @hapi, and now Mozilla.
npm install hawkVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates a basic Hawk client-server interaction in Node.js, including server-side request authentication and client-side header generation.
Upgrade your Node.js runtime to version 12 or newer. If using Hapi, ensure it's version 18 or newer.
For browser usage, consider alternative client-side authentication mechanisms or adapt your build process to bundle compatible older versions, though this is not recommended due to security implications.
Evaluate alternative authentication schemes or Hawk implementations in other languages if long-term active development and feature additions are critical for your project.
Always use `npm install hawk` and verify that the installed package's `package.json` points to the `mozilla/hawk` repository for the latest maintenance version.
If time synchronization is a critical component for your application's security, consider implementing an external NTP client or a similar mechanism to ensure client and server clocks are synchronized.
Ensure the client is sending the correct `id` in its Hawk credentials that the server's `credentialsLookup` function can successfully resolve.
Check client-side clock synchronization, ensure credentials (id, key, algorithm) are correct, and verify that the request details (URI, method, payload) used for MAC generation precisely match the server's expectations. Look for 'mac' or 'timestamp' errors in server logs.
For ESM, use `import { Server, Client } from 'hawk';`. For CJS, ensure `const Hawk = require('hawk');` and then use `Hawk.Server.authenticate` or `Hawk.Client.header`. Alternatively, import specific modules like `require('hawk/server')` or `require('hawk/client')` if the package structure allows.No dependency data recorded yet.