Widget Authentication
Secure your embedded chat widget with token-based authentication. ChatterMate supports both public and authenticated access modes to fit your application’s needs.Authentication Modes
ChatterMate offers two authentication modes for your widget:- Optional (Default)
- Required
Public Access Mode
The default mode allows anonymous visitors to start conversations without authentication.How it works:- Token is automatically generated when the widget initializes
- Visitors can chat immediately without signing in
- Email collection is optional (based on chat style settings)
- Conversation history is linked to the generated token
- Public support websites
- Documentation assistants
- General Q&A interfaces
- Lead generation chatbots
How Token Authentication Works
Authenticated mode uses server-to-server token generation. Your backend calls ChatterMate’s/generate-token endpoint with a Widget App API key and the user’s details. ChatterMate creates (or matches) a customer record, then returns a short-lived JWT that the widget uses to start the chat.
You do not sign your own JWTs. ChatterMate issues and signs the token — that’s how it registers the token for revocation and links the conversation to a stored customer. All you provide is your API key and the user’s email/name. (Your
CONVERSATION_SECRET_KEY is an internal server secret and is never used by integrators.)What you need
Create a Widget App (API key)
In the ChatterMate dashboard, open Widget Apps and create an app. Copy the API key — it is shown only once. Treat it as a server-side secret.
Token flow
Generate a token (server-side)
When a signed-in user opens a page with the widget, your backend calls
POST /api/v1/generate-token with your API key and the user’s email and name.Pass the token to the widget
Return the token to your page and set
window.chattermateToken before the widget script loads.Implementation
1. Generate a token on your backend
Call/generate-token with your Widget App API key in the Authorization header. ChatterMate returns a signed token bound to the customer.
customer_email is optional — omit it and ChatterMate creates an anonymous customer. Passing it is what links the conversation to a named customer in the inbox, and if the same email returns later the existing customer (and their history) is reused. customer_name updates the stored name when it changes.Passing extra customer metadata
Passcustom_data to attach arbitrary fields to the customer — for example a student’s name and coaching center for a tutoring app, or an account tier and plan for a SaaS app. ChatterMate stores these on the customer record and shows them to agents in the chat inbox, right alongside the name and email.
custom_data is capped at 20 keys and 4KB serialized. Calling /generate-token again for the same customer merges new keys into what’s already stored — existing keys are overwritten if present in the new call, and any keys you don’t send are left untouched.2. Pass the token to the widget
Setwindow.chattermateToken before the loader script runs:
window.chattermateToken, sends it as a Bearer token, and ChatterMate resolves it back to the stored customer for the whole conversation.
What’s inside the token
You don’t build this yourself — ChatterMate signs it — but for reference the issued token carries:| Field | Description |
|---|---|
sub / customer_id | ChatterMate customer id (derived from the email) |
widget_id | The widget the token is bound to |
customer_email | Email you supplied (stored on the customer) |
customer_name | Name you supplied |
custom_data | Extra fields you supplied (merged into the customer’s stored metadata) |
jti | Token id, used for revocation |
exp | Expiration timestamp |
Security Features
Organization Isolation
Tokens are scoped to your organization. Cross-organization access is prevented.
Signature Verification
All tokens are cryptographically signed and verified on each request.
Widget Binding
Tokens are bound to specific widgets, preventing cross-widget token reuse.
Revocable & Short-Lived
Every token has a JTI and a TTL (60s–24h), so it can be revoked and expires quickly.
Best Practices
-
Token Expiration
- Keep
ttl_secondsshort (default 1 hour); the range is 60s–24h - Request a fresh token per page load or session rather than reusing long-lived ones
- Handle expired-token errors by re-requesting a token
- Keep
-
Secure Generation
- Call
/generate-tokenserver-side only, with the API key in an environment variable - Regenerate the key from Widget Apps if it is ever exposed
- Call
-
Customer Identification
- Always pass
customer_emailso conversations are attributed to a named customer in the inbox - Keep the same email for a returning user so their history and customer record are reused
- Pass
customer_nameto show a friendly name to your agents - Use
custom_datafor context agents need at a glance (e.g. account tier, plan, or in a tutoring app the student’s name and center) — it shows up in the inbox next to the customer’s name and email
- Always pass
Troubleshooting
Widget shows 'Token required' / won't load with a token
Widget shows 'Token required' / won't load with a token
- The agent has
require_token_auth: true, sowindow.chattermateTokenmust be set before the loader script runs - Verify the token isn’t expired (check
expires_at) - Check the browser console for JavaScript errors
Customer / email not showing in the inbox
Customer / email not showing in the inbox
- You must pass
customer_email(and ideallycustomer_name) to/generate-token— a self-signed JWT or a token without an email won’t create a named customer - Reuse the same email for the same user so the existing customer is matched instead of a new one being created
What’s Next?
After configuring authentication:- Set up your widget integration
- Configure chat customization options
- Test with authenticated and anonymous users
Widget Integration
Learn how to integrate the widget into your website