Skip to main content

The problem

Your public key (mq_live_…) sits in your web page. Anyone can copy it and send track calls that name any userId. That can change a person’s profile or start a journey that emails them.

The fix

Your server signs a short-lived token that says “this call is for u_42”. Maqetin checks the signature before it accepts a call that names that user. Only your server holds the private key, so only your server can make a valid token.

Set it up

1

Create a signing key

In the console, open Developers, then Identity tokens, and choose Create signing key. Only the owner can.Copy the private key now. Maqetin keeps only the public half and cannot show the private key again. Store it in your server’s secrets, never in a web page.
2

Sign a token on your server

Sign one for each signed-in person, and give it to your page. Any JWT library that signs ES256 works. The private key is the PEM you copied, and kid is the key id shown in the console.
3

Send it with the call

The call carries the token in the Maqetin-Identity-Token header. The SDK does it for you.
The SDK’s token options need a version of @maqetin/sdk-js newer than 0.2.0. See Identity token.
4

Turn it on

Open Developers, then Identity tokens. Under Identity check, pick a mode and choose Save mode.

Modes

A workspace that has not chosen a mode is in Required mode. Only the owner changes the mode, and choosing Required asks for a confirmation. Roll it out in order: create a key, set Optional, start sending tokens, then set Required once every call carries one.

What the token holds

Every userId in the call must equal sub. Calls that carry only an anonymousId need no token, and neither does a secret key sending to /v1/batch. An hour is a good lifetime.

If a call is refused

A refused token is a 401 whose body names the reason, for example { "error": "token_expired" }. In Optional mode none of these refuse the call. See Errors for the rest.

Rotate and revoke keys

A workspace has up to three live keys. In the Signing keys list:
  • Rotate makes a new key with the same name. The old one stays live, so deploy the new key first.
  • Revoke stops a key within a minute and cannot be undone. Move your server to another live key first.