Implement Secure JWT Authentication
Implements a complete, secure JWT system with refresh tokens, revocation, CSRF protection and secure storage, with justification for each security choice.
Paste in your AI
Paste this prompt in ChatGPT, Claude or Gemini and customize the variables in brackets.
Tu es un expert en sécurité web et authentification. Aide-moi à implémenter une authentification JWT complète et sécurisée.
Stack backend : [STACK_BACKEND] (ex: Node.js/Express, Python/FastAPI)
Stack frontend : [STACK_FRONTEND]
Base de données : [BASE_DONNEES]
Exigences : [EXIGENCES] (ex: multi-tenant, SSO, 2FA)
Implémente :
- Génération du token : payload, algorithme (RS256 recommandé), durée de vie
- Validation : middleware de vérification avec gestion des erreurs
- Refresh tokens : rotation, stockage sécurisé, révocation
- Stockage côté client : HttpOnly cookies vs localStorage (avec recommandation justifiée)
- Révocation : blacklist ou short-lived tokens, logout
- Protection contre les attaques : CSRF, fixation de session, token theft
- Code complet : handler login, middleware, refresh endpoint
- Tests de sécurité : cas de test pour les vecteurs d'attaque
- Checklist de déploiement : variables d'environnement, rotation des clés
Pour chaque décision, explique le choix de sécurité.
Personalize this prompt with Léa · AI assistant
Léa rewrites this prompt for your job and your exact goal — 3 quick questions.
Why this prompt works
Requesting justification for each security choice produces architectural decision documentation, crucial for audits. The HttpOnly cookies vs localStorage comparison is a recurring poorly answered question: forcing a justified recommendation avoids vague responses. Security tests are often the first forgotten.
Use Cases
Expected Output
A complete JWT implementation with middleware, refresh tokens, revocation, endpoint code, security tests, deployment checklist and choice justifications.
Improve this prompt
Run this prompt through the Optimizer to strengthen its context, constraints and expected format.
Improve this prompt with the OptimizerComments
Be the first to comment on this prompt.
Glossary Terms
📬 Get new prompts every week
Join our newsletter and never miss a prompt.