Introduction Learn how a Sisense client-side plugin can sign users straight into a Compose SDK app by passing their own API token in the app's URL. So users can skip the authentication step and every query respects their data security. Where it fits The plugin gets the user's token from Fusion and opens the app with it in the URL fragment. The app mounts SisenseContextProvider with it, so every query runs as that user. The link will looks like this: https://csdk-app.example.com/?url=https://bi.example.com&dashboardId=<oid>&widgetId=<oid>#token=<api token> url : the Fusion instance the app should connect to. dashboardId , widgetId : it's an optional context, so the app can open in the right Dashboard or Rendering the Widget. #token : the user's API token, in the fragment so it is never sent to a server. [STEP 1]: Get the user's API token in the plugin The plugin runs inside Fusion, so its requests carry the user's session cookie. One call to the public GET /api/v1/authentication/tokens/api endpoint ( REST API reference ) returns an API token for that user. Fusion checks cookie-authenticated calls for XSRF, so copy the XSRF-TOKEN cookie into an X-XSRF-TOKEN header. Code type: JavaScript (Sisense plugin, main.js ): const TOKEN_ENDPOINT = '/api/v1/authentication/tokens/api';
function readCookie(cookieString, name) {
for (const part of cookieString.split(';')) {
const [key, ...rest] = part.trim().split('=');
if (key === name) return decodeURIComponent(rest.join('='));
}
return undefined;
}
async function requestSessionToken() {
const headers = { Accept: 'application/json' };
const xsrf = readCookie(document.cookie, 'XSRF-TOKEN');
if (xsrf) headers['X-XSRF-TOKEN'] = xsrf;
const response = await fetch(TOKEN_ENDPOINT, {
method: 'GET',
credentials: 'include',
headers,
});
if (!response.ok) throw new Error(`HTTP ${response.status}`);
const body = await response.json();
const token = typeof body === 'string' ? body : body?.token || body?.access_token;
if (!token) throw new Error('No token in response');
return token;
} Cache the token for the page's lifetime. Each call issues a new token and revokes the previous one, so requesting it on every click would break any app still open with the old token. Code type: JavaScript (Sisense plugin, main.js ): let sessionToken = null;
async function getSessionToken() {
if (sessionToken) return sessionToken;
try {
sessionToken = await requestSessionToken();
return sessionToken;
} catch (error) {
console.warn('Could not get an API token:', error);
return undefined; // the app falls back to its own login form
}
} [Step 2]: Build the URL and open it Put the instance URL and ids in the query string and the token in the fragment. URLSearchParams and encodeURIComponent handle the escaping. Code type: JavaScript (Sisense plugin, main.js ): function buildAppUrl(appUrl, { sisenseUrl, dashboardId, widgetId, token }) {
const url = new URL(appUrl);
url.searchParams.set('url', sisenseUrl);
if (dashboardId) url.searchParams.set('dashboardId', dashboardId);
if (widgetId) url.searchParams.set('widgetId', widgetId);
url.hash = token ? `token=${encodeURIComponent(token)}` : '';
return url.toString();
} Open the tab before the first await . Browsers only allow window.open during the click itself; called after the token request resolves, it gets blocked as a popup. So open an empty tab right away and navigate it once the token is ready. Code type: JavaScript (Sisense plugin, main.js ): async function openApp(dashboardId, widgetId) {
const win = window.open('', '_blank'); // still inside the click
if (win) win.opener = null;
const token = await getSessionToken();
const url = buildAppUrl(config.appUrl, {
sisenseUrl: window.location.origin,
dashboardId,
widgetId,
token,
});
if (win) win.location.href = url;
else window.location.href = url;
} Call openApp from wherever the plugin exposes the action, for example a "..." menu item added with prism.on('beforemenu', …) . win.opener = null stops the app's page from reaching back into Fusion's window. [Step 3]: Read the token in the Compose SDK app, then strip it On load, read url and the ids from the query string and token from the fragment. Code type: TypeScript (Compose SDK app) export function readLink(location: Pick<Location, 'search' | 'hash'>) {
const query = new URLSearchParams(location.search);
const hash = new URLSearchParams(location.hash.replace(/^#/, ''));
return {
url: query.get('url') ?? undefined,
token: hash.get('token') ?? undefined,
dashboardId: query.get('dashboardId') ?? undefined,
widgetId: query.get('widgetId') ?? undefined,
};
} Then remove the token from the address bar with history.replaceState , so it does not stay in browser history or get copied when the user shares the link. Other parameters stay. Code type: TypeScript (Compose SDK app) export function stripTokenFromUrl(win: Window = window) {
const current = new URL(win.location.href);
const hash = new URLSearchParams(current.hash.replace(/^#/, ''));
if (!hash.has('token')) return;
hash.delete('token');
const rest = hash.toString();
current.hash = rest ? `#${rest}` : '';
win.history.replaceState(win.history.state, '', current.toString());
} Run both once, before the first render, and keep the values in app state: Code type: TypeScript (Compose SDK app, app entry point) const link = readLink(window.location);
stripTokenFromUrl();
store.connect({ url: link.url, token: link.token }); If either url or token is missing, show the app's normal login form, prefilled with whatever the link did carry. [Step 4]: Pass the token to SisenseContextProvider Compose SDK authenticates through a React context. Every CSDK hook and component must sit under SisenseContextProvider , which takes the instance url and an API token ( CSDK authentication guide ). Mount it once both values exist: Code type: TypeScript + React / TSX (Compose SDK app) import { SisenseContextProvider } from '@sisense/sdk-ui';
export function SisenseConnection({ connection, children }) {
const disconnect = useStore((s) => s.disconnect);
return (
<SisenseContextProvider
url={connection.url} // from ?url=
token={connection.token} // from #token=
onError={(error) => <ConnectionErrorCard error={error} onBack={disconnect} />}
>
{children}
</SisenseContextProvider>
);
} Pass an onError handler. Without one, a bad or revoked token makes the provider render its own full-page error box, with no way back to the login form. From here every CSDK hook, such as useGetDashboardModels or useExecuteQuery , runs as the user who clicked in Fusion. Example: query the data directly The link already carries dashboardId and widgetId , so the app can run that widget's own query and read the rows itself, without rendering the widget. The result has columns and rows ; each cell has data (the raw value) and text (the formatted value). Code type: TypeScript + React / TSX (Compose SDK app) import { useExecuteQueryByWidgetId } from '@sisense/sdk-ui';
export function WidgetData({ dashboardId, widgetId }) {
const { data, isLoading, isError, error } = useExecuteQueryByWidgetId({
dashboardOid: dashboardId, // from ?dashboardId=
widgetOid: widgetId, // from ?widgetId=
count: 100,
});
if (isLoading) return <p>Loading…</p>;
if (isError) return <p>Query failed: {error.message}</p>;
if (!data) return null;
return (
<table>
<thead>
<tr>{data.columns.map((c) => <th key={c.name}>{c.name}</th>)}</tr>
</thead>
<tbody>
{data.rows.map((row, i) => (
<tr key={i}>{row.map((cell, j) => <td key={j}>{cell.text ?? String(cell.data)}</td>)}</tr>
))}
</tbody>
</table>
);
} To write the query yourself instead, use useExecuteQuery with a data model generated by @sisense/sdk-cli . This example uses the Sample ECommerce model: Code type: TypeScript + React / TSX (Compose SDK app) import { useExecuteQuery } from '@sisense/sdk-ui';
import { measureFactory } from '@sisense/sdk-data';
import * as DM from './sample-ecommerce'; // generated by @sisense/sdk-cli
export function RevenueByAge() {
const { data, isLoading, isError } = useExecuteQuery({
dataSource: DM.DataSource,
dimensions: [DM.Commerce.AgeRange],
measures: [measureFactory.sum(DM.Commerce.Revenue, 'Revenue')],
});
if (isLoading) return <p>Loading…</p>;
if (isError || !data) return <p>Query failed.</p>;
return <pre>{JSON.stringify(data.rows, null, 2)}</pre>;
} Both hooks must run inside SisenseContextProvider , so they use the token from the link. [Step 5]: Keep the token safe Put the token in the fragment, not the query string. Browsers never send the fragment to a server, so it stays out of places a query parameter ends up: Web server and proxy access logs: a ?token= query parameter is logged; a #token= fragment is not. Referer header on outgoing requests: the query string can be sent along; the fragment never is. Browser history and copied links: both forms stay there until the app strips the token. That last point is why Step 3 strips the token right after reading it. Each user gets their own token. The plugin never uses a shared or service token, so data security and row-level rules apply exactly as in Fusion. Never put a token in the plugin's config.js : every user's browser downloads that file. Allow the app's origin in Fusion's CORS settings. The app is on a different origin and calls Fusion directly from the browser, so Fusion must allow it. Each new token revokes the previous one. Opening the app again from a fresh page load invalidates the token an already-open copy is using. Cache the token in the plugin (Step 1) to avoid this within one page. Treat the link like a password until the app has stripped the token. Do not log it, and do not send it through chat or email. Conclusion A Sisense plugin can get the signed-in user's API token from GET /api/v1/authentication/tokens/api , using the session cookie and the XSRF header. Pass the token to the Compose SDK app in the URL fragment ( #token= ), never the query string, so it stays out of server logs and Referer headers. The app reads the token, removes it from the address bar right away, and passes it to SisenseContextProvider . Each user works with their own token, so data security applies as it does in Sisense. Allow the app's origin in Sisense's CORS settings, and cache the token in the plugin, since each new token revokes the previous one. You can download the plugin here (Github repository) References/Related Content Compose SDK: Authentication & Security REST API reference: Get API token Building JavaScript Plugins for Sisense Sisense add-ons (Linux) Sisense bearer tokens (Linux) Disclaimer: This post outlines a potential custom workaround for a specific use case or provides instructions regarding a specific task. The solution may not work in all scenarios or Sisense versions, so we strongly recommend testing it in your environment before deployment. If you need further assistance with this, please let us know.