Registry / auth-security / passport-http-header-token

passport-http-header-token

JSON →
library1.1.0jsnpmunverified

Passport HTTP Header Token is a Node.js authentication strategy for the Passport.js middleware, designed to authenticate users based on a raw token provided directly in an HTTP header. This strategy, currently at version 1.1.0, was last published in 2016 and has not received updates since, indicating it is an abandoned package. Its simple design requires a `verify` callback to validate the submitted token against a user store. Unlike the more commonly used `passport-http-bearer` strategy, `passport-http-header-token` expects a raw token value in the header rather than parsing a 'Bearer <token>' format, which can lead to confusion if standard RFC 6750 bearer tokens are expected. Due to its unmaintained status, developers should carefully consider potential security implications and evaluate more actively supported alternatives like `passport-http-bearer` or `passport-jwt` for modern applications.

npm install passport-http-header-token
INSTALL
IMPORT
SIG · PASSPORT-HTTP-HEAD
P
passport-http-header-token
auth-securityjavascriptv1.1.0
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

Strategy
const HTTPHeaderTokenStrategy = require('passport-http-header-token').Strategy;
import { Strategy } from 'passport-http-header-token';
The package is CommonJS-only and does not provide an ESM export for `Strategy`.
passport
const passport = require('passport');
import passport from 'passport';
Passport.js itself, like this strategy, is primarily CommonJS and typically imported via `require` in older Node.js projects.
configure strategy
passport.use(new HTTPHeaderTokenStrategy( /* ... */ ));
passport.use('http-header-token', /* ... */);
The strategy is typically instantiated and passed directly to `passport.use()` or named explicitly (e.g., `'token'`) as the first argument.

Demonstrates how to set up and use `passport-http-header-token` in an Express application to authenticate requests using a token provided in the 'Authorization' header.

const express = require('express'); const passport = require('passport'); const HTTPHeaderTokenStrategy = require('passport-http-header-token').Strategy; const app = express(); // Mock User database for demonstration const users = [{ id: 1, username: 'testuser', token: 'mysecrettoken123' }]; passport.use(new HTTPHeaderTokenStrategy( function(token, done) { // In a real application, you would query your database here // for a user associated with the provided token. console.log(`Attempting to authenticate with token: ${token}`); const user = users.find(u => u.token === token); if (!user) { return done(null, false, { message: 'Incorrect token.' }); } return done(null, user); } )); app.use(passport.initialize()); app.get('/api/protected', passport.authenticate('http-header-token', { session: false, failureMessage: true }), function(req, res) { res.json({ message: `Access granted, user: ${req.user.username}` }); } ); app.get('/', (req, res) => { res.send('Welcome! Try GET /api/protected with an Authorization header like: Authorization: mysecrettoken123'); }); const PORT = process.env.PORT || 3000; app.listen(PORT, () => { console.log(`Server running on http://localhost:${PORT}`); console.log('Test with: curl -H "Authorization: mysecrettoken123" http://localhost:3000/api/protected'); console.log('Test failure with: curl -H "Authorization: wrongtoken" http://localhost:3000/api/protected'); });
Debug
Known issues
breakingThis package is effectively abandoned, with the last publish date over 10 years ago (June 2016). It has not received any updates or security patches since. Using unmaintained software carries significant security risks and may not be compatible with modern Node.js versions or best practices.
fix
Consider migrating to actively maintained alternatives like `passport-http-bearer` (for standard bearer tokens) or `passport-jwt` (for JSON Web Tokens). If custom header token behavior is required, `passport-http-custom-bearer` is another option. Evaluate the security implications carefully if continued use is unavoidable.
affects: >=1.1.0
gotchaUnlike `passport-http-bearer`, this strategy expects the raw token value directly in the specified HTTP header (defaulting to 'Authorization'). It does not parse standard 'Bearer <token>' or other scheme-prefixed formats. Providing 'Bearer <token>' will pass 'Bearer <token>' as the token value to your verify callback.
fix
Ensure your client sends only the raw token value (e.g., `Authorization: mysecrettoken123`) or modify your `verify` callback to parse the incoming header string if it includes a scheme. For standard bearer token parsing (e.g., `Authorization: Bearer <token>`), use `passport-http-bearer` instead.
affects: >=1.0.0
gotchaThis package is CommonJS-only and does not provide native ESM exports. Attempting to `import { Strategy } from 'passport-http-header-token'` in an ESM module will result in an error.
fix
Use CommonJS `require` syntax: `const HTTPHeaderTokenStrategy = require('passport-http-header-token').Strategy;` in your Node.js application.
affects: >=1.0.0
gotchaThis package does not ship with TypeScript type definitions, nor are official types available on `@types/passport-http-header-token`. This necessitates manual type declarations or `@ts-ignore` usage in TypeScript projects.
fix
Create a `d.ts` declaration file (e.g., `passport-http-header-token.d.ts`) with basic types for the strategy. Example: `declare module 'passport-http-header-token' { class Strategy extends require('passport').Strategy { constructor(verify: (token: string, done: (err: any, user?: any, info?: any) => void) => void); } export { Strategy }; }`
affects: >=1.0.0
gotchaFor API authentication using tokens, sessions are typically not needed and should be explicitly disabled to prevent unexpected behavior or session cookies being set. The default Passport behavior often involves sessions.
fix
When authenticating requests, always specify `{ session: false }` in the `passport.authenticate()` options: `passport.authenticate('http-header-token', { session: false, ... })`.
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: Strategy must be a function
The `HTTPHeaderTokenStrategy` was not properly imported or instantiated as a class before being passed to `passport.use()`.
fix
Ensure you are requiring the `Strategy` property from the package and instantiating it with `new`: `const HTTPHeaderTokenStrategy = require('passport-http-header-token').Strategy; passport.use(new HTTPHeaderTokenStrategy(...));`
Error: Unknown authentication strategy "http-header-token"
The `passport-http-header-token` strategy has not been registered with Passport using `passport.use()` before `passport.authenticate()` is called.
fix
Verify that `passport.use(new HTTPHeaderTokenStrategy(...))` is executed before any routes or middleware that use `passport.authenticate('http-header-token', ...)`. Also check for typos in the strategy name.
Authentication Failed (or similar log/response for incorrect token)
The token provided by the client does not match any known user, or the `verify` callback returned `done(null, false)`.
fix
Check the token sent in the HTTP header by the client. Ensure your `verify` callback logic correctly retrieves and validates the token against your user data. Remember this strategy expects a raw token, not 'Bearer <token>' unless you parse it.
Upgrade
Version history
1.1.0latest on npm
Audit
Dependencies
passportrequiredThis package is a strategy for the Passport.js authentication middleware.
Agent activity
9 hits · last 30 days
node
8
OpenAI (training)
1
Resources