← ClaudeAtlas

jwtlisted

JSON Web Tokens for authentication. Covers token structure, signing, and validation. Use for stateless authentication. USE WHEN: user mentions "JWT", "token authentication", "access token", "refresh token", asks about "stateless auth", "token signing", "token validation" DO NOT USE FOR: session-based auth (use session management), OAuth flows (use oauth2 skill), NextAuth.js (use nextauth skill)
claude-dev-suite/claude-dev-suite · ★ 33 · AI & Automation · score 80
Install: claude install-skill claude-dev-suite/claude-dev-suite
# JWT Core Knowledge > **Deep Knowledge**: Use `mcp__documentation__fetch_docs` with technology: `jwt` for comprehensive documentation. ## Token Structure ``` header.payload.signature Header: { "alg": "HS256", "typ": "JWT" } Payload: { "sub": "1234", "name": "John", "iat": 1516239022 } Signature: HMACSHA256(base64(header) + "." + base64(payload), secret) ``` ## Node.js Implementation ```typescript import jwt from 'jsonwebtoken'; const SECRET = process.env.JWT_SECRET!; // Generate token function generateToken(user: User): string { return jwt.sign( { sub: user.id, email: user.email }, SECRET, { expiresIn: '1h' } ); } // Verify token function verifyToken(token: string): JwtPayload { return jwt.verify(token, SECRET) as JwtPayload; } // Refresh token pattern function generateRefreshToken(user: User): string { return jwt.sign( { sub: user.id, type: 'refresh' }, SECRET, { expiresIn: '7d' } ); } ``` ## Middleware ```typescript const authenticate = (req, res, next) => { const authHeader = req.headers.authorization; if (!authHeader?.startsWith('Bearer ')) { return res.status(401).json({ error: 'Missing token' }); } const token = authHeader.split(' ')[1]; try { req.user = verifyToken(token); next(); } catch (err) { res.status(401).json({ error: 'Invalid token' }); } }; ``` ## When NOT to Use This Skill - **Session-based authentication** - Use traditional server-side sessions with cookies - **OAuth 2.0 flows**