Skip to main content

Integration, Extension & APIs

Discussion board where members can learn more about Integration, Extensions and API’s for Qlik Sense.

Announcements
Welcome to Qlik Community! Check out our new navigation! FIND OUT MORE
cancel
Showing results for 
Search instead for 
Did you mean: 
d_pranskus
Partner - Creator III
Partner - Creator III

Connecting to the existing enigma.js session in a browser

Hi Qlik Experts

I am working on a mashup application, where I connect to Qlik Engine using enigma.js library.

To authenticate the user I use a custom-build backend service, which authenticates against LDAP and requests a ticket from proxy service.

My code looks something like this:

 

const enigmaConfig = {
    host: 'server',
    port: 443,
    secure: true,
    prefix: 'some',
    appId: 'appId',
    options: {
        qpsPort: 4243,
        cookie: 'QSCookie',
    },
};

const enigmaConnect({sessionId, qlikTicket}) {
    const config = { ...enigmaConfig };
    if (qlikTicket) {
        config.urlParams = {qlikTicket};
    }
    if (sessionId) {
        config.identity = sessionId;
    }
    const url = SenseUtilities.buildUrl(config);

    try {
        const global = enigma.create({
            schema,
            url: url,
        });
        const session = await global.open();
        const doc = await session.openDoc(config.appId);
        const sessions = await dispatch('getSessions'); // this function will return the list of user sessions by making a request to the back-end service, which will load them from proxy service
        const latestSession = sessions[sessions.length - 1];
        latestSession.qlikTicket = qlikTicket;
        document.cookie = `${enigmaConfig.options.cookie}=${btoa(JSON.stringify(latestSession))};secure=true`;

        return true;
    } catch (err) {
        console.log(err);
        document.cookie = `${enigmaConfig.options.cookie}=;`;
        return false;
    }
}

const open() {
    let cookieSession = null;
    let connected = false;
    try {
        cookieSession = JSON.parse(atob(parseSession(document.cookie)));
    } catch (err) {
    }

    const session = {};
    if (cookieSession) {
        session.sessionId = cookieSession.SessionId;
        // session.qlikTicket = cookieSession.qlikTicket; // here I can provide the old ticket
    } else {
        session.qlikTicket = await dispatch('getTicket');
    }
    connected = await dispatch('enigmaOpen', session);
}

 

So idea is when the user opens the connection for first time to capture the session id and store it in a cookie. Then if the user refreshes the browser while the old session is still active to reconnect to the same session by providing the identity attribute in the URL. 

The problem is that if I provide sessionId as identity attribute and do not provide a new qlikTicket attribute connecting to the enigma second time or provide the old ticket (which I can store in the cookie), the connection fails. But if I provide the identity with the existing sessionId and a new qlikTicket , then a session with the new sessionId is created and the old one is being removed. If I refresh the browser multiple times, then I get an error related to too many active sessions.

I can't use certificates in the connection parameters (or do not want to use them, because this is a front-end application which runs in the browser.

Could someone help me to connect to the same session? Do I miss some parameter?

Thanks

Regards

Darius

Labels (2)
0 Replies