HMAC identity verification
HMAC Identity Verification ensures every user tracked by the platform comes from an authenticated, trusted source. When enabled, the system enforces HMAC validation on all identify calls, blocking tracking of spoofed or unidentified users.
When to use it
Section titled “When to use it”- To guarantee trust in user data across analytics and feature management.
- To prevent spoofing, where someone impersonates a user by sending fake events.
- To comply with security and privacy policies for verified user tracking.
How it works
Section titled “How it works”- An admin generates a secret key in the Identity Verification settings.
- Developers use the secret to generate an HMAC-SHA256 hash of the user ID (usually
userIdor email), server-side. - The client SDK sends both the
userIdand theuserHashwith each identify call. - The platform validates the hash against the secret:
- If valid, the user is tracked.
- If invalid or missing, the user is rejected and not tracked.
sequenceDiagram
participant A as Admin
participant B as Your Backend
participant C as Client SDK
participant F as Foldspace
A->>B: Share secret key (from Settings)
Note over B: Secret stays server-side
B->>B: HMAC-SHA256(userId, secret)
B->>C: userId + userHash
C->>F: identify(userId, userHash)
F->>F: Recompute HMAC & compare
alt Hash matches
F-->>C: User tracked ✓
else Hash invalid or missing
F-->>C: User rejected ✗
end
Enable Identity Verification
Section titled “Enable Identity Verification”- Go to Settings → Identity Verification.
- Click Generate to create a new secret.
- Copy the secret and store it securely (for example, in a key vault).
- Share the secret with your development team to implement hashing.
- Toggle Enforce Identity Verification to ON.
- Save your changes.
Parameters
Section titled “Parameters”| Field | Description |
|---|---|
userId | Unique identifier of the user (e.g., UUID, email, database ID). |
userHash | HMAC-SHA256 hash of userId, signed with the secret. Must be computed server-side. |
Generate the user hash
Section titled “Generate the user hash”After enabling HMAC, update your identify calls to include userHash. The userHash is an HMAC-SHA256 hash of the userId, signed with the shared secret from the admin.
const crypto = require("crypto");
function generateUserHash(secret, userId) { return crypto.createHmac("sha256", secret).update(userId).digest("hex");}
const userId = "user_123";const secret = process.env.FOLDSPACE_SECRET;const userHash = generateUserHash(secret, userId);
// Pass to the SDKfoldspaceClient.identify({ userId, userHash});import hmacimport hashlib
def generate_user_hash(secret, user_id): return hmac.new( secret.encode("utf-8"), user_id.encode("utf-8"), hashlib.sha256 ).hexdigest()
user_id = "user_123"secret = os.getenv("FOLDSPACE_SECRET")user_hash = generate_user_hash(secret, user_id)
client.identify({ "userId": user_id, "userHash": user_hash})Related
Section titled “Related”- JWT Authentication: protect agent sessions with signed tokens.
- Authentication: API keys and scopes.