Search results

Anonymous User Embedding

Anonymous embedding is an ideal solution for applications with a large number of users, where managing each user individually within Bold BI would be inefficient. Instead, anonymous embedding allows you to seamlessly integrate dashboards with a predefined, permission-based group on the BI server, providing a streamlined experience for your users.

Steps to Implement Anonymous Embedding

  • Enable the System User option in the UMS Accounts page. This allows you to manage anonymous users without creating individual accounts for each user. Systemuser

  • Create a new group and assign the necessary permissions for this group to access the necessary dashboards. grouplist

    grouppermission

Generate Embed Token for Anonymous User from v14

Node

var http = require("http");
var https = require("https");
var express = require('express');
var cors = require('cors');
var app = express();

app.use(cors());
// Parse JSON bodies (as sent by API clients)
app.use(express.json());

app.post('/tokenGeneration', function (request, response) {
  const embedDetails = {
    serverurl: "<Bold BI Server URL>",
    siteidentifier: "<Site Identifier>",
    dashboard: { // Dashboard ID property is mandatory only when using BoldBI version 14.1.11.
      id: "<Dashboard Id>"
    },
    embedsecret: "<Embed Secret Key>",
    // Anonymous details
    email: "<Anonymous User Email>",
    anonymous: {
        isenabled: true,
        groupname: "<Group Name>"
    }
  }

  const parsedUrl = new URL(embedDetails.serverurl);
  const postData = JSON.stringify(embedDetails);
  const client = parsedUrl.protocol === 'https:' ? https : http;
  const options = {
    hostname: parsedUrl.hostname,
    port: parsedUrl.port || (parsedUrl.protocol === 'https:' ? 443 : 80),
    path: `${parsedUrl.pathname}/api/${embedDetails.siteidentifier}/embed/authorize`,
    method: 'POST',
    headers: {
      'Content-Type': 'application/json',
      'Content-Length': Buffer.byteLength(postData)
    }
  };

  const authRequest = client.request(options, authResponse => {
    let result = '';
    authResponse.setEncoding('utf8');
    authResponse.on('data', chunk => result += chunk);
    authResponse.on('end', () => {
      const resultparse = JSON.parse(result);
      response.send(resultparse?.Data?.access_token);
    });
  });

  authRequest.on('error', (e) => {
    console.error("Error fetching embed token:", e.message);
  });

  authRequest.write(postData);
  authRequest.end();
});
Parameter Description
email Email of the anonymous user (not in Bold BI)
anonymous: { groupname: } The group name under which the anonymous user will be authorized

Generate Embed Token for Anonymous User below v14

Node

const express = require('express');
const crypto = require('crypto');
const https = require('https');
const http = require('http');

const app = express();

app.post('/tokenGeneration', function (req, res) {
  // Required details
  const serverUrl = "<Bold BI Server URL>";
  const siteIdentifier = "<Site Identifier>";
  const serverApiUrl = serverUrl + "/api/" + siteIdentifier;
  const dashboardId = "<Dashboard Id>";
  const embedSecret = "<Embed Secret Key>";

  // Other required details
  const useremail = "<Anonymous User Email>";  // Email of the anonymous user (not in Bold BI)
  const groupName = "<Group Name>";  // The group name under which the anonymous user will be authorized

  // Build query string
  let queryString = "embed_nonce=" + crypto.randomUUID();
  queryString += "&embed_dashboard_id=" + dashboardId;

  // Add anonymous embedding and group details to the query string
  queryString += "&embed_anonymous_token=true";  // This property enables anonymous embedding.
  queryString += "&embed_authorize_group=" + groupName;  // Authorize the user with a specific group
  queryString += "&embed_user_email=" + useremail;  // The email associated with the anonymous user

  // Sign query string
  const embedSignature = "&embed_signature=" + getSignatureUrl(queryString, embedSecret);
  const embedDetailsUrl = "/embed/authorize?" + queryString + embedSignature;

  // Request token from Bold BI server
  const serverProtocol = new URL(serverApiUrl).protocol === 'https:' ? https : http;
  serverProtocol.get(serverApiUrl + embedDetailsUrl, function (resultContent) {
    let str = '';
    resultContent.on('data', chunk => { str += chunk; });
    resultContent.on('end', function () {
      const resultJson = JSON.parse(str);
      if (resultJson?.ApiStatus && resultJson.Data?.access_token) {
        res.json({ access_token: resultJson.Data.access_token });
      } else {
        res.status(500).json({ error: "Failed to generate embed token" });
      }
    });
  });
});

// Helper function: Sign query string using embedSecret
function getSignatureUrl(queryString, embedSecret) {
  const hmac = crypto.createHmac('sha256', Buffer.from(embedSecret));
  return hmac.update(queryString).digest('base64');
}
Property Description
embed_user_email Email of the anonymous user (not in Bold BI)
embed_authorize_group The group name under which the anonymous user will be authorized

Embed the Dashboard for the Anonymous User

After generating the embed token, you can embed the dashboard into your frontend application using the Bold BI Embed SDK. The token will authorize the anonymous user based on the group assignment.

<div id="dashboard_container_id"></div>
<script>
    var boldbiEmbedInstance = BoldBI.create({
        serverUrl: "<Bold BI Server URL>",
        dashboardId: "<Dashboard Id>",
        embedContainerId: "dashboard_container_id",
        embedToken: "<Embed token generated from backend server>"
    });
    boldbiEmbedInstance.loadDashboard();  
</script>

Important: Anonymous user support is available only for the single dashboard viewer starting from Bold BI Version 10.1.18. It also supports Row-Level Security (RLS) for dynamic data filtering. You can find more details on implementing RLS here.