Passport.js strategy for TLS client certificate authentication. Version 2.1.0 is the latest stable release (as of 2023). The package enables mutual TLS authentication directly in Node.js applications without requiring a reverse proxy. It provides a verify callback that receives the parsed client certificate object from Node's TLS socket. Key differentiators: first-class support for the standard Passport.js pattern (serialization/deserialization, req.logIn, etc.), ability to pass request object to verify callback, and TypeScript type definitions shipped. Alternative to handling client certificates manually via tls.getPeerCertificate. Release cadence is low; updates are infrequent. Works only with Node.js HTTP/HTTPS servers (not Express middleware alone). Requires a TLS-enabled server with requestCert and rejectUnauthorized options set.
npm install passport-client-certNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Establishes HTTPS server with mutual TLS, uses passport-client-cert strategy to authenticate users based on client certificate common name.
Check the clientCert object structure: ensure you access properties like clientCert.subject.CN (note: uppercase CN, not cn). Use optional chaining for safety.
Either use session: false in authenticate or implement passport.serializeUser/deserializeUser and call req.login(user) in verify callback.
Use import { Strategy } from 'passport-client-cert' or const { Strategy } = await import('passport-client-cert'). For CommonJS, use require('passport-client-cert').default if default export, but named export works with older Node.Update import pattern: const Strategy = require('passport-client-cert').Strategy;Make sure passport.use(new ClientCertStrategy(...)) is executed before authenticate. Verify the strategy name is correct (default is 'client-cert').
Ensure the server has requestCert: true, and optionally handle cases where clientCert is null/falsy in the verify callback.
Check that the client certificate file is correctly formatted and the key matches. Use openssl to validate: openssl x509 -in cert.pem -text -noout.