Registry / auth-security / passport-oauth2-client-password

passport-oauth2-client-password

JSON →
library0.1.2jsnpmunverified

passport-oauth2-client-password is an authentication strategy module designed for the Passport.js middleware framework, specifically implementing the OAuth 2.0 client password grant type. It allows applications to authenticate client credentials (client ID and client secret) when provided in the request body, a common pattern for securing OAuth 2.0 token endpoints. The current stable version is 0.1.2. The package's last publish was 11 years ago, and its GitHub repository shows no recent activity, indicating it is no longer actively maintained. Its primary differentiator lies in providing a focused, simple implementation for this specific OAuth2 authentication mechanism within the Passport ecosystem. However, its age means it likely lacks modern JavaScript features, TypeScript definitions (though `@types/passport-oauth2-client-password` exists), and contemporary security updates. Developers should consider its abandoned status and potential compatibility issues with newer Node.js versions when evaluating its use.

npm install passport-oauth2-client-password
INSTALL
IMPORT
SIG · PASSPORT-OAUTH2-CL
P
passport-oauth2-client-password
auth-securityjavascriptv0.1.2
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.

ClientPasswordStrategy
const ClientPasswordStrategy = require('passport-oauth2-client-password');
import ClientPasswordStrategy from 'passport-oauth2-client-password';
This module directly exports the Strategy constructor. Given its age (last published 2013), ESM imports are not supported and will lead to errors in Node.js environments.
Strategy (named destructure)
const Strategy = require('passport-oauth2-client-password');
const { Strategy } = require('passport-oauth2-client-password');
The module's default export *is* the Strategy constructor itself, not an object containing a named export 'Strategy'. Attempting to destructure it will result in `undefined`.
ClientPasswordStrategy (Type)
import type { Strategy as ClientPasswordStrategy } from 'passport-oauth2-client-password';
import type { ClientPasswordStrategy } from 'passport-oauth2-client-password';
While the core package does not ship with types, `@types/passport-oauth2-client-password` provides definitions. It typically exports `Strategy` which can be aliased.

Demonstrates how to set up an Express server with Passport.js using `passport-oauth2-client-password` to authenticate client credentials for a mock token endpoint. It includes basic body parsing and a sample client database.

const express = require('express'); const passport = require('passport'); const ClientPasswordStrategy = require('passport-oauth2-client-password'); const app = express(); const port = 3000; // Middleware to parse request body (e.g., for client_id and client_secret) app.use(express.urlencoded({ extended: false })); app.use(express.json()); // Initialize Passport middleware app.use(passport.initialize()); // --- Mock Database (in a real app, this would be a database query) --- const clients = [ { id: 1, clientId: 'client123', clientSecret: 'secret123', name: 'Test Client' }, { id: 2, clientId: 'anotherClient', clientSecret: 'superSecret', name: 'Another Test Client' }, ]; // --- End Mock Database --- // Configure the Client Password strategy passport.use(new ClientPasswordStrategy( function(clientId, clientSecret, done) { console.log(`Attempting to authenticate client: ${clientId}`); const client = clients.find(c => c.clientId === clientId); if (!client) { console.log('Client not found.'); // `done(null, false)` indicates authentication failure. return done(null, false); } if (client.clientSecret !== clientSecret) { console.log('Client secret mismatch.'); return done(null, false); } console.log(`Client '${client.name}' authenticated successfully.`); // `done(null, client)` indicates success, attaching client to req.user return done(null, client); } )); // Define a token endpoint (or any endpoint requiring client authentication) app.post('/token', // Authenticate using the 'oauth2-client-password' strategy // `session: false` because clients typically don't establish sessions passport.authenticate('oauth2-client-password', { session: false }), (req, res) => { // If we reach here, the client is authenticated (req.user will contain the client object) console.log('Client authenticated successfully at /token endpoint.'); res.json({ message: 'Client authenticated successfully', client: req.user // The authenticated client object }); } ); // Simple root endpoint for demonstration app.get('/', (req, res) => { res.send('Welcome! Try POSTing to /token with client_id and client_secret in the body (form-urlencoded or JSON).'); }); app.listen(port, () => { console.log(`Server listening at http://localhost:${port}`); console.log('\n--- Test Commands ---'); console.log(`curl -X POST -H "Content-Type: application/x-www-form-urlencoded" -d "client_id=client123&client_secret=secret123" http://localhost:${port}/token`); console.log(`curl -X POST -H "Content-Type: application/x-www-form-urlencoded" -d "client_id=badclient&client_secret=badsecret" http://localhost:${port}/token`); console.log(`curl -X POST -H "Content-Type: application/json" -d '{"client_id":"client123","client_secret":"secret123"}' http://localhost:${port}/token`); });
Debug
Known issues
breakingThis package is effectively abandoned, with the last publish being over a decade ago. It has not received updates for new Node.js versions, security patches, or modern JavaScript features. Use with caution in production environments, especially regarding security vulnerabilities and compatibility.
fix
Consider more actively maintained alternatives for OAuth 2.0 client authentication, or audit the source code thoroughly and fork for maintenance.
affects: >=0.1.2
gotchaThis strategy is specifically designed for OAuth 2.0 client password authentication (client_id and client_secret in the request body) and not for authenticating end-users directly. It's typically used at a token endpoint to verify the requesting client application.
fix
Ensure you understand the OAuth 2.0 client credential flow. For user authentication, use other Passport strategies like `passport-local` or `passport-oauth2` for specific providers.
affects: >=0.1.2
gotchaThe package does not officially support ESM (ECMAScript Modules). Using `import` statements will result in runtime errors due to Node.js's CJS/ESM interoperability rules for older packages.
fix
Always use CommonJS `require()` syntax for importing this package. Example: `const ClientPasswordStrategy = require('passport-oauth2-client-password');`.
affects: >=0.1.2
Errors
Common errors & fixes
Error: Cannot find module 'passport-oauth2-client-password'
The package is not installed or the module resolution path is incorrect.
fix
Ensure the package is installed: `npm install passport-oauth2-client-password`. If using a non-standard module path, verify the path.
TypeError: ClientPasswordStrategy is not a constructor
This error typically occurs if you try to import the strategy using a named import (e.g., `import { ClientPasswordStrategy } from '...'`) or destructure it incorrectly from a `require` statement, or if the `require` statement itself fails.
fix
Use the correct CommonJS `require` syntax as the module directly exports the constructor: `const ClientPasswordStrategy = require('passport-oauth2-client-password');`.
Client authentication failing (verify callback returning `done(null, false)`)
The `verify` callback function within the strategy is returning `done(null, false)`, indicating that the provided `clientId` or `clientSecret` does not match your stored client credentials.
fix
Inspect the `clientId` and `clientSecret` values passed to the `verify` callback and compare them against your mock or database records. Ensure they match exactly and that your client lookup logic is correct. Log the input credentials and your stored clients for debugging.
Upgrade
Version history
0.1.2latest on npm
Audit
Dependencies
passportrequiredRequired for the strategy to function as an authentication middleware. This package integrates with Passport.js, which is a peer dependency by nature for any Passport strategy.
passport-strategyrequiredThis is a direct dependency listed in the package.json, providing the base Strategy class from which this strategy extends.
Agent activity
7 hits · last 30 days
node
6
OpenAI (training)
1
Resources
passport-oauth2-client-password — npm install passport-oauth2-client-password · libregistry