How it works
- You create an identity secret for your project in the platform. Only your server knows it.
- When a customer is logged in, your server signs a token (a JSON Web Token) with that secret.
- Your page hands the token to the widget. botBrains checks the signature and the expiry, then identifies the customer from it.
Create the identity secret
Open Identity verification in your project settings and click Generate secret. The platform shows the secret once, together with its Key ID (kid), so store both in your server’s secret store right away. Generating, rotating and deleting the secret needs the permission to manage API keys.Sign a token on your server
Sign the token with HS256, put the key ID in the token header askid, and keep its lifetime short: a few minutes is enough.
PROJECT_ID with your project’s ID, the number in your platform URL.
If your user IDs are shorter than 16 characters, derive a longer one that stays stable, for example
customer-000000042 for the user with ID 42. Never change it afterwards: botBrains recognizes the customer by it across visits and devices.
Each claim in the token replaces the matching value you set in the browser, and the user ID always comes from sub. Fields the token doesn’t carry keep the value you set in the browser and stay unverified, just like custom attributes you pass with user.data.
Pass the token to the widget
Send the token from your server to the page and pass it to the Web SDK withuser.data:
sub. Other fields you set, such as external_attributes, stay unverified.
user.identify also accepts userJwt, but it only runs once the widget has loaded, so the widget’s first request goes out without the token.
Tokens expire after a few minutes, and the widget doesn’t fetch new ones itself. Replace the token before it expires, for example on a timer slightly shorter than the token’s lifetime. In this example, /api/botbrains-token stands for your own endpoint that signs a new token for the logged-in customer:
userJwt at the same moment instead.
When a different customer logs in on the same page, call user.logout before you pass their token. This clears the previous customer’s chat and data from the widget:
user.logout and reset forget it.
On frames that ask visitors to sign in, botBrains identifies the customer from that sign-in and ignores the token.
Use verified fields
Each identified user records which fields botBrains verified. Use them in an audience to limit sensitive procedures to verified customers:Troubleshooting
When a token is invalid, botBrains returns an error and the widget doesn’t identify the customer.Next steps
Identify users
Decide how to identify customers and what your AI agent can do for them
Audiences
Limit procedures to verified customers