Subversion Simple Auth Provider
The `svn-simple-auth-provider` package offers a Node.js-based solution for programmatically accessing credentials stored in Subversion's 'simple' authentication files. These files, typically located in `~/.subversion/auth/simple`, contain plaintext username and password pairs for various SVN realms. The library, currently at version 1.3.5, provides a `SvnSimpleAuthProvider` class to read and retrieve these stored credentials. Its release cadence is irregular, primarily focusing on dependency updates and minor bug fixes. A key differentiator is its direct parsing of the SVN simple auth file format, allowing integration into applications that need to interact with SVN repositories using stored credentials without invoking external SVN client commands. It requires Node.js version 16.20.2 or higher.
Common errors
-
Error: ENOENT: no such file or directory, scandir 'path/to/nonexistent/directory'
cause The `realmDirectory` provided to `SvnSimpleAuthProvider` constructor does not exist or the application lacks read permissions to it.fixVerify that the `realmDirectory` path is correct and points to a valid directory (e.g., `~/.subversion/auth/simple`). Ensure the Node.js process has sufficient read permissions for this directory and its contents. -
No credentials found for realm 'your.example.com:443'
cause The `getCredentials` method could not find a matching entry in the SVN simple auth files for the specified `realm` and `url`, or the format of the auth files is unexpected.fixDouble-check the `realm` and `url` parameters against your actual SVN client configuration and the contents of the simple auth files. The `realm` string in the code must exactly match the realm identifier within the SVN auth file (e.g., `<svn.example.com:443> Subversion Repository`). Ensure the auth files are correctly formatted by SVN itself.
Warnings
- gotcha Subversion 'simple' authentication files store passwords in plaintext. Using this provider exposes these credentials in memory, and the files themselves are vulnerable if the system is compromised. Ensure appropriate file system permissions and secure handling of credentials.
- breaking The package requires Node.js version 16.20.2 or higher. Older Node.js versions are not supported and may lead to runtime errors or unexpected behavior.
Install
-
npm install svn-simple-auth-provider -
yarn add svn-simple-auth-provider -
pnpm add svn-simple-auth-provider
Imports
- SvnSimpleAuthProvider
const SvnSimpleAuthProvider = require('svn-simple-auth-provider').SvnSimpleAuthProvider;import { SvnSimpleAuthProvider } from 'svn-simple-auth-provider'; - Credential
import type { Credential } from 'svn-simple-auth-provider';
Quickstart
import { SvnSimpleAuthProvider } from 'svn-simple-auth-provider';
import path from 'path';
import os from 'os';
async function getSvnCredentials() {
// Define a dummy realm directory for demonstration. In a real scenario,
// this would be the actual SVN auth directory, e.g., ~/.subversion/auth/simple.
// For a quick test, you might point it to a directory with a dummy auth file.
const realmDirectory = path.join(os.homedir(), '.subversion', 'auth', 'simple');
const provider = new SvnSimpleAuthProvider({
realmDirectory: realmDirectory
});
// Example: Attempt to retrieve credentials for a specific realm and URL.
// Replace with actual realm and URL from your SVN configuration.
const exampleRealm = 'svn.example.com:443'; // The realm as it appears in the auth file
const exampleUrl = 'https://svn.example.com/repo/trunk'; // The URL used to identify the realm
try {
console.log(`Attempting to retrieve credentials for realm '${exampleRealm}' from ${realmDirectory}...`);
const credentials = await provider.getCredentials(exampleRealm, exampleUrl);
if (credentials) {
console.log('Credentials found:');
console.log(` Username: ${credentials.username}`);
console.log(` Password: ${credentials.password ? '[HIDDEN]' : 'N/A'}`);
// Note: passwords are typically stored in plain text in simple auth files.
} else {
console.log(`No credentials found for realm '${exampleRealm}'.`);
}
} catch (error) {
console.error('Failed to retrieve SVN credentials:', error);
if (error instanceof Error && error.message.includes('ENOENT')) {
console.error('Make sure the realmDirectory path is correct and the auth files exist.');
}
}
}
getSvnCredentials();