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
- In the console open Settings → Channels → Web widget and click Identity on your widget.
- 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. - Choose the Enforcement mode:
| Mode | Valid signature | No signature | Invalid or expired signature |
|---|---|---|---|
| Off | Signature ignored → unverified | unverified | Signature ignored → unverified |
| Optional | verified | unverified (display only) | rejected (everything discarded) |
| Required | verified | rejected | rejected |
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
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.
userIdmust 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
expwhen you render the page, for example now + 1 hour — never hard-code it.expmay be at most 90 days in the future; 60 seconds of clock skew is tolerated. After it expires the signature isrejectedand 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:
| Input | Value |
|---|---|
| secret | 3f9a0c1e5b7d2f4a6c8e0b1d3f5a7c9e1b3d5f7a9c0e2b4d6f8a0c2e4b6d8f0a |
| userId | u_123 |
| exp | 1767225600 |
| message | u_123:1767225600 |
| userHash | c5e83d194c49d11d209ce99ecb648f6bd059160b173616a2d91c98dd9f60aae8 |
userHash without exp (message u_123) | 6ae76d049b0f5d7a6607df7ee8bd2a23800e1e1f9bbc5174632589c57355f519 |
3. Pass the identity to the widget
Render the values into the page on the server:
<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():
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 theexpyou signed differs from theexppassed to the widget. expis in the past or more than 90 days ahead, or your server clock is off by more than 60 seconds.userIdhas 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]
