Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 33 additions & 13 deletions BlazorWebAssembly/Client/wwwroot/index.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
Expand Down Expand Up @@ -28,7 +29,10 @@
<script type="text/javascript" src="https://cdn.boldbi.com/embedded-sdk/latest/boldbi-embed.js"></script>
<script>
var data;
var authorizationServerUrl = "api/EmbedData/AuthorizationServer";

//Url of the TokenGeneration action in EmbedDataController of the Server application
var tokenGenerationUrl = "api/EmbedData/TokenGeneration";

async function fetchDataAndHandleErrors() {
try {
const response = await fetch('/api/EmbedData/GetConfig');
Expand All @@ -49,19 +53,35 @@

fetchDataAndHandleErrors();

function renderDashboard() {
this.dashboard = BoldBI.create({
serverUrl: data.ServerUrl + "/" + data.SiteIdentifier,
dashboardId: data.DashboardId,
embedContainerId: "dashboard",
width: "100%",
height: window.innerHeight + "px",
authorizationServer: {
url: authorizationServerUrl
}
});
this.dashboard.loadDashboard();
function getEmbedToken() {
return fetch(tokenGenerationUrl, { // Backend application URL
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({})
})
.then(response => {
if (!response.ok) throw new Error("Token fetch failed");
return response.text();
});
}

function renderDashboard() {
this.getEmbedToken()
.then(accessToken => {
const dashboard = BoldBI.create({
serverUrl: data.ServerUrl + "/" + data.SiteIdentifier,
dashboardId: data.DashboardId,
embedContainerId: "dashboard",
embedToken: accessToken
});

dashboard.loadDashboard();
})
.catch(err => {
console.error("Error rendering dashboard:", err);
});
};
</script>
</body>

</html>
60 changes: 24 additions & 36 deletions BlazorWebAssembly/Server/Controllers/EmbedDataController.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,7 @@
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Newtonsoft.Json;
using BlazorWebAssembly.Shared;
using BlazorWebAssembly.Client.Pages;
using System.Text;

namespace BlazorWebAssembly.Server.Controllers
{
Expand Down Expand Up @@ -42,38 +36,32 @@ public IActionResult EmbedConfigErrorLog()
}

[HttpPost("[action]")]
[Route("AuthorizationServer")]
public string AuthorizationServer([FromBody] object embedQuerString)
[Route("TokenGeneration")]
public string TokenGeneration()
{
var embedClass = JsonConvert.DeserializeObject<EmbedClass>(embedQuerString.ToString());
var embedQuery = embedClass.embedQuerString;
embedQuery += "&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;
embedQuery += "&embed_server_timestamp=" + timeStamp;
var embedDetailsUrl = "/embed/authorize?" + embedQuery + "&embed_signature=" + GetSignatureUrl(embedQuery);

using (var client = new HttpClient())
var embedDetails = new
{
client.BaseAddress = new Uri(embedClass.dashboardServerApiUrl);
client.DefaultRequestHeaders.Accept.Clear();
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
}
};

//Post call to Bold BI server
var client = new HttpClient();
var requestUrl = $"{embedDetails.serverurl}/api/{embedDetails.siteidentifier}/embed/authorize";

var result = client.GetAsync(embedClass.dashboardServerApiUrl + embedDetailsUrl).Result;
string resultContent = result.Content.ReadAsStringAsync().Result;
return resultContent;
}
}
var jsonPayload = JsonConvert.SerializeObject(embedDetails);
var httpContent = new StringContent(jsonPayload, Encoding.UTF8, "application/json");

public 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 System.Security.Cryptography.HMACSHA256(keyBytes))
{
var hashMessage = hmacsha1.ComputeHash(messageBytes);
return Convert.ToBase64String(hashMessage);
}
var result = client.PostAsync(requestUrl, httpContent).Result;
var resultContent = result.Content.ReadAsStringAsync().Result;

return JsonConvert.DeserializeObject<dynamic>(resultContent).Data.access_token;
}
}
}
Binary file modified images/dashboard.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.