
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.
auth-master
Advanced tools
JWT + Basic middleware for Express & Socket.IO (ESM-first with CJS fallback)
ESM-first, class-based JWT & Basic authentication middleware for Express and Socket.IO.
✅ ESM primary · ✅ TypeScript types · ✅ Lightweight
auth-master/
├─ src/
│ ├─ index.ts
│ ├─ types.ts
│ └─ ambient.d.ts
├─ test/
│ └─ index.ts
├─ tsconfig.json
├─ package.json
└─ README.md
npm i auth-master
# peer deps you likely already have in your app:
npm i express jsonwebtoken socket.io
# dev types (recommended for TS users)
npm i -D @types/express @types/jsonwebtoken @types/socket.io
import { AuthMaster } from "auth-master";
// 1) Register your token keys via the constructor (names are fully custom)
const authMaster = new AuthMaster({
userToken: "secret-user-key",
merchantToken: "secret-merchant-key",
systemToken: "secret-system-key",
adminToken: "secret-admin-key",
});
// 2) Create a JWT
const tokenRes = authMaster.create({
data: { user_id: 123, user_role: "admin" },
keyName: "adminToken",
expiresIn: "1h", // or 3600
});
console.log(tokenRes); // { data: string|null, success: boolean, message: string, code: "200"|"500" }
// 3) Express: Protect a route using Bearer token
import express from "express";
const app = express();
app.get(
"/secure",
authMaster.checkTokenBearer(["adminToken", "systemToken"], {
required: true,
}),
(req, res) => {
res.json({ ok: true, user: req.user, role: req.role });
},
);
Need to rotate keys at runtime? Use
authMaster.setKeys({...})at any time.
app.get(
"/basic",
authMaster.checkTokenBasic({ required: true }),
(req, res) => {
res.json({ basic: req.authMaster });
},
);
import { Server } from "socket.io";
import { createServer } from "http";
const server = createServer();
const io = new Server(server, { cors: { origin: "*" } });
io.use(authMaster.checkTokenSocket(["userToken"], { required: true }));
io.on("connection", (socket) => {
socket.emit("hello", { uid: socket.req?.user_id ?? "anonymous" });
});
All exported functions and middleware-produced responses conform to a single shape:
type JsonResp<T = any> = {
data: T | null;
success: boolean;
message: string;
code: string; // HTTP-like code as string: "200", "400", "401", "500", ...
};
create, checker, basic return this shape directly.401) via res.status(...).json(...).new AuthMaster(keys?: Record<string, string>)Registers your JWT secrets by name (the name will be referenced as keyName elsewhere).
const authMaster = new AuthMaster({
userToken: "secret-user-key",
merchantToken: "secret-merchant-key",
systemToken: "secret-system-key",
adminToken: "secret-admin-key",
});
authMaster.setKeys({...}) to replace them at runtime.setKeys(keys: Record<string, string>) => { keys: Record<string, string> }Replaces the current key map at runtime.
authMaster.setKeys({
userToken: "new-user-key",
adminToken: "new-admin-key",
});
create(args: CreateType): JsonResp<string>Create a JWT using one of your registered keys.
Type
interface CreateType {
data: any; // Payload to embed → stored under { data: ... }
keyName: string; // One of the names you registered
expiresIn?: string | number; // e.g. "1h", "2d", or 3600 (seconds)
}
Returns
{ success: true, code: "200", data: "<jwt>", message: "success" }{ success: false, code: "500", data: null, message: "..." }Example
const res = authMaster.create({
data: { user_id: 1, user_role: "admin" },
keyName: "adminToken",
expiresIn: "1h",
});
checker(args: CheckerType): JsonResp<any>Verify a JWT using one of your registered keys.
Type
interface CheckerType {
token: string | null | undefined; // Bearer token string (with or without "Bearer ")
keyName: string; // one of your keys
}
Returns
{ success: true, code: "200", data: <decoded>, message: "success" }{ success: false, code: "401", data: null, message: "<reason>" }Example
const check = authMaster.checker({
token: tokenRes.data!,
keyName: "adminToken",
});
basic(authHeader?: string): JsonResp<{ username: string; password: string }>Decodes Basic authorization header into { username, password }.
Example
const header = "Basic " + Buffer.from("john:secret").toString("base64");
const res = authMaster.basic(header);
// { success: true, code: "200", data: { username: "john", password: "secret" }, message: "success" }
On invalid/missing header, returns success: false with code: "400" or "500".
checkTokenBearer(allowedKeys: string[], options?: { required?: boolean })Express middleware that verifies a Bearer token (header/cookie/query).
Accepted token sources (first match wins):
Authorization: Bearer <token>token?authMasterTokenBearer=<token>If verified:
next()req:
req.tokenUser (the key name that passed)req.token (raw token)req.authMaster (full JWT payload)req._id, req.user_id, req.role, req.user (if present in payload)If not verified:
required: true → res.status(401).json({ data:null, success:false, message:"Unauthorized", code:"401" })next() (let your handler decide)checkTokenBasic(options?: { required?: boolean })Express middleware that parses Basic auth from:
Authorization: Basic <base64>token?authMasterTokenBasic=<Basic ...>Behavior
next() and req.authMaster = { username, password }, req.tokenUser = "basicToken"required: true → 401 JSON (standard shape)next()checkTokenSocket(allowedKeys: string[], options?: { required?: boolean })Socket.IO middleware that verifies a Bearer token from:
socket.handshake.headers.authorizationsocket.handshake.query.Authorizationsocket.handshake.query.authMasterTokenBearerBehavior
socket.req = { ... } with the same fields as the Express variant.required: true → next(new Error("Authentication error: invalid token"))socket.req = { query, headers } and next()Key exported types (from types.ts):
export interface AuthMasterRequest extends Request {
tokenUser?: string;
token?: string;
authMaster?: any;
authMasterSocket?: any;
_id?: any;
user_id?: any;
role?: any;
user?: any;
}
export interface AuthMasterSocket extends Socket {
req?: {
tokenUser?: string;
token?: string;
authMaster?: any;
_id?: any;
user_id?: any;
role?: any;
user?: any;
query?: any;
headers?: any;
};
}
export interface CreateType {
data: any;
keyName: string; // must match a name registered in constructor/setKeys()
expiresIn?: string | number; // "1h", "2d", or seconds
}
export interface CheckerType {
token: string | null | undefined;
keyName: string;
}
export interface ConfigType<T extends string = string> {
keys: Record<T, string>;
}
export type OptionsType = {
required?: boolean;
};
The library also includes an ambient declaration that merges these fields into Express’s
Request, so you get autocompletion onreq.user,req.user_id, etc., without extra imports.
npm run build
dist/index.js, types → dist/index.d.tsISC © TOGTOKH.DEV
FAQs
JWT + Basic middleware for Express & Socket.IO (ESM-first with CJS fallback)
We found that auth-master 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.