Skip to content

Authentication

stefancalibrate1 edited this page Dec 5, 2022 · 2 revisions

The package itself is not performing authentication. The authentication information is passed to the package when initializing.

Certificates

Certificates data is passes as https.Agent()

import fs from "fs";
import https from "https";
import { QlikRepositoryClient } from "qlik-rest-api";

// read the certificates
const crt = fs.readFileSync("path/to/certificate.pem");
const key = fs.readFileSync("path/to/certificate_key.pem");

// init https agent
const httpsAgent = new https.Agent({
  rejectUnauthorized: false,
  cert: crt,
  key: key,
});

// create our config by passing the created httpAgent
const config = {
  host: "my-qlik-sense-instance",
  port: 4242,
  httpsAgent: httpsAgent,
  authentication: {
    user_dir: "SOME_DIR",
    user_name: "SOME_USER",
  },
};

// use the config
const repoClient = new QlikRepositoryClient(config);
const result = await repoClient.Get("about");

Header

import { QlikRepositoryClient } from "qlik-rest-api";

const config = {
  host: "my-sense-host",
  proxy: "proxy-prefix",
  authentication: {
    header: "header-name",
    user: "directory\\user", //(or in whatever format the user is)
  },
};

const repoClient = new QlikRepositoryClient(config);
const result = await repoClient.Get("about");

JWT

import { QlikRepositoryClient } from "qlik-rest-api";

const config = {
  host: "my-sense-host",
  proxy: "jwt-proxy-prefix",
  authentication: {
    token: "eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2...",
  },
};

const repoClient = new QlikRepositoryClient(config);
const result = await repoClient.Get("about");

Session

import { QlikRepositoryClient } from "qlik-rest-api";

const config = {
  host: "my-sense-host",
  proxy: "jwt-proxy-prefix",
  authentication: {
    sessionId: "xxxxxxxx-xxx-xxx-xxxx-xxxxxxxxxxxx",
    cookieHeaderName: "X-Qlik-Session", // whatever is set in the virtual proxy
  },
};

const repoClient = new QlikRepositoryClient(config);
const result = await repoClient.Get("about");

Ticket

import { QlikRepositoryClient } from "qlik-rest-api";

const config = {
  host: "my-sense-host",
  authentication: {
    ticket: "some-ticket-value",
  },
};

const repoClient = new QlikRepositoryClient(config);
const result = await repoClient.Get("about");

SaaS

import { QlikSaaSClient } from "qlik-rest-api";

const config = {
  host: "some-tenant.qlikcloud.com",
  authentication: {
    token: "eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2...",
  },
};

const saasClient = new QlikSaaSClient(config);
const result = await saasClient.Get("items");

SaaS OAuth (machine-to-machine)

import { QlikSaaSClient } from "qlik-rest-api";

const config = {
  host: "some-tenant.qlikcloud.com",
  authentication: {
    client_id: "467c467c467c467c467c467c467c467c",
    client_secret: "ad96ad96ad96ad96ad96ad96ad96ad96ad96ad96ad96ad96ad96...",
  },
};

const saasClient = new QlikSaaSClient(config);
const result = await saasClient.Get("items");