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-tokenVerified import paths — ran on the pinned version, not inferred.
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.
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.
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.
Use CommonJS `require` syntax: `const HTTPHeaderTokenStrategy = require('passport-http-header-token').Strategy;` in your Node.js application.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 }; }`When authenticating requests, always specify `{ session: false }` in the `passport.authenticate()` options: `passport.authenticate('http-header-token', { session: false, ... })`.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(...));`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.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.