From 2cbb4970fe6a295c807f5d5410503eee629f4eb1 Mon Sep 17 00:00:00 2001 From: "anuabarna.bsf19" Date: Tue, 17 Feb 2026 18:55:50 +0530 Subject: [PATCH] updated sample with embedtoken --- BoldBIEmbedSample/Default.aspx.cs | 75 +++++++++++++++--------------- BoldBIEmbedSample/Site.Master | 39 +++++++++++----- images/dashboard-view.png | Bin 135804 -> 117466 bytes 3 files changed, 64 insertions(+), 50 deletions(-) diff --git a/BoldBIEmbedSample/Default.aspx.cs b/BoldBIEmbedSample/Default.aspx.cs index bf7027d..c431166 100644 --- a/BoldBIEmbedSample/Default.aspx.cs +++ b/BoldBIEmbedSample/Default.aspx.cs @@ -1,54 +1,53 @@ using System; -using System.Collections.Generic; -using System.Linq; using System.Net.Http; -using System.Security.Cryptography; -using System.Web; +using System.Text; using System.Web.Services; using System.Web.UI; -using System.Web.UI.WebControls; using BoldBIEmbedSample.Models; +using Newtonsoft.Json; +using Newtonsoft.Json.Linq; namespace BoldBIEmbedSample { public partial class _Default : Page { [WebMethod()] - public static void AuthorizationServer(string embedQuerString, string dashboardServerApiUrl) + public static string TokenGeneration() { - embedQuerString += "&embed_user_email=" + GlobalAppSettings.EmbedDetails.UserEmail; - //To set embed_server_timestamp to overcome the EmbedCodeValidation failing while different timezone using at client application. - double timeStamp = (int)DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1)).TotalSeconds; - embedQuerString += "&embed_server_timestamp=" + timeStamp; - var embedDetailsUrl = "/embed/authorize?" + embedQuerString + "&embed_signature=" + GetSignatureUrl(embedQuerString); - - using (var client = new HttpClient()) + var embedDetails = new { - client.BaseAddress = new Uri(dashboardServerApiUrl); - client.DefaultRequestHeaders.Accept.Clear(); - - var result = client.GetAsync(dashboardServerApiUrl + embedDetailsUrl).Result; - string resultContent = result.Content.ReadAsStringAsync().Result; - //return resultContent; - var js = new System.Web.Script.Serialization.JavaScriptSerializer(); - - HttpContext.Current.Response.Clear(); - HttpContext.Current.Response.ContentType = "application/json; charset=utf-8"; - HttpContext.Current.Response.Write(js.Serialize(resultContent)); - HttpContext.Current.Response.Flush(); - HttpContext.Current.Response.End(); - } - } + email = GlobalAppSettings.EmbedDetails.UserEmail, + serverurl = GlobalAppSettings.EmbedDetails.ServerUrl, + siteidentifier = GlobalAppSettings.EmbedDetails.SiteIdentifier, + embedsecret = GlobalAppSettings.EmbedDetails.EmbedSecret, + dashboard = new // Dashboard ID property is mandatory only when using BoldBI version 14.1.11. + { + id = GlobalAppSettings.EmbedDetails.DashboardId + } + }; - public static string GetSignatureUrl(string message) - { - var encoding = new System.Text.UTF8Encoding(); - var keyBytes = encoding.GetBytes(GlobalAppSettings.EmbedDetails.EmbedSecret); - var messageBytes = encoding.GetBytes(message); - using (var hmacsha1 = new HMACSHA256(keyBytes)) - { - var hashMessage = hmacsha1.ComputeHash(messageBytes); - return Convert.ToBase64String(hashMessage); - } + //Post call to Bold BI server + var client = new HttpClient(); + var requestUrl = $"{embedDetails.serverurl}/api/{embedDetails.siteidentifier}/embed/authorize"; + + var jsonPayload = JsonConvert.SerializeObject(embedDetails); + var httpContent = new StringContent(jsonPayload, Encoding.UTF8, "application/json"); + + var result = client.PostAsync(requestUrl, httpContent).Result; + var resultContent = result.Content.ReadAsStringAsync().Result; + + // Extract token from server response + var json = JObject.Parse(resultContent); + var token = json["Data"]?["access_token"]?.ToString() ?? json["access_token"]?.ToString(); + + // Write raw token to the HTTP response so client-side `response.text()` returns the token string + var resp = System.Web.HttpContext.Current.Response; + resp.Clear(); + resp.ContentType = "text/plain"; + resp.Write(token); + resp.Flush(); + resp.End(); + + return token; } protected void Page_Load(object sender, EventArgs e) diff --git a/BoldBIEmbedSample/Site.Master b/BoldBIEmbedSample/Site.Master index 57ef1ea..9fd38be 100644 --- a/BoldBIEmbedSample/Site.Master +++ b/BoldBIEmbedSample/Site.Master @@ -26,22 +26,37 @@ <% Response.Redirect("~/EmbedConfigErrorLog.aspx"); %> <% } %> - function Init() { - this.dashboard = BoldBI.create({ - serverUrl: rootUrl + "/" + siteIdentifier, - dashboardId: dashboardId, - embedContainerId: "dashboard", - width: "100%", - height: "100%", - authorizationServer: { - url: "Default.aspx/AuthorizationServer" - } + function getEmbedToken() { + return fetch("Default.aspx/TokenGeneration", { + method: 'POST', + headers: { 'Content-Type': 'application/json' }, + body: JSON.stringify({}) + }) + .then(response => { + if (!response.ok) throw new Error("Token fetch failed"); + return response.text(); }); - this.dashboard.loadDashboard(); } + + function renderDashboard(dashboardId) { + getEmbedToken() + .then(accessToken => { + const dashboard = BoldBI.create({ + serverUrl: rootUrl + "/" + siteIdentifier, + dashboardId: dashboardId, + embedContainerId: "dashboard", + embedToken: accessToken + }); + + dashboard.loadDashboard(); + }) + .catch(err => { + console.error("Error rendering dashboard:", err); + }); + }; - +
diff --git a/images/dashboard-view.png b/images/dashboard-view.png index a988169359e0fbb6a82d17244334b7a5e60e820f..04bc71d6593f5f64735fa3e53b4a6a9fc7cd31df 100644 GIT binary patch literal 117466 zcmce-cUV*D^FFMrt_8ak0Ra^dr78$Wx6+G(bOI~Vs{#oKgy>pOkS-uyqzQqUqKJ!lq5A1isZ9+koqx zw+!urH*MPcf%kWFbKontO`Fz>j4ofe9_Gv#-WPeDl{34p&F-dPKXb^~bdKk2&=Pwl zje^D$(QAt?Jo9n&i09!nHAw?jqr zQ`Rb+LWjYKhrg_}amS+5`xuZ|sjuSs|NO4d^N=iLeP(uj1T6jEm2)j#k;Km3dOc~VEH$pNkeHFNe<|goOSLa;W^-zYwwQ%Q zgR_{~E0QYmC|2guqupOWnE$%5o+sTiSF{dSrPDgP=0lv(qpTQpehgMyv*UB*=)qt2 zl8Ao-Ipd+%E1W+{%M9tK_Y3Efrkj=r>Tu)XRsXp+4x;Q~amZpa46T;K4F}ttghY4` zao*CO6o4~)k=Oyv^##CCfma#_+7~rJpBlvez5kM`w)bpJ@g5CYIT5aM2}R~RuCC(Qrgq6W4pOBzdrLseA=fY zzRBV^Si8`-x0?u;yNDvkD)a1|b*-SlztdeyM1SU238e&-T|e%Sn;6eIFzwe7FYN$4 z9L40$!d&#@k9b45HAtwLew>K(rRcq21%rk|bb7xvpyMm^D<*q&^a84B>8wjSQLAAY zTA>K-)wvG?#PE#zY%#17zTV^)yC%93dWuXco~MWEyNYd_>YxAK`S#wH@yYH2OB