Pen Settings



CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource


Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource


Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.


Auto Save

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.



  <title>Creating Json Web Token (JWT) with Javascript</title>

<body class="p-2">
  <div class="flex flex-row">
    <div style="width: 25%;">
      <h2 class="p-1 text-lg font-bold border-b border-gray-100">Token properties</h2>
      <p class="p-2">
        You can find more info about Json Web Tokens at <a href="" targer="_blank"></a>.
      <form class="m-4">
        <div class="space-y-4">
            <label for="iss" class="block font-medium">iss (issuer)</label>
            <input type="text" name="iss" id="iss" class="block rounded ring-1 ring-inset ring-gray-300 p-1" placeholder="iss (issuer)">
            <label for="sub" class="block font-medium">sub (subject)</label>
            <input type="text" name="sub" id="sub" class="block rounded ring-1 ring-inset ring-gray-300 p-1" placeholder="sub (subject)">
            <label for="secret" class="block font-medium">secret (not base64 encoded)</label>
            <input type="text" name="secret" id="secret" class="block rounded ring-1 ring-inset ring-gray-300 p-1" placeholder="secret (not base64 encoded)">
        <div class="mt-4">
          <button type="button" id="create-token-btn" class="rounded-md bg-indigo-600 px-3 py-2 text-sm font-semibold text-white shadow-sm hover:bg-indigo-500 focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-indigo-600">Create token</button>
    <div style="width: 75%;">
      <h2 class="p-1 text-lg font-bold border-b border-gray-100">Token</h2>
      <p class="p-2">Toke will appare here.</p>
      <div class="p-2 italic" id="token-placeholder"></div>





                import * as jose from "";

document.querySelector("#create-token-btn").addEventListener("click", (event) => {
  ).then((token) => {
    document.querySelector('#token-placeholder').innerHTML = token;

async function createJsonWebToken(iss, sub, secret) {
  const header = {
    alg: "HS256",// Token generation algorithm
    typ: "JWT"

  const payload = {
    iss: iss,
    sub: sub,
    exp: Math.round( / 1000) + 60 // token is valid for 60 seconds

  return await new jose.SignJWT(payload)
    .sign(new TextEncoder().encode(secret));