passport-http-bearer-sl is an HTTP Bearer authentication strategy specifically for the Passport.js middleware, forked from the original `passport-http-bearer` package. It enables Node.js applications to authenticate requests using bearer tokens, typically for protecting API endpoints and often in conjunction with OAuth 2.0. The key differentiation of this fork (version 1.0.4, last published in 2013) is the change in the expected query parameter for the token from 'access_token' to 'bearer_token'. This modification was made to prevent conflicts with reserved 'access_token' parameters used by certain OAuth providers, particularly within the context of the SuperLogin project. Due to its age and lack of recent updates (last GitHub commit in 2017), it is largely considered abandoned, with no active development or defined release cadence, making it suitable only for legacy systems or specific SuperLogin environments where this exact behavior is required. The original `passport-http-bearer` (actively maintained) or other `passport-http-custom-bearer` forks are generally preferred for new projects.
npm install passport-http-bearer-slVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to configure and use `passport-http-bearer-sl` with Express.js to protect an API endpoint using a bearer token, showing token verification and access to user data.
Ensure clients send the bearer token in the `Authorization` header as `Bearer <token>` or as a `bearer_token` query/body parameter, not `access_token`.
For new projects, consider using the original `passport-http-bearer` (which is actively maintained) or a more recent alternative. If you must use this package, thoroughly audit its code and dependencies for security flaws.
Always provide a `verify` callback function to the `BearerStrategy` constructor that handles token validation and calls the `done` callback.
Ensure your core `passport` package dependency is updated to version `0.6.0` or later to mitigate session fixation vulnerabilities. Even with `session: false` this is good practice.
Pass a function as the second argument (or first, if no options object) to the `BearerStrategy` constructor: `new BearerStrategy(function(token, done) { /* ... */ })`.For CommonJS, use `const { Strategy: BearerStrategy } = require('passport-http-bearer-sl');`. For ESM (if transpiled), use `import { Strategy as BearerStrategy } from 'passport-http-bearer-sl';`.Send the token via the `Authorization: Bearer <token>` header or use the `bearer_token` query/body parameter instead of `access_token`.