KB : How to make automatic logging into chat on external application

Usecase:

You are having a web application with an embedded logging mechanism. Your application is using for this purpose form which has a password and username (not using any external identity providers).

You would like to embed chat into this application without the need for double authentication (both in the application and chat).

Steps:

Chat is using JSD authentication so the username and password of JSD customer and application have to match.

 

 

The general idea is the following:

  1. Don’t invoke chat immediately

  2. Call /messaging/login endpoint

  3. Get in response JSON

  4. Get userIdentity from that JSON

  5. Set it in cookie e.g. document.cookie = "spartez-support-chat-identity=' +'res.data.data.useIdentity'+'; expires= Thu, 21 Aug 2021 20:00:00 UTC; path=/ "

  6. Then load our script https://{{your have Jira URL}}/SUPPORTSP/download/resources/com.spartez.jira.plugins.support-chat/frontend/js/chat.js

If possible we suggest not adding directly to https://{{your have Jira URL}}/SUPPORTSP/download/resources/com.spartez.jira.plugins.support-chat/frontend/js/chat.js

This can be achieved using the following script:

function chatLoginAndLoad() { window.spartezSupportChat = { url: 'here goes you SD portal URL', portal: 1, // or whatever your customer portal is }; console.log("chatLogin() invoked..."); let username = document.getElementById("username").value; let password = document.getElementById("password").value; let data = { userName: username, password: password }; axios.post('https://{{your have Jira URL}}/SUPPORTSP/rest/com-spartez-support-chat/1.0/messaging/login?_=' + (new Date).getTime(), data).then(res => { if (!res.data.success){ throw (res.data.error); } console.log('logged in as', res.data.data.user, 'with identity', res.data.data.useIdentity); document.cookie = "spartez-support-chat-identity=' +'res.data.data.useIdentity'+'; expires= Thu, 21 Aug 2021 20:00:00 UTC; path=/ " let jsPath = 'https://{{your have Jira URL}}/SUPPORTSP/download/resources/com.spartez.jira.plugins.support-chat/frontend/js/chat.js'; console.log('loading chat script from', jsPath); $("head").append($('<script src="' + jsPath + '"></script>')); }) }

The requirements of the above script are Axios and jQuery. If those are not available, use a substitute.