Example: Generate Embed Token for Anonymous User shows how to generate an embed token for an anonymous user with group to access the necessary permission in v13.1.
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 |
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.