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

createHeaderPayload(header, payload)

Full Documentation

  • header: the decoded JWT header either in JSON object or a string literal in json format.
  • payload: the decoded JWT payload either in JSON object or a string literal in json format.

Use this to create the header and payload combined by a “.”. Useful for signing functions.

import { createHeaderPayload } from "jwt-authn";

const header = { alg: "RS256" },
const payload = {
  iss: "joe",
  exp: 1300819380,
  "http://example.com/is_root": true,
}

createHeaderPayload(header, payload);

// expected output:
// eyJhbGciOiJSUzI1NiJ9.eyJpc3MiOiJqb2UiLA0KICJleHAiOjEzMDA4MTkzODAsDQogImh0dHA6Ly9leGFtcGxlLmNvbS9pc19yb290Ijp0cnVlfQ.eyJpc3MiOiJqb2UiLA0KICJleHAiOjEzMDA4MTkzODAsDQogImh0dHA6Ly9leGFtcGxlLmNvbS9pc19yb290Ijp0cnVlfQ