Skip to main content

Signing the Messenger widget with a JWT token

Messenger

Signing the Messenger widget with a JWT token

At the bottom of the "Get Code" box is a section where you can define a JWT token. JWT is a way to cryptographically sign some data so the system knows the data can be trusted (i.e. it was not tampered with).

There are two use-cases for using a JWT signing:

  • You have internal pages on your site and you want to set the user on a chat as if they were logged in. For example, maybe you have an internal members area and you want your users to raise chats. You can set the email address on the chat, sign it with JWT, and then the chat widget will act as though that user was logged in.
  • The second use-case is when you want to control where the widget can be installed to by requiring JWT signing. This would prevent, for example, someone copying the chat code to put on an arbitrary site.

Using JWT signing

Within the chat widget code you copy from the "Get Code" section is a declaration for options. Specify a jwt property here containing your encoded token.

For example:

window.DESKPRO_WIDGET_OPTIONS = {
  //...
  "jwt": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJlbWFpbC...trucated"
};

You will need some kind of server-side scripting to generate the token with your secret. The JWT website has lots of information with a variety of libraries.

The payload (array of data) in the token can be anything (even empty). The following are supported:

  • Recommneded: exp field, which is a timestamp representing when the token expires
  • email -- the email address of the user you want to make the chat belong to. Note that since this value is signed by you, it is trusted. It's as if this user were actually logged-in to the chat.
  • name -- The name of the user. This will be set on the user if their account in Deskpro doesn't already have a name.
  • person_id -- If you know the person ID of the person you want to set specifically, you can use that instead of the email address.
Authors list

First published: 20/07/2020

Last updated: Jul 20, 2020 by Matthew Wray