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
muslnode 18–226 runs
build_error
glibcnode 18–226 runs
build_error
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
Factory
✓ const sasl = require('saslmechanisms');
const factory = new sasl.Factory();
✗ import { Factory } from 'saslmechanisms';
The package exports an object (often aliased as `sasl`) that contains the `Factory` constructor. This package is CommonJS-only; ESM imports are not supported.
Mechanism registration
✓ factory.use(require('sasl-plain'));
✗ factory.use(SASLPlain);
Mechanism packages like `sasl-plain` are expected to be `require()`-d directly and passed to the `use` method to register them with the factory. Ensure the mechanism package is installed.
ClientSession / ServerSession
✓ const clientSession = factory.createClientSession('PLAIN');
✗ const clientSession = new sasl.ClientSession('PLAIN');
Client and server sessions are instantiated via the `factory` instance after mechanisms have been registered, not directly from the `sasl` object.
Demonstrates initializing the SASL factory, registering the 'PLAIN' mechanism, and simulating a basic client-server authentication flow.
const sasl = require('saslmechanisms');
// Create a SASL mechanism factory.
const factory = new sasl.Factory();
// Register supported SASL mechanisms. This package only provides the framework;
// mechanism implementations like 'sasl-plain' must be installed separately.
// For this example, ensure 'sasl-plain' is installed: npm install sasl-plain
try {
factory.use(require('sasl-plain'));
console.log('SASL PLAIN mechanism registered successfully.');
} catch (e) {
console.error('Failed to load sasl-plain. Make sure it is installed: npm install sasl-plain');
process.exit(1);
}
// Simulate client and server interactions for 'PLAIN' authentication.
const username = process.env.SASL_USERNAME || 'testuser';
const password = process.env.SASL_PASSWORD || 'testpassword';
// Client-side: initiate authentication with credentials
const clientSession = factory.createClientSession('PLAIN'); // 'PLAIN' is the mechanism name
const initialClientChallenge = clientSession.challenge({
username: username,
password: password
});
console.log(`\nClient initiated authentication with challenge: "${initialClientChallenge}"`);
// Server-side: respond to the client's challenge
const serverSession = factory.createServerSession('PLAIN');
try {
const serverResponse = serverSession.response(initialClientChallenge);
if (serverSession.isComplete()) {
console.log('Server successfully completed authentication.');
console.log(`Authenticated user: ${serverSession.username}`);
// In PLAIN, serverResponse is typically an empty string on success
} else {
console.log('Server authentication not complete, further steps might be required.');
}
} catch (error) {
console.error(`Server failed to authenticate: ${error.message}`);
}
console.log('\nSASL framework demonstration complete.');
Errors
Common errors & fixes
TypeError: Cannot read properties of undefined (reading 'Factory')
The `saslmechanisms` package was not correctly `require()`-d, or the variable name does not match the expected export.
fixEnsure you are using `const sasl = require('saslmechanisms');` and then `new sasl.Factory();`. Error: Unknown mechanism "PLAIN"
The required SASL mechanism package (e.g., `sasl-plain`) was not installed or not correctly registered with the factory using `factory.use()`.
fixInstall the necessary mechanism package (e.g., `npm install sasl-plain`) and add `factory.use(require('sasl-plain'));` to your initialization code. Audit
Dependencies
sasl-plainoptionalCommon SASL mechanism, required at runtime for 'PLAIN' authentication. Other `sasl-*` mechanism packages are also runtime dependencies depending on desired authentication methods.