Enable Auto-Login Feature

This page is about Chat for JSM Cloud. Using Server or Data Center? Click here.

Supporting customers is even faster and more seamless with the auto-login integration. With this feature, once a customer logs in to your website, they will automatically be logged in to the Chat Widget without having to enter separate credentials. This makes the customer's experience seamless and removes a potential blocker to them getting in touch with you. It also enables agents to respond more quickly.

The auto-login feature requires several changes on the front end and back end of the service that is going to be integrated.

Prerequisites

  1. A secret key is used to verify that the login request is valid and coming from your (client’s) back end. Each service desk project has its own secret key. To obtain the key, open your project, and go to Project Settings > Chat for JSM > Authentication > Auto Login on Website.

  2. Here, enable the Auto Login feature, and then click Generate secret key:

    image-20240216-094307.png
  1. The secret key should be stored on the back end.

Logging in

While performing user login on the website, the service should generate and issue a JWT access token for a chat and sign it with the secret key, as shown in the example below:

const header = { alg: 'HS256', typ: 'JWT' }; const payload = { email: "user@example.com", displayName: "User Account Name", iat: Date.now() / 1000, //unix timestamp in seconds exp: Date.now() / 1000 + 60 * 5 //token expiry date }; const token = KJUR.jws.JWS.sign( //example using jsrsasign library "HS256", JSON.stringify(header), JSON.stringify(payload), sharedSecret );

The service’s front end should receive this token and call Chat’s SSO login API:

const chatWidget = document.querySelector('chat-widget'); chatWidget.onload = async function () { await chatWidget.loginWithToken(token); };
try { await spartezSupportChat.sso.login(token); } catch (exception){ //handle exception }

If you don’t want to show Chat Widget to users until they log in, you can add the following call to the code above:

If you want to show the Chat Widget only to certain users, you can filter by email domain:

During the login operation, an error may occur. In that case, an exception will be thrown. To get the error description, you can access exception.message property.

After that, the user will be logged in with the credentials described in the token, and all tickets will have the reporter field assigned to the SSO user, keeping the original user in the requested participants.

Limitation 1: If the login failed in the case that the customer has an account already in atlassian.com, please check if they have set the visibility of their contact email to "Anyone" so that the Chat app can see the email address and match the two. Here's the link to the profile setting: Profile and Visibility.

Limitation 2: Due to the Jira user creation process, while logging in with a non-existing JSM user email, it may take some time for the user to be fully created on the Atlassian side (less than 1 minute). During this process, trying to log in again with the newly created user may lead to an error, which is temporary.

Logging out

To log out, the service’s front end should call await chatWidget.logout();.

await spartezSupportChat.sso.logout();