<!DOCTYPE html>
<html lang="fr">
<head>
  <meta charset="UTF-8">
  <title>Générateur JWT (test WhatsApp)</title>
  <script src="https://cdn.jsdelivr.net/npm/jsonwebtoken@9.0.2/index.min.js"></script>
  <script>
    function generateJWT() {
      const ssoid = document.getElementById("ssoid").value;
      const secret = document.getElementById("secret").value;
      const exp = Math.floor(Date.now() / 1000) + 60 * 60; // 1h
      const payload = {
        username: ssoid,
        exp: exp
      };

      const token = window.jwt.sign(payload, secret);
      document.getElementById("output").textContent = token;
      document.getElementById("copyBtn").disabled = false;
    }

    function copyToken() {
      const token = document.getElementById("output").textContent;
      navigator.clipboard.writeText(token).then(() => {
        alert("Token copié dans le presse-papier ✅");
      });
    }
  </script>
</head>
<body>
  <h1>Générateur JWT de test</h1>
  <label>SSOID (username dans token):</label><br>
  <input type="text" id="ssoid" value="admin001" size="30"><br><br>

  <label>Clé secrète :</label><br>
  <input type="text" id="secret" value="secret-key" size="30"><br><br>

  <button onclick="generateJWT()">Générer le token JWT</button>

  <h2>Token :</h2>
  <pre id="output" style="white-space: pre-wrap; background: #f9f9f9; border: 1px solid #ccc; padding: 1rem;"></pre>

  <button id="copyBtn" onclick="copyToken()" disabled>📋 Copier le token</button>
</body>
</html>