Identity verification

Sign visitor identities on your server so nobody can claim to be your customers.

A visitor opens the browser console on your website and types:

window.Assistify.identify({ email: '[email protected]' });

Anyone can claim to be John. So an unsigned identify stays on this browser's own contact: it never reaches the real John or his conversation history. If John later proves that address, the claimant's conversations move to John's contact and leave the claimant's reach.

The catch: an unsigned claim from your genuinely signed-in customer looks exactly like the impostor's. Without a signature the backend must treat both the same way, so your real customer starts on their own contact too, and reaches their history only after proving the email: a sign-in link requested in Webchat, Discord sign-in, the link in a reply email, or a signed identify().

Identity verification spares your signed-in users that step. Your server signs the identity with a secret only it knows, the widget sends the signature, and the backend recomputes it and trusts the identity only if it matches. A trusted identity attaches the browser to the real contact at once, with its full history across devices. A forged signature is ignored at boot and recorded as unverified by identify().

Skip it and conversations still work: identities recorded through identify() or the in-chat form are stored as unverified, and unsigned boot-time identity is ignored. Set up signing as soon as your website has signed-in visitors.

What the signature covers

The signature covers every identifier you send: email, externalId and discordId. Each one is proved, so the backend finds the contact by any of them. A customer who changes their email on your website still reaches their contact through their externalId.

Sign exactly the identifiers you pass in the same call or boot. An identifier sent beside the signature but left out of it makes the signature fail.

The algorithm

message  = "v2\n" + email + "\n" + externalId + "\n" + discordId
userHash = HMAC-SHA256(identitySecret, message)
  • An identifier you do not send is the empty string. Keep all three line breaks.
  • An identifier containing a line break or a carriage return cannot be signed.
  • Sign the exact strings you send: an email is not normalized before the signature is checked.
  • The output is 64 hex characters with no prefix and no base64.

Signatures of a single field

Signatures made before this format, HMAC-SHA256(identitySecret, email || externalId || discordId), are still accepted. They prove only that first non-empty field, and the other identifiers sent beside it are ignored. Switch to the message above to have all of them proved.

Your HMAC secret

The secret is in the dashboard under Settings → Channels → Webchat → Sign-in → Identification methods → Signed-in visitors (HMAC). Reveal it to copy it or to rotate it. Keep it on your server: anyone who holds it can sign identities your backend will trust.

Where to pass the signature

PathSignature carrier
Script tag, at bootdata-user-hash attribute
React, at bootidentity.userHash on <AssistifyScript>
CMS-friendly, at bootwindow.ASSISTIFY_USER.userHash
SDK, at bootidentity.userHash in mount({ identity })
After bootwidget.user.identify({ email, userHash }). Listen for identified to confirm.

Send the identifiers you signed alongside userHash: the hash is the proof, not the identifier.

A verified contact is never downgraded. A signed identity verifies the browser's own contact after an anonymous chat, and moves the browser to the person who signed in when someone else used it before.

Identifying after the chat already started

If a visitor began an anonymous conversation (typed in an email through the in-chat form, sent a few messages) and then signs in to your website, calling widget.user.identify({ email, userHash }) does both:

  1. Records the visitor as HMAC-verified: on the contact the identifiers name when one is verified already, otherwise on this browser's own contact.
  2. Keeps the anonymous transcript with the verified identity: the same conversations and messages.

Listen for identified:

widget.events.on('identified', ({ verified, merged }) => {
  // verified: true  -> userHash matched your workspace's secret
  // merged:   true  -> the call used a contact that already existed
});

When an email recorded as unverified is proved later (the visitor clicks a sign-in link or the link in a reply email, or completes Discord sign-in), the widget emits verified with { verifiedVia, merged }.

To switch between distinct visitors on a shared device, call widget.reset() before identifying as the new user. See Lifecycle.

Code

Each snippet reads the secret from the environment and signs the three identifiers, empty when absent.

const crypto = require('crypto');
 
const message = ['v2', user.email ?? '', user.externalId ?? '', user.discordId ?? ''].join('\n');
 
const userHash = crypto
  .createHmac('sha256', process.env.ASSISTIFY_IDENTITY_SECRET)
  .update(message)
  .digest('hex');

Check your output

Run your implementation once with these fixed inputs and compare:

email:      [email protected]
externalId: user_4821
discordId:  (none)
secret:     8f4f0c2ab19e44deb3a17c2a9c5e6f01d7b8a3549c0e12fd6b80a4de93715c2e
expected:   b04ee0c4a7559aab182bca8dc0fc0e647f2321a42efa262133bb8447d786b259

A different output means one of the usual mistakes: plain SHA-256 instead of HMAC-SHA256, base64 output instead of hex, the secret hex-decoded into bytes instead of used as the literal string, a trailing newline read along with the secret, or the final line break dropped along with the empty discordId.

Rotating the secret

There's one secret per tenant and no overlap window, so rotation is a hard cutover: the instant you rotate, signatures made with the old secret stop matching.

  1. Reveal the secret in the dashboard, rotate it and confirm. The new secret shows in place; the old one is invalid immediately.
  2. Copy the new value to your signing servers and redeploy.

Between the two steps, signatures don't match, so signed identities are ignored at boot and recorded as unverified by identify() until your servers run the new value. Keep the window short by staging the deploy before you rotate. Contacts already verified aren't downgraded; only verification attempted during the gap is affected.

Troubleshooting

Visitor still anonymous. The widget logs a console warning when boot identity arrives without a userHash. Inspect POST /api/widget/boot in the network tab: if userHash is missing from the payload, your templating engine stripped the attribute. Check the spelling: data-user-hash.

Signature there but visitor unverified. The identifiers sent do not match the ones you signed. Sign every identifier you pass in that call, in the order email, externalId, discordId, with an empty string for each one you leave out. A wrong signature at boot gives no signal in the browser: call identify() with the same values and read verified on the identified event.

Worked yesterday, broken today. The secret was rotated. Pull the new value and redeploy.

Use HMAC-SHA256. A plain SHA-256 or HMAC-SHA1 digest never matches the expected value, so the identity is recorded as unverified (or discarded at boot).