less than 1 minute read

npm npm bundle size codesize npm NPM GitHub Sponsors GitHub Repo stars GitHub forks GitHub watchers Rate on Openbase link to npm

jwt-authn

hs256Sign(headerPayload, key)

Full Documentation

  • headerPayload: The combined base64url(header) and base64url(payload) separated by a “.”.
  • key: The signing key or passphrase.
import { hs256Sign, createHeaderPayload } from "jwt-authn";

const decodedHeader = { typ: "JWT", alg: "HS256" };
const decodedPayload = {
  iss: "joe",
  exp: 1300819380,
  "http://example.com/is_root": true,
};
const passphrase =
  "AyM1SysPpbyDfgZld3umj1qzKObwVMkoqQ-EstJQLr_T-1qS0gZH75aKtMN3Yj0iPS4hcgUuTwjAzZr1Z9CAow";

const headerPayload = createHeaderPayload(
  decodedHeader,
  decodedPayload
);

const sig = hs256Sign(headerPayload, passphrase);

// expected output
// "lliDzOlRAdGUCfCHCPx_uisb6ZfZ1LRQa0OJLeYTTpY"