Registry / http-networking / superagent-auth-bearer

superagent-auth-bearer

JSON →
library0.0.1jsnpmunverified

A lightweight plugin for Superagent that adds a convenient `.authBearer()` method for OAuth2 Bearer Token authentication. Version 0.0.1, released in 2014, is a minimal wrapper that monkey-patches the Superagent prototype. It is not actively maintained and lacks TypeScript types, ESM support, or modern security features. Compared to alternatives like `superagent-oauth`, this plugin focuses solely on Bearer tokens without extra OAuth2 flows. It requires Superagent as a peer dependency and modifies the global request object.

npm install superagent-auth-bearer
INSTALL
IMPORT
SIG · SUPERAGENT-AUTH-BE
S
superagent-auth-bearer
http-networkingjavascriptv0.0.1
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.

plugin
const request = require('superagent'); require('superagent-auth-bearer')(request);
import 'superagent-auth-bearer';
The plugin is a function that must be called with the superagent request module. A bare import will not activate it. There is no ESM version.
authBearer method
request.get('/').authBearer('token')
request.get('/').set('Authorization', 'Bearer token')
The plugin adds the .authBearer() method to superagent instances. Using .set() is the manual alternative but is not directly wrong.
default export
const bearer = require('superagent-auth-bearer'); bearer(request);
import bearer from 'superagent-auth-bearer';
The package uses CommonJS and exports a single function. There is no default export for ESM.

Shows how to install the plugin, call it with superagent, and use the authBearer method to make an authenticated GET request.

const request = require('superagent'); require('superagent-auth-bearer')(request); request .get('https://api.example.com/data') .authBearer(process.env.ACCESS_TOKEN ?? '') .then(res => console.log(res.body)) .catch(err => console.error(err));
Debug
Known issues
deprecatedPackage has not been updated since 2014 and likely has unpatched vulnerabilities.
fix
Consider using native superagent .set('Authorization', 'Bearer token') or migrate to a modern HTTP library like axios or node-fetch.
affects: >=0.0.0
gotchaThe plugin mutates the global superagent prototype, which can lead to unexpected behavior if multiple versions of superagent are installed.
fix
Ensure only one version of superagent is used; use npm's shrinkwrap or lockfile.
affects: >=0.0.0
gotchaThe plugin does not check for a valid token string; it sets the header even if token is null or undefined.
fix
Manually validate the token before passing to .authBearer().
affects: >=0.0.0
breakingIncompatible with superagent v3+ which uses a different plugin API?
fix
Test with superagent v2; for v3+ use manual Authorization header.
affects: >=0.0.0
Errors
Common errors & fixes
TypeError: request(...).authBearer is not a function
The plugin has not been initialized. It must be called with the superagent module.
fix
Make sure to run require('superagent-auth-bearer')(request) before using .authBearer().
Cannot find module 'superagent-auth-bearer'
The package may not be installed. Also check that you are in the correct directory.
fix
Run npm install superagent-auth-bearer --save (or --save-dev).
Warning: require() of ES modules not supported
You are using an ESM project and trying to require() a CommonJS module without proper handling.
fix
Use dynamic import or create a CommonJS compatibility layer. For example: const bearer = (await import('superagent-auth-bearer')).default;
Upgrade
Version history
0.0.1latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
23 hits · last 30 days
node
20
OpenAI (training)
1
Resources
superagent-auth-bearer — npm install superagent-auth-bearer · libregistry