@secureauth/server
v1.0.2
Published
Production-ready PASETO v4 authentication SDK for Node.js with instant token revocation, refresh rotation, and device fingerprinting
Maintainers
Readme
@secureauth/server
SecureAuth server SDK for Node.js. It provides Layer 1 authentication primitives: PASETO v4.public access tokens, Redis-backed refresh rotation, token revocation, Express middleware, rate limiting, and httpOnly refresh-token cookies.
Install
npm install @secureauth/server express cookie-parser ioredisBasic Usage
import express from 'express';
import cookieParser from 'cookie-parser';
import { SecureAuth } from '@secureauth/server';
const app = express();
app.use(express.json());
app.use(cookieParser());
const auth = new SecureAuth({
redis: { url: process.env.REDIS_URL ?? 'redis://localhost:6379' },
keys: {
private: process.env.PASETO_PRIVATE_KEY!,
public: process.env.PASETO_PUBLIC_KEY!,
},
});
app.post('/login', auth.limiters.auth(), async (req, res) => {
const tokens = await auth.issueTokens('user_123', ['user'], req, res);
res.json({ accessToken: tokens.accessToken });
});
app.use('/auth', auth.router());
app.get('/me', auth.verify(), (req, res) => {
res.json({ userId: req.auth!.sub, roles: req.auth!.roles });
});Generate Ed25519 keys with the root workspace keygen script:
npm run keygenRedis Test Modes
Unit tests opt in to ioredis-mock with USE_REDIS_MOCK=true. To exercise the
same code against a real Redis server, start Redis locally and run the server
tests without that variable:
redis-server
npm run test --workspace @secureauth/serverRepository: https://github.com/SecureAuthSystem/SecureAuth
