{"id":18839,"library":"superagent-auth-bearer","title":"superagent-auth-bearer","description":"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.","status":"maintenance","version":"0.0.1","language":"javascript","source_language":"en","source_url":"http://github.com/rojo2/superagent-auth-bearer","tags":["javascript"],"install":[{"cmd":"npm install superagent-auth-bearer","lang":"bash","label":"npm"},{"cmd":"yarn add superagent-auth-bearer","lang":"bash","label":"yarn"},{"cmd":"pnpm add superagent-auth-bearer","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"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.","wrong":"import 'superagent-auth-bearer';","symbol":"plugin","correct":"const request = require('superagent'); require('superagent-auth-bearer')(request);"},{"note":"The plugin adds the .authBearer() method to superagent instances. Using .set() is the manual alternative but is not directly wrong.","wrong":"request.get('/').set('Authorization', 'Bearer token')","symbol":"authBearer method","correct":"request.get('/').authBearer('token')"},{"note":"The package uses CommonJS and exports a single function. There is no default export for ESM.","wrong":"import bearer from 'superagent-auth-bearer';","symbol":"default export","correct":"const bearer = require('superagent-auth-bearer'); bearer(request);"}],"quickstart":{"code":"const request = require('superagent');\nrequire('superagent-auth-bearer')(request);\n\nrequest\n  .get('https://api.example.com/data')\n  .authBearer(process.env.ACCESS_TOKEN ?? '')\n  .then(res => console.log(res.body))\n  .catch(err => console.error(err));","lang":"javascript","description":"Shows how to install the plugin, call it with superagent, and use the authBearer method to make an authenticated GET request."},"warnings":[{"fix":"Consider using native superagent .set('Authorization', 'Bearer token') or migrate to a modern HTTP library like axios or node-fetch.","message":"Package has not been updated since 2014 and likely has unpatched vulnerabilities.","severity":"deprecated","affected_versions":">=0.0.0"},{"fix":"Ensure only one version of superagent is used; use npm's shrinkwrap or lockfile.","message":"The plugin mutates the global superagent prototype, which can lead to unexpected behavior if multiple versions of superagent are installed.","severity":"gotcha","affected_versions":">=0.0.0"},{"fix":"Manually validate the token before passing to .authBearer().","message":"The plugin does not check for a valid token string; it sets the header even if token is null or undefined.","severity":"gotcha","affected_versions":">=0.0.0"},{"fix":"Test with superagent v2; for v3+ use manual Authorization header.","message":"Incompatible with superagent v3+ which uses a different plugin API?","severity":"breaking","affected_versions":">=0.0.0"}],"env_vars":null,"last_verified":"2026-04-25T00:00:00.000Z","next_check":"2026-07-24T00:00:00.000Z","problems":[{"fix":"Make sure to run require('superagent-auth-bearer')(request) before using .authBearer().","cause":"The plugin has not been initialized. It must be called with the superagent module.","error":"TypeError: request(...).authBearer is not a function"},{"fix":"Run npm install superagent-auth-bearer --save (or --save-dev).","cause":"The package may not be installed. Also check that you are in the correct directory.","error":"Cannot find module 'superagent-auth-bearer'"},{"fix":"Use dynamic import or create a CommonJS compatibility layer. For example: const bearer = (await import('superagent-auth-bearer')).default;","cause":"You are using an ESM project and trying to require() a CommonJS module without proper handling.","error":"Warning: require() of ES modules not supported"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}