Verify user identity
Turn on Identity verification in an environment's settings when flags are targeted at signed-in users. In SDK keys, issue an identity secret for the browser client key. Copy it to your backend's secret store when the panel displays it.
Sign on the backend
Sign the user ID from the authenticated session. Return the ID and its signature to your frontend. The signing secret stays on the backend.
import { signIdentity } from '@dipswitch/sdk-node'
export function browserIdentity(authenticatedUserId: string) {
const secret = process.env.DIPSWITCH_IDENTITY_SECRET
if (!secret) throw new Error('Set DIPSWITCH_IDENTITY_SECRET')
return { id: authenticatedUserId, signature: signIdentity(authenticatedUserId, secret) }
}
The signature is the hexadecimal HMAC-SHA256 of the UTF-8 user ID. Use the full identity secret as a UTF-8 string if your backend signs in another language.
Pass the signature to the browser SDK
JavaScript, Vue and React take the proof in the signature option. Pass a fresh proof with each new signed-in user. Sign-out still reads anonymous flags.
import { createClient } from '@dipswitch/sdk-js'
type Identity = { id: string; signature: string }
export function start(clientKey: string, first: Identity) {
const flags = createClient({ clientKey, user: { id: first.id }, signature: first.signature })
return {
flags,
identify: (next: Identity) => flags.identify({ id: next.id }, next.signature),
signOut: () => flags.identify(undefined),
}
}
Missing or rejected proofs use your flag defaults. When you replace an identity secret, issue new signatures from the backend for that key. Server keys and anonymous evaluations can continue without a signature. For OFREP, send the signature in X-Dipswitch-Signature with the public client key.