Skip to the page
Docs articles

Sign a token on your server

Sign the token that names a signed-in user, in Node.js, Python, Ruby, PHP or Go, and get it to your page.

Last updated

View as Markdown
On this page

Every example signs the same token: HS256, under your identity secret, with the user's sub, email, email_verified: true, optional name, iat, when it was signed, and an exp a day after it. The widget refuses a token signed to last longer than a day. If you sign without a library, read the clock once for both iat and exp, so exp never lands a second past the day.

Set email_verified only once your product has confirmed the address, such as by a link it emailed. Notert treats whoever your token names as the owner of that address, so a token for an address no one proved is refused.

To have the widget and your user's emails speak the language your product shows them, add a language claim: a language tag, such as fr or fr-FR, read as a browser's is, for one of English, German, Spanish, French, Italian, Dutch, Danish, Swedish, Finnish, Norwegian (nb, no or nn), Polish, Portuguese (pt-BR or pt-PT), Russian, Ukrainian or Simplified Chinese (zh, zh-CN). The widget speaks it while it's one of your board's languages, and your default language otherwise. Without the claim, the widget speaks your default language to everyone, so send it if your product shows each user their own. A language Notert doesn't speak is ignored, and the token still works. Each reads the secret from an environment variable, NOTERT_IDENTITY_SECRET, so it never sits in your code.

The token doesn't say what your user pays you. To have your team see each customer's plan, connect your billing instead. See choose an integration.

To have your team see each user's face, add a picture claim: an https address of their photo, a PNG, JPEG, WebP or GIF under 2 MB that anyone can open without signing in. The address is on a host name with a dot, never an IP address or localhost, carries no user name or password, and is up to 2,000 characters; one that isn't is ignored, and the photo Notert already has stays. Notert copies it, so the address may change at any time, and checks it again within a week; send null once they have no photo. If they set a photo on their own Notert account, that one is shown instead. Their photo is never shown on your public board.

To have your team see what your product knows of each user, add a traits object, such as { company: "Acme", seats: 40, admin: true }. Each value is a text up to 255 characters, a number, true or false, or null to clear it; a date is a number of seconds since 1970 or an ISO date, such as "2025-01-31". A key is read in lower case, and must start with a letter and hold only letters, digits and underscores, such as signed_up_at; any other is ignored. Only the traits you've ticked on the Signed-in users tab are kept, and a value of another type than the trait's is ignored. Leave out a trait the user doesn't have rather than sending it empty. A trait your token leaves out keeps its last value.

To have your team see which of your customers' accounts each user belongs to, add a companies list, such as [{ id: "company_456", name: "Acme Corp", domain: "acme.com" }]. Each company has your own id for it, a text or a whole number, and a name, cut at 120 characters, and may have a web domain; one without an id or a name is ignored, and a domain that isn't one is left out. Up to 20 are kept. Each token that sends the list puts the user in exactly the companies it names, so send all of them every time, or [] once they belong to none; a token that leaves the list out changes nothing. A company's name and domain are the ones your latest token gave. Companies are kept while they're ticked on the Signed-in users tab, as the user writes in the widget or signs in on your board, and a company no one belongs to any more goes.

A token with every optional claim, in Node.js:

import { SignJWT } from "jose";

const token = await new SignJWT({
  email: user.email,
  // Leave the claim out rather than sending null.
  ...(user.name ? { name: user.name } : {}),
  // Only once your product has confirmed the address.
  email_verified: true,
  language: user.locale, // such as "fr" or "pt-BR"
  picture: user.avatarUrl ?? null, // null once they have no photo
  traits: {
    company: user.company.name,
    seats: user.company.seats,
    admin: user.isAdmin,
    signed_up_at: Math.floor(user.createdAt.getTime() / 1000),
  },
})
  .setProtectedHeader({ alg: "HS256" })
  .setSubject(String(user.id))
  .setExpirationTime("1d")
  .setIssuedAt()
  .sign(new TextEncoder().encode(process.env.NOTERT_IDENTITY_SECRET));

Decoded, its claims read:

{
  "email": "priya@northwind.example",
  "name": "Priya Shah",
  "email_verified": true,
  "language": "en",
  "picture": "https://cdn.northwind.example/avatars/priya.png",
  "traits": { "company": "Northwind", "seats": 40, "admin": true, "signed_up_at": 1735603200 },
  "sub": "1842",
  "exp": 1763892000,
  "iat": 1763805600
}

Use the secret exactly as Notert shows it, starting nis_, as text. Don't decode it first.

Node.js

With jose:

import { SignJWT } from "jose";

const token = await new SignJWT({
  email: user.email,
  ...(user.name ? { name: user.name } : {}),
  email_verified: true,
})
  .setProtectedHeader({ alg: "HS256" })
  .setSubject(String(user.id))
  // Set the expiry before the issue time: each reads the clock, and the other order can sign a
  // token a second longer than a day, which the widget refuses.
  .setExpirationTime("1d")
  .setIssuedAt()
  .sign(new TextEncoder().encode(process.env.NOTERT_IDENTITY_SECRET));

Python

With PyJWT:

import os
import time

import jwt

now = int(time.time())
claims = {
    "sub": str(user.id),
    "email": user.email,
    "email_verified": True,
    "iat": now,
    "exp": now + 86400,
}
if user.name:
    claims["name"] = user.name

token = jwt.encode(claims, os.environ["NOTERT_IDENTITY_SECRET"], algorithm="HS256")

Ruby

With the jwt gem:

require "jwt"

now = Time.now.to_i
claims = { sub: user.id.to_s, email: user.email, email_verified: true, iat: now, exp: now + 86_400 }
claims[:name] = user.name if user.name

token = JWT.encode(claims, ENV.fetch("NOTERT_IDENTITY_SECRET"), "HS256")

PHP

With firebase/php-jwt:

use Firebase\JWT\JWT;

$now = time();
$claims = [
    'sub' => (string) $user->id,
    'email' => $user->email,
    'email_verified' => true,
    'iat' => $now,
    'exp' => $now + 86400,
];
if ($user->name) {
    $claims['name'] = $user->name;
}

$token = JWT::encode($claims, getenv('NOTERT_IDENTITY_SECRET'), 'HS256');

Go

With golang-jwt:

import (
	"fmt"
	"os"
	"time"

	"github.com/golang-jwt/jwt/v5"
)

now := time.Now()
claims := jwt.MapClaims{
	"sub":            fmt.Sprint(user.ID),
	"email":          user.Email,
	"email_verified": true,
	"iat":            now.Unix(),
	"exp":            now.Add(24 * time.Hour).Unix(),
}
if user.Name != "" {
	claims["name"] = user.Name
}

token, err := jwt.NewWithClaims(jwt.SigningMethodHS256, claims).
	SignedString([]byte(os.Getenv("NOTERT_IDENTITY_SECRET")))

A token for your board

A token that signs people in on your board carries one more claim, aud set to notert:board, and its exp is no more than 10 minutes after its iat. In Node.js:

import { SignJWT } from "jose";

const boardToken = await new SignJWT({
  email: user.email,
  ...(user.name ? { name: user.name } : {}),
  email_verified: true,
})
  .setProtectedHeader({ alg: "HS256" })
  .setSubject(String(user.id))
  .setAudience("notert:board")
  .setExpirationTime("10m")
  .setIssuedAt()
  .sign(new TextEncoder().encode(process.env.NOTERT_IDENTITY_SECRET));

Get it to your page

Either works:

  • Write it into the page your server renders for a signed-in user, then call window.notert.identify(token) in a script on it.
  • Serve it from your API, such as a route that answers the signed-in user's token, and call identify with the answer once your app knows who's signed in.

A route that serves it, in Express, behind your own sign-in:

app.get("/api/notert-token", requireSignedIn, async (req, res) => {
  const token = await signWidgetToken(req.user); // the jose example above
  res.set("Cache-Control", "no-store").json({ token });
});

And the page that asks it, handing the widget a function so it fetches a fresh token before each one expires (see keep the token fresh):

window.notert.identify(async () => {
  const response = await fetch("/api/notert-token", { credentials: "same-origin" });
  if (!response.ok) return null;
  return (await response.json()).token;
});

Cache-Control: no-store keeps a shared cache from handing one user's token to another.

Check a token

Paste a token your server signed into Check a token on the Signed-in users tab: it says whom the widget would know it as, or why it would refuse it, as the widget does. To look at one on your own machine first, decode its claims without checking the signature:

node -e 'const [, claims] = process.argv[1].split("."); console.log(JSON.parse(Buffer.from(claims, "base64url")))' "$TOKEN"

Things that make a token fail

  • No email_verified, or one that isn't true. The token must say your product confirmed the address.
  • sub as a number. It must be a string, so turn a numeric id into text first, as the examples do.
  • name as null. Leave the claim out instead.
  • No exp, or one in the past. A token without an end is refused.
  • No iat, or an exp more than a day after it. A token for the widget lasts a day at most, so one that leaks soon stops working.
  • An iat in the future. Check your server's clock.
  • Another algorithm. Only HS256 is accepted.
  • Another workspace's secret, or one revoked since. See your identity secret.
  • aud set to notert:board. That token is for signing people in on your board, and the widget refuses it.

Start here

Up and down arrowsto moveEnterto openEscto close