Secure identification
Sign user identities on your server with HMAC-SHA256 so Encatch can trust who a user is, in the Web and Mobile SDKs and in shareable links
Secure identification proves that a user identity came from your server. Your server signs the user's identifier with a secret only it knows, and the signature travels with the identity — in an SDK identifyUser call or in a shareable link. Encatch checks the signature before it trusts the identity.
It is optional, and we recommend it for production.
Keep the secret on your server
Compute signatures on your server only. Never put a secret key in browser code, a mobile app, HTML, or a link, and never commit it to source control.
Why sign identities
A publishable SDK key is designed to be public, and a shareable link can be read or edited by anyone who has it. Without a signature, anyone with either one can claim to be any user, for example by calling identifyUser('someone-else@example.com') from the browser console, or by changing contact_id in a link.
With secure identification turned on, Encatch accepts an identity only when its signature matches, so responses, traits and targeting are attributed to the real user.
Signatures apply only to identified users. Anonymous visitors (users you never identify, or a link without contact_id or contact_email) are not signed.
Where the secret lives
Each place you identify users has its own secret. Use the secret that belongs to where the identity is used.
| Used in | Secret key and session time | Set up in |
|---|---|---|
| Web and Mobile SDKs | On the publishable SDK key → Security Configuration → Secret key and Session time (minutes) | Publishable SDK Keys |
| Shareable links | On the link → Security Configuration → secret key and Session Time (Minutes) | Feedback Links |
A signature made with an SDK key's secret does not verify a shareable link, and the other way round.
Two ways to sign
How you sign depends on the session time set next to the secret. Session time is optional: it only limits how long a signature stays valid. It is not related to SDK sessions (startSession() and the session ping), which work the same with or without it.
| Session time | What your server signs | What you send |
|---|---|---|
| 0 (off, the default) | The identifier | The signature |
| More than 0 | The identifier followed by the current time | The signature and the same time |
In both cases the signature is the hex-encoded HMAC-SHA256 of that value, using the secret as the key:
Signature only: HMAC-SHA256(identifier, secretKey) → hex
With session time: HMAC-SHA256(identifier + timestamp, secretKey) → hex- Timestamp: milliseconds since the Unix epoch, as a 13-digit string (for example
1741867200000). Send exactly the string you signed. - Session window: with a session time set, a signature is valid for that many minutes. After that, sign again. Without a session time, a signature has no time limit.
- Clock skew: your server's clock must be within 5 minutes of real time. Keep it synced (for example with NTP).
Session time applies wherever it is set, to every SDK and to shareable links.
What to sign
| Used in | Identifier to sign |
|---|---|
| Web and Mobile SDKs | The userName you pass to identifyUser |
| Shareable links | The contact_id value, or the contact_email value when email is the only identifier |
Sign the identifier exactly as you send it: same case, no added spaces. For a link, sign the raw value, not its URL-encoded form.
Sign on your server
Each example returns the signature and, when you use a session time, the timestamp to send with it.
import crypto from 'node:crypto';
// withTime: true when the key or link has a session time above 0.
export function signEncatchIdentity(identifier, secretKey, withTime) {
const time = withTime ? String(Date.now()) : undefined;
const message = withTime ? identifier + time : identifier;
const signature = crypto
.createHmac('sha256', secretKey)
.update(message)
.digest('hex');
return { signature, time };
}Give your app a fresh signature
Apps usually get the signature from an endpoint on your backend, called after the user signs in. Only return a signature for the user who is signed in:
// Express example. requireAuth sets req.user for a signed-in user.
app.get('/encatch/signature', requireAuth, (req, res) => {
const userName = req.user.email;
const { signature, time } = signEncatchIdentity(
userName,
process.env.ENCATCH_SECRET_KEY,
true, // the key has a session time
);
res.json({ userName, signature, time });
});Send the signature
In the SDKs
Pass the signature, and the timestamp when you use a session time, in the secure option of identifyUser. The timestamp field is spelled differently in some SDKs:
| SDK | Where it goes | Timestamp field |
|---|---|---|
| JavaScript Web | identifyUser(userName, traits, { secure: { signature, generatedDateTimeinUTC } }) | generatedDateTimeinUTC |
| React Native (1.4.4+) | identifyUser(userName, traits, { secure: { signature, generatedDateTimeinUTC } }) | generatedDateTimeinUTC |
| Flutter (1.2.0+ for session time) | IdentifyOptions(secure: SecureOptions(signature: …, generatedDateTimeinUTC: …)) | generatedDateTimeinUTC |
| Android | IdentifyOptions(secure = SecureOptions(signature = …, generatedDateTimeInUtc = …)) | generatedDateTimeInUtc |
| iOS | IdentifyOptions(secure: SecureOptions(signature: …, generatedDateTimeInUtc: …)) | generatedDateTimeInUtc |
| Kotlin Multiplatform | IdentifyOptions(secure = SecureOptions(signature = …, generatedDateTimeInUtc = …)) | generatedDateTimeInUtc |
| Compose Multiplatform | IdentifyOptions(secure = SecureOptions(signature = …, generatedDateTimeInUtc = …)) | generatedDateTimeInUtc |
For example, in the Web SDK:
const { userName, signature, time } = await fetch('/encatch/signature').then((r) => r.json());
_encatch.identifyUser(userName, undefined, {
secure: {
signature,
generatedDateTimeinUTC: time, // leave out when the key has no session time
},
});After a successful secure identify, the SDK sends the signature with every request for that user. A later identifyUser replaces it, an identifyUser without secure removes it, and so do resetUser() and identifying another user.
In shareable links
Add the signature as contact_signature, and the timestamp as contact_signature_time when the link has a session time:
const contactId = 'customer_123';
const { signature, time } = signEncatchIdentity(contactId, process.env.ENCATCH_LINK_SECRET, true);
const link = new URL('https://form.encatch.com/<shareable-link-id>');
link.searchParams.set('contact_id', contactId);
link.searchParams.set('contact_signature', signature);
link.searchParams.set('contact_signature_time', time);A signature needs contact_id or contact_email in the same link; without one it is ignored. See User Identification for all contact_ parameters.
Links that require signatures can't be used for email survey export, because each recipient needs their own signature. Generate signed links on your server, one per recipient.
When a signature expires
With a session time set, a signature stops being valid once its session window has passed.
In the SDKs, requests for that user are no longer accepted until you identify again with a fresh signature. The SDK calls onSignatureExpired so your app can fetch a new signature and identify again:
_encatch.init('your-publishable-sdk-key', {
onSignatureExpired: async (info) => {
const { signature, time } = await fetch('/encatch/signature').then((r) => r.json());
_encatch.identifyUser(info.userName, undefined, {
secure: { signature, generatedDateTimeinUTC: time },
});
},
});The callback's exact signature differs per platform — see each SDK page. To avoid running into expiry, fetch a fresh signature and identify on every app launch or page load.
In shareable links, the signature in the link stops verifying when its session window passes. Generate signed links close to when you send them, not far in advance, and choose a session time long enough for recipients to open the link.
Use case: time-limited feedback links
Session time on a feedback link is also a simple way to time-limit a known user's submission. Each recipient gets a personal, signed link, and because the signature stops verifying once its session window passes, they can submit as themselves only within that window.
Typical uses:
- Support follow-up: send a satisfaction survey when a ticket closes, valid for 24 hours (session time
1440). - Event or webinar feedback: collect answers while the experience is fresh, for example within 2 hours (
120). - Post-purchase or onboarding check-ins: ask about a specific order or milestone, only around the time it happened.
To set it up:
- On the link's Security Configuration, generate a secret key and set Session Time (Minutes) to the window you want.
- When you send the link, sign the recipient's
contact_id(orcontact_email) with the current time on your server, and addcontact_signatureandcontact_signature_timeto the link, as shown in In shareable links. - Generate the link at the moment you send it — the window starts from the time you signed.
What a signature doesn't cover
A signature verifies the identifier only.
- SDKs: traits passed to
identifyUserorsetUserPropertiesare not signed. - Shareable links: other
contact_traits andresponse_values are not signed, and anyone with the link can change them.
Don't rely on signed identities to protect traits or answers, and never put secrets or sensitive data in a link.
Troubleshooting
If a signed identity is rejected, check these common causes:
| Symptom | Cause | Fix |
|---|---|---|
| Every signature fails | Signing with the wrong secret, for example the SDK key's secret for a link | Use the secret from where the identity is used — see Where the secret lives |
| Every signature fails | Base64 output instead of hex | Encode the HMAC digest as lowercase hex |
| Every signature fails | Signed value differs from the sent value: extra spaces, different case, or the URL-encoded email | Sign exactly the identifier you send |
| Fails only with a session time | Timestamp in seconds (10 digits) instead of milliseconds (13 digits) | Use milliseconds since the Unix epoch |
| Fails only with a session time | The timestamp sent differs from the one signed | Send the same string you signed |
| Fails only with a session time | Server clock more than 5 minutes off | Sync your server clock |
| Works, then stops after a while | The session window passed | Sign again and identify again, or regenerate the link |
| Fails on an old SDK version | React Native before 1.4.4, or Flutter before 1.2.0 with a session time | Upgrade the SDK |
When sharing logs with support, redact X-Api-Key and X-User-Signature headers.
Related
- Publishable SDK Keys — create the SDK secret and session time
- Feedback Links — create a link's secret and session time
- User Identification — identify respondents in shareable links
- JavaScript Web SDK · Mobile & Native SDKs
Was this page helpful?
