Website chatFor admins
Sign your visitors in
Tell the chat who your signed-in user is, with a short identity your back end signs.
Visitors chat anonymously until your website says who they are. A signed-in visitor's earlier anonymous chat carries on under their account, and only a signed-in visitor can use tools that reach their own data.
How it works#
Your back end signs a short identity for the user who is signed in to your website and the page hands it to the chat window. The chat checks the signature with a key you made for the bot. Only the public half of that key is kept on our side, so nothing we hold can sign a visitor in.
Make a sign-in key#
- In the console, open the bot under Customer serviceCustomer service and make a sign-in key.
- Copy the private key at once and store it with your back end's secrets. It is shown this one time.
- Keep the key's id: put it in each identity's header as
kid. A bot accepts two keys at a time, so you can replace one without a gap.
The bot can also be set to signed-in visitors only; anonymous visitors then cannot open its chat.
Sign an identity on your back end#
The identity is a JSON Web Token signed with ES256. It carries sub, your user's id, unchanging and unique in your company; iat, when it was signed; and exp, at most one hour later. A longer one is refused.
import { SignJWT, importPKCS8 } from "jose";
const key = await importPKCS8(process.env.CHAT_SIGNING_KEY, "ES256");
const identity = await new SignJWT({})
.setProtectedHeader({ alg: "ES256", kid: process.env.CHAT_KEY_ID })
.setSubject(user.id)
.setIssuedAt()
.setExpirationTime("30m")
.sign(key);
The same in Python, with PyJWT:
import time
import jwt
now = int(time.time())
identity = jwt.encode({"sub": user.id, "iat": now, "exp": now + 1800}, signing_key,
algorithm="ES256", headers={"kid": key_id})
Hand it to the chat window#
Give a function that fetches a fresh identity from your back end. The window calls it when it starts and whenever the identity runs out:
TigerlessChat("identity", () => fetch("/chat-identity").then((answer) => answer.text()));
When the user signs out of your website, send an empty identity. The chat ends that visitor's session at once and starts a new anonymous one:
TigerlessChat("identity", null);