- Home
- Skills
- APIs & Backend
- Freebies — Basic Jwt Auth Generator
Works with the AI Agents you already use
Freebies — Basic Jwt Auth Generator
Implement secure JWT issuance and verification middleware with automated environment variable enforcement.
Free
Freebies — Basic Jwt Auth Generator
Example session with this skill installed
Implement JWT signing and a verification middleware for my API. Use a 15-minute expiration and make sure it pulls the secret from an environment variable.
- Read your context and instructions
- Compiled the freebies
I have generated the JWT authentication logic, including a signing utility and a verification middleware. The implementation uses `JWT_SECRET` from your environment variables and enforces a 15-minute TTL on all issued tokens. ## JWT Authentication Implementation ```javascript const jwt = require('jsonwebtoken'); // 1. Token Signing Logic // Generates a token with sub, iat, and 15m exp claims const signAccessToken = (userId) => { const secret = process.env.JWT_SECRET; if (!secret) { throw new Error('JWT_SECRET environment variable is not defined'); } return jwt.sign({ sub: userId }, secret, { expiresIn: '15m' }); }; // 2. Verification Middleware // Extracts Bearer token and handles signature/expiration errors const authenticateToken = (req, res, next) => { const authHeader = req.headers['authorization']; const token = authHeader && authHeader.split(' ')[1]; if (!token) { return res.status(401).json({ error: 'Access token required' }); } jwt.verify(token, process.env.JWT_SECRET, (err, user) => { if (err) { if (err.name === 'TokenExpiredError') { return res.status(401).json({ error: 'Token expired' }); } if (err.name === 'JsonWebTokenError') { return res.status(403).json({ error: 'Invalid token signature' }); } return res.status(403).json({ error: 'Authentication failed' }); } req.user = user; next(); }); }; module.exports = { signAccessToken, authenticateToken }; ``` **Next steps** 1. Add `JWT_SECRET` to your `.env` file or CI/CD secrets. 2. Apply the `authenticateToken` middleware to your protected routes. 3. Review `references/technical-guide.md` for the full compliance checklist.
Connects securely to your tools. The creator never sees your data.
About this skill
Authentication is frequently a source of security vulnerabilities when implemented from scratch. This skill provides a deterministic path to implementing JWT issuance and middleware, ensuring you follow standard security practices without hardcoding sensitive data. ## What it does - **Token Signing**: Implements logic for signing tokens with `sub`, `iat`, and `exp` claims using a 15-minute TTL. - **Middleware Generation**: Creates verification logic to protect routes by validating token signatures. - **Header Extraction**: Handles the extraction of Bearer tokens from incoming `Authorization` HTTP headers. - **Error Handling**: Standardizes responses for common failures like `TokenExpiredError` and `JsonWebTokenError`. - **Environment Security**: Enforces the retrieval of secrets from dynamic environment variables. ## How it works 1. **Key Setup**: The agent identifies your environment variable configuration to locate `JWT_SECRET`. 2. **Logic Generation**: It generates the signing function with the required standard claims. 3. **Middleware Insertion**: It writes or updates the middleware to intercept requests and verify the Bearer token. 4. **Validation**: It adds catch blocks for expired or malformed signatures to prevent silent failures or crashes. ## Frameworks & tools This skill is designed for backend environments requiring JWT implementations, specifically those using environment variable management through `os.environ` or `runtime_config_env`. ## Why this beats prompting it yourself Generic prompts often lead to hardcoded secrets or missing expiration checks. This skill enforces a strict security workflow that mandates environment variables and standardizes claim structures, preventing common architectural oversights. ## Use cases - Secure an API endpoint with a 15-minute rotating Bearer token. - Implement a verification middleware for a microservice. - Add standard JWT error handling to an existing auth controller. - Standardize token claims across multiple internal backend services. ## Known limitations This skill focuses on basic JWT issuance and does not support OAuth2 PKCE flows or Redis-backed rate limiting without upgrading.
Strictly limited to workspace file operations. Does not handle global package installations or root-level system configurations. Requires pre-configured JWT_SECRET environment variable.
How to use
- 1
Connect your agent to the Agensi MCP
Copy the prompt and paste it into Claude, ChatGPT, Cursor or any agent that supports MCP. It sets up the connection for you. Manual setup
- 2
Sign in to Agensi
Your agent shows a sign-in link. Sign in and click Allow.
- 3
Ask for what you need
Your agent loads this skill and uses it on your task. It always asks before any payment.
Reviews
No reviews yet
Be one of the first to try it. Every listed skill goes through the trust checks below.
Security scanned
Checked by our 8-point scan before listing
Fresh listing
Recently published to Agensi
Free forever
No account required to browse
Trust & safety
Security scan
Security scan passed 3 days ago
- Free with an Agensi account
Requires
Permissions
Target Use Cases: - Generate JWT signing and verification middleware in Node.js. - Implement Bearer token authentication in Express. - Create a secure JWT authentication middleware.