15-day Pro trial · no credit cardStart free →

Web JS SDK

Identity verification

Identify logged-in users in the web widget and sign them with HMAC-SHA256 on your server. Samples for Node.js, Python, PHP, Go and Java.

Tell the widget who your logged-in user is so agents see their name and email, and — with a server-side signature — so the same customer gets the same conversation history on every device.

Unsigned vs. signed claims

Unsigned claim — pass userId (and optionally name / email) without userHash. The values are shown to agents as display attributes only (identityStatus = unverified). They are never used to merge conversations across devices or to load history, because anyone can fake them in a browser. If verification is set to Required, unsigned claims are ignored (rejected).

Signed claim (recommended) — your server computes userHash with a secret key that only it knows. A valid signature gives identityStatus = verified, and the same userId shares conversation history across devices. The name and email you pass are still display-only: they are not covered by the signature and are never used to match identities.

1. Turn on verification

  1. In the console open Settings → Channels → Web widget and click Identity on your widget.
  2. Click Generate secret. The secret is a 64-character hex string; store it in your server's secret store (for example an environment variable STINGIM_IDENTITY_SECRET). Each widget has its own secret.
  3. Choose the Enforcement mode:
ModeValid signatureNo signatureInvalid or expired signature
OffSignature ignored → unverifiedunverifiedSignature ignored → unverified
Optionalverifiedunverified (display only)rejected (everything discarded)
Requiredverifiedrejectedrejected

rejected visitors are treated as anonymous. Rotate secret replaces the key; signatures made with the old key stop verifying.

2. Compute the signature on your server

Text
user_hash = lowercase_hex( HMAC-SHA256( key = the secret string itself (UTF-8 bytes), message ) )
message   = userId                  (no expiry)
          | userId + ":" + exp      (exp = Unix time in seconds; pass the same exp to the widget)
  • Use the secret as text. Do not hex-decode it.
  • userId must be 1–255 characters with no control characters and no leading or trailing spaces (the widget trims it before sending). Sign exactly the string you pass to the widget.
  • Prefer an expiring signature. Compute exp when you render the page, for example now + 1 hour — never hard-code it. exp may be at most 90 days in the future; 60 seconds of clock skew is tolerated. After it expires the signature is rejected and the visitor becomes anonymous.
// Node.js 18+
const crypto = require('node:crypto');

function signStingimUser(userId, ttlSeconds = 3600) {
  const exp = Math.floor(Date.now() / 1000) + ttlSeconds;
  const userHash = crypto
    .createHmac('sha256', process.env.STINGIM_IDENTITY_SECRET) // the secret string, not hex-decoded
    .update(`${userId}:${exp}`, 'utf8')
    .digest('hex');
  return { userId, userHash, exp };
}

For a non-expiring signature, sign userId alone and omit exp.

Test vector

Use this to check your implementation:

InputValue
secret3f9a0c1e5b7d2f4a6c8e0b1d3f5a7c9e1b3d5f7a9c0e2b4d6f8a0c2e4b6d8f0a
userIdu_123
exp1767225600
messageu_123:1767225600
userHashc5e83d194c49d11d209ce99ecb648f6bd059160b173616a2d91c98dd9f60aae8
userHash without exp (message u_123)6ae76d049b0f5d7a6607df7ee8bd2a23800e1e1f9bbc5174632589c57355f519

3. Pass the identity to the widget

Render the values into the page on the server:

HTML
<script>
  window.stingImSettings = Object.assign(window.stingImSettings || {}, {
    user: { userId: 'u_123', userHash: '<%= userHash %>', exp: <%= exp %>, name: 'Jane', email: '[email protected]' },
  });
</script>

Or, in a single-page app, fetch them from your backend after login and call identify():

JavaScript
const { userId, userHash, exp } = await fetch('/api/me/stingim-identity').then((r) => r.json());
await window.stingIm.identify({ userId, userHash, exp, name: me.name, email: me.email });

When the user signs out, call logout().

Troubleshooting

When a userHash was provided but the verdict is rejected, the browser console shows [stingim] identify(): userHash was rejected …. Common causes:

  • Wrong secret — each widget has its own, and rotating the secret invalidates old signatures.
  • The secret was hex-decoded before use. Use the string as-is.
  • The message is missing :exp, or the exp you signed differs from the exp passed to the widget.
  • exp is in the past or more than 90 days ahead, or your server clock is off by more than 60 seconds.
  • userId has surrounding spaces or differs from the signed value.

If a userHash was provided but the verdict is unverified, verification is Off for this widget and the signature was ignored.

Never put the identity secret in browser code, a mobile app or a public repository. Anyone with it can sign in as any of your users in the chat.

The mobile SDKs use the same signature scheme — see Android and iOS.

Found a mistake? Email [email protected]