
Security News
Package Maintainers Call for Improvements to GitHub’s New npm Security Plan
Maintainers back GitHub’s npm security overhaul but raise concerns about CI/CD workflows, enterprise support, and token management.
@pardnchiu/jwt-auth
Advanced tools
A JWT authentication package providing both Access Token and Refresh Token mechanisms, featuring fingerprint recognition, Redis storage, and automatic refresh functionality.
A JWT authentication package providing both Access Token and Refresh Token mechanisms, featuring fingerprint recognition, Redis storage, and automatic refresh functionality.
version Golang can get here
npm install @pardnchiu/jwt-auth
import { JWTAuth } from '@pardnchiu/jwt-auth';
// initialize the JWT instance
await JWTAuth.init({
privateKeyPath: "./keys/private.pem",
publicKeyPath: "./keys/public.pem",
// or paste keys directly:
// privateKey: "-----BEGIN EC PRIVATE KEY-----...",
// publicKey: "-----BEGIN PUBLIC KEY-----...",
accessTokenExpires: 900, // seconds
refreshTokenExpires: 604800, // seconds
// true: domain=domain, samesite=none, secure=true
// false: domain=localhost, samesite=lax, secure=false
isProd: false,
domain: "pardn.io",
// cookie key, default access_token/refresh_id
AccessTokenCookieKey: "access_token",
RefreshTokenCookieKey: "refresh_id",
// store with redis
redis: {
host: "localhost",
port: 6379,
password: "", // optional
db: 0 // optional
},
checkUserExists: async (userId: string): Promise<boolean> => {
// return true if user exists, false otherwise
return true;
}
});
process.on("SIGINT", async () => {
await JWTAuth.close();
process.exit(0);
});
import { Request, Response } from 'express';
import { JWTAuth } from '@pardnchiu/jwt-auth';
async function loginHandler(req: Request, res: Response) {
// after verifying user login info...
const userData = {
id: "user123",
name: "",
email: "john@example.com",
thumbnail: "avatar.jpg",
role: "user",
level: 1,
scope: ["read", "write"]
};
try {
const tokenResult = await JWTAuth.CreateJWT(req, res, userData);
// automatically set in cookies
res.json({
success: true,
token: tokenResult.token,
refresh_id: tokenResult.refresh_id
});
} catch (error) {
res.status(500).json({ error: error.message });
}
}
import { Request, Response } from 'express';
import { JWTAuth } from '@pardnchiu/jwt-auth';
async function protectedHandler(req: Request, res: Response) {
try {
const result = await JWTAuth.VerifyJWT(req, res);
if (typeof result === "number") {
// Authentication failed, result is HTTP status code (401/400)
return res.status(result).json({
error: result === 401 ? "Unauthorized" : "Bad Request"
});
}
// Authentication success, result is user data
res.json({
message: "Protected resource accessed",
user: result
});
} catch (error) {
res.status(500).json({ error: error.message });
}
}
import { Request, Response } from "express";
import { JWTAuth } from "@pardnchiu/jwt-auth";
async function logoutHandler(req: Request, res: Response) {
try {
await JWTAuth.RevokeJWT(req, res);
res.json({
message: "Successfully logged out"
});
} catch (error) {
res.status(500).json({ error: error.message });
}
}
privateKeyPath
/ privateKey
: private key file path or contentpublicKeyPath
/ publicKey
: public key file path or contentaccessTokenExpires
: access token expire timerefreshTokenExpires
: refresh id expire timeisProd
: is production or not (affects cookie setting)domain
: cookie domainredis
: redis connection
host
: redis hostport
: redis portpassword
: redis password (optional)db
: redis db (optional)checkUserExists
: user existence check functionAccessTokenCookieKey
: access token cookie name (default: 'access_token')RefreshTokenCookieKey
: refresh id cookie name (default: 'refresh_id')Authorization: Bearer <token>
X-Device-ID
: Device IDX-Refresh-ID
: Custom Refresh IDThe system automatically generates a new Refresh ID in the following cases:
The new tokens are returned via:
X-New-Access-Token
X-New-Refresh-ID
The VerifyJWT
method returns:
AuthData
object on successful authentication401
: Unauthorized (invalid/expired tokens, user doesn't exist)400
: Bad Request (invalid fingerprint, malformed tokens)Common error scenarios:
FAQs
A JWT authentication package providing both Access Token and Refresh Token mechanisms, featuring fingerprint recognition, Redis storage, and automatic refresh functionality.
The npm package @pardnchiu/jwt-auth receives a total of 79 weekly downloads. As such, @pardnchiu/jwt-auth popularity was classified as not popular.
We found that @pardnchiu/jwt-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
Maintainers back GitHub’s npm security overhaul but raise concerns about CI/CD workflows, enterprise support, and token management.
Product
Socket Firewall is a free tool that blocks malicious packages at install time, giving developers proactive protection against rising supply chain attacks.
Research
Socket uncovers malicious Rust crates impersonating fast_log to steal Solana and Ethereum wallet keys from source code.