jwt-handler
БесплатноБез исполняемых скриптовНе проверенWhen the user needs to generate, validate, refresh, or debug JSON Web Tokens. Use when the user mentions "JWT," "access token," "refresh token," "token…
от TerminalSkills★ 221 звезда на GitHubОб этом скилле
JWT Handler
Overview
Implements secure JWT token lifecycle for web applications — generation, validation, refresh rotation, revocation, and debugging. Produces code that follows current security best practices including short-lived access tokens, one-time refresh rotation with family tracking, and proper key management.
Instructions
Token Generation
When creating JWT tokens:
- Access token: Short-lived (15 min), contains user ID and roles, signed with RS256 or ES256
- Refresh token: Longer-lived (7-30 days), opaque or JWT, stored hashed in database
- Always use asymmetric signing (RS256/ES256) for production — allows verification without the private key
- Minimal payload: user ID, roles, issued-at, expiration. No PII, no secrets.
// Access token payload — keep it minimal
{
sub: "user_abc123",
roles: ["member"],
iat: 1708185600,
exp: 1708186500 // 15 minutes
}
Refresh Token Rotation
Implement one-time rotation with reuse detection:
- Each refresh token belongs to a "family" (first token in chain)
- On refresh: invalidate old token, issue new access + refresh pair
- If a revoked token is presented → revoke ALL tokens in that family (theft detected)
- Store in database: token_hash, family_id, user_id, expires_at, revoked_at
Token Validation Middleware
1. Extract token from Authorization header (Bearer scheme)
2. Verify signature with the public key, passing an explicit allowlist: jwt.verify(token, publicKey, { algorithms: ['RS256'], issuer: 'app', audience: 'api' })
3. Check expiration (exp claim) — done by jwt.verify; clockTolerance: 30 allows 30 s of drift
4. Check issuer and audience (passed in step 2)
5. Attach decoded payload to request context
6. Return 401 with a specific error, mapped from the library's error name:
- TokenExpiredError → token_expired
- JsonWebTokenError (malformed, bad signature, wrong issuer or audience) → token_invalid
- NotBeforeError → token_invalid
- no Authorization header → token_missing
Key Management
- Generate RSA 2048+ or EC P-256 key pairs
- Store private key in environment variable or secrets manager
- Expose public key via /.well-known/jwks.json endpoint
- Support key rotation: include key ID (kid) in token header (
keyidoption in jsonwebtoken), and look up the public key bykidwhen verifying - Env vars hold PEM text with line breaks; a
.envfile needs\nescapes that the loader must turn back into newlines
Examples
Example 1: Node.js Token Service
Prompt: "Create a JWT token service with refresh rotation for my Express app"
Output:
// token.service.ts
import jwt from 'jsonwebtoken';
import crypto from 'crypto';
export class TokenService {
generateAccessToken(user: User): string {
return jwt.sign(
{ sub: user.id, roles: user.roles },
process.env.JWT_PRIVATE_KEY, // PEM; keep the line breaks (see Key Management)
{ algorithm: 'RS256', expiresIn: '15m', issuer: 'app', audience: 'api', keyid: process.env.JWT_KEY_ID }
);
}
async generateRefreshToken(userId: string, familyId?: string): Promise<string> {
const token = crypto.randomBytes(32).toString('hex');
const hash = crypto.createHash('sha256').update(token).digest('hex');
await db.refreshTokens.create({
tokenHash: hash,
userId,
familyId: familyId || crypto.randomUUID(),
expiresAt: new Date(Date.now() + 7 * 24 * 60 * 60 * 1000),
});
return token;
}
async rotateRefreshToken(oldToken: string) {
const hash = crypto.createHash('sha256').update(oldToken).digest('hex');
const stored = await db.refreshTokens.findByHash(hash);
if (!stored || stored.revokedAt) {
// Reuse detected — revoke entire family
if (stored) await db.refreshTokens.revokeFamily(stored.familyId);
throw new TokenReuseError();
}
await db.refreshTokens.revoke(stored.id);
const newRefresh = await this.generateRefreshToken(stored.userId, stored.familyId);
const user = await db.users.findById(stored.userId);
const newAccess = this.generateAccessToken(user);
return { accessToken: newAccess, refreshToken: newRefresh };
}
}
Example 2: Debug a JWT Token
Prompt: "My API returns token_expired for this JWT, can you decode it? eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCIsImtpZCI6ImtleS0yMDI2LTEwIn0.eyJzdWIiOiJ1c3JfN2YzYTljIiwicm9sZXMiOlsibWVtYmVyIl0sImlhdCI6MTc5MTgwMDAwMCwiZXhwIjoxNzkxODAwOTAwfQ.iQvA-PS2MWDxkpNyTq6bY7NynWud4HHjqUR2Npufl4m-PBZko8-mDia64a09TBJt51_HF7J3Pw3gwk8svIHc81Mqr2YfFU-_4vGYSC7OiMiF3qoJhvFuoe3jwBY3G_y92R6qQxyrBClfe3ec9BaCMwiGR9XTyo9Iwa-7Rse20G3abdyFFnRMdNLB-qwxsyT1tcX5CELmd5Tx184QAa-fD3uYzE7LEvvxzotxwg02eX83vdNpaF62MeAcZtuoC8z_gltwu-wHv1BSBNdwlThFTUX2ToZ09-LZUn_cUApVGa4BBTrOBX6OL2Ko_oGbb52_wmIjQ8T204mgu4OgmL6V-g"
Output:
Decoded JWT (signature not checked here; the public key is needed for that):
Header: { alg: "RS256", typ: "JWT", kid: "key-2026-10" }
Установить jwt-handler в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
Без ограничений — скилл может использовать любой инструмент.
Вложенные файлы
FAQ
Что делает скилл jwt-handler?
When the user needs to generate, validate, refresh, or debug JSON Web Tokens. Use when the user mentions "JWT," "access token," "refresh token," "token rotation," "token expiration," "token validation," "bearer token," or "decode JWT." Handles secure token lifecycle including signing, verification, refresh rotation, and revocation. For full auth system design, see auth-system-setup.
Как установить скилл jwt-handler?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл jwt-handler запускает скрипты?
Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.
Похожие скиллы
mcp-builder
Guide for creating high-quality MCP (Model Context Protocol) servers that enable LLMs to interact with external services through well-designed tools. Use when…
от Anthropicclaude-api
Reference for the Claude API / Anthropic SDK — model ids, pricing, params, streaming, tool use, MCP, agents, caching, token counting, model migration. TRIGGER…
от Anthropicalgorithmic-art
Creating algorithmic art using p5.js with seeded randomness and interactive parameter exploration. Use this when users request creating art using code…
от Anthropicmcp-integration
This skill should be used when the user asks to "add MCP server", "integrate MCP", "configure MCP in plugin", "use .mcp.json", "set up Model Context…
от Anthropic