CodingSaves ~1.5 hours
Implement JWT authentication middleware
Implement secure, production-ready JWT authentication with proper validation and refresh rotation.
The prompt
You are a security engineer implementing authentication. Write JWT authentication middleware for [FRAMEWORK] in [LANGUAGE]. The middleware must: extract the JWT from the Authorization header (Bearer scheme), verify the signature using the correct algorithm (RS256 preferred over HS256 — explain why), validate standard claims (exp, iss, aud), attach the decoded user payload to the request context, return 401 with specific error messages for expired vs invalid vs missing tokens, handle refresh token rotation (issue new access + refresh tokens), and never log the token value. Include the token generation code for login endpoints and the complete middleware. JWT library: [LIBRARY e.g. jsonwebtoken / PyJWT / golang-jwt] Access token TTL: [e.g. 15 minutes] Refresh token TTL: [e.g. 7 days]
Replace the [BRACKETED] fields with your details, then paste into ChatGPT, Claude or Gemini.
Want AI to fill this in for you?
Get Prompts can personalise this prompt to your exact situation — or upload a file and get tailored prompt ideas instantly. 3 free edits, no sign-up.
Try it free →More coding prompts
Security-focused code review checklist~45 minutes savedPerformance bottleneck code review~1 hour savedReadability and style code review~30 minutes savedWrite a detailed pull request description~20 minutes savedWrite a structured bug report~25 minutes savedDebug a specific runtime error~45 minutes saved