Skip to main content

Authentication

In the Widget API, visitor identity is verified with a JWT (accessToken).

Summary

MechanismWhenHow
JWT BearerMessage history and sending messagesHeader: Authorization: Bearer <accessToken>
JWT (socket)Socket.IO /messageHandshake: auth.token = accessToken

The accessToken is obtained from the Visitor Registration response.

JWT (accessToken)

The token returned after registration represents the visitor's chat session. In summary, the token payload includes:

FieldDescription
chatAppIdChat application ID
chatUserIdWidget user ID
nameDisplay name
emailAddressOptional email
phoneOptional phone
externalUserIdOptional external user ID

REST usage

Authorization: Bearer <accessToken>

The following calls require a Bearer JWT:

Socket.IO usage

import { io } from 'socket.io-client';

const socket = io(`${BASE_URL}/message`, {
auth: { token: accessToken },
withCredentials: true,
});

See Realtime messages for details.

Failed authentication

SituationTypical result
Invalid / missing JWT (REST)401
Invalid / missing JWT (socket)error event, then the connection is closed