
Security News
Attackers Are Hunting High-Impact Node.js Maintainers in a Coordinated Social Engineering Campaign
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.
postgres-entra-auth
Advanced tools
Azure Entra ID authentication extension for PostgreSQL in JavaScript
This package provides seamless Azure Entra ID authentication for JavaScript/Node.js database drivers connecting to Azure Database for PostgreSQL. It supports both Sequelize ORM and the native pg driver with automatic token management and connection pooling.
Install the package:
npm install postgres-entra-auth
Install Sequelize and the pg driver as peer dependencies:
npm install postgres-entra-auth sequelize pg
Install the pg driver as a peer dependency:
npm install postgres-entra-auth pg
The repository includes comprehensive working examples in the samples/ directory:
samples/pg/getting-started/: node-postgres (pg) examplessamples/sequelize/getting-started/: Sequelize ORM examplesConfigure your environment variables first, then run the samples:
# Copy and configure environment (if using .env file)
cp samples/pg/getting-started/.env.example samples/pg/getting-started/.env
# Edit .env with your Azure PostgreSQL server details
# Test pg driver
node samples/pg/getting-started/create-db-connection.js
# Test Sequelize with hook
node samples/sequelize/getting-started/create-db-connection-hook.js
The pg driver integration provides connection support with Azure Entra ID authentication through a dynamic password function.
import { Pool } from 'pg';
import { getPassword } from 'postgres-entra-auth';
const pool = new Pool({
host: process.env.PGHOST,
port: process.env.PGPORT,
database: process.env.PGDATABASE,
user: process.env.PGUSER,
password: getPassword, // Dynamic password function
ssl: { rejectUnauthorized: true },
connectionTimeoutMillis: 10000,
idleTimeoutMillis: 30000,
max: 10, // Maximum pool size
min: 2 // Minimum pool size
});
// Use the pool
const client = await pool.connect();
Sequelize integration uses pg as the backend driver with automatic Entra ID authentication through hooks.
import { Sequelize } from 'sequelize';
import { configureEntraIdAuth } from 'postgres-entra-auth';
const sequelize = new Sequelize({
dialect: 'postgres',
host: process.env.PGHOST,
port: process.env.PGPORT,
database: process.env.PGDATABASE,
dialectOptions: {
ssl: { rejectUnauthorized: true }
},
pool: {
min: 2,
max: 10,
idle: 30000
}
});
// Configure Entra ID authentication
configureEntraIdAuth(sequelize, {
fallbackUsername: 'my-db-user' // Optional fallback username
});
await sequelize.authenticate();
console.log('Connection established successfully.');
DefaultAzureCredential by default) to acquire access tokens from Azure Entra IDAuthentication Errors
# Error: "password authentication failed"
# Solution: Ensure your Azure identity has been granted access to the database
# Run this SQL as a database administrator:
CREATE ROLE "your-user@your-domain.com" WITH LOGIN;
GRANT ALL PRIVILEGES ON DATABASE your_database TO "your-user@your-domain.com";
Connection Timeouts
// Increase connection timeout for slow networks
const pool = new Pool({
host: process.env.PGHOST,
database: process.env.PGDATABASE,
password: getPassword,
connectionTimeoutMillis: 30000 // 30 seconds instead of default
});
# Clone the repository
git clone https://github.com/Azure/postgres-entra-auth.git
cd postgres-entra-auth/javascript
# Install dependencies
npm install
# Run tests
npm test
# Run tests in watch mode
npm run test:watch
# Run tests with coverage
npm run test:coverage
# Lint code
npm run lint
# Fix linting issues
npm run lint:fix
# Format code
npm run format
# Check formatting
npm run format:check
# Run sample applications
npm run samples:pg
npm run samples:sequelize-hook
Run all quality checks locally before pushing:
# Run all checks (install, lint, format, test)
.\scripts\run-javascript-checks.ps1
# Skip npm install if dependencies are already installed
.\scripts\run-javascript-checks.ps1 -SkipInstall
We welcome contributions! Please see CONTRIBUTING.md for guidelines.
git checkout -b feature/amazing-feature).\scripts\run-javascript-checks.ps1)git commit -m 'Add some amazing feature')git push origin feature/amazing-feature)This project is licensed under the MIT License - see the LICENSE file for details.
For support and questions:
FAQs
Azure Entra ID authentication extension for PostgreSQL in JavaScript
We found that postgres-entra-auth demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.