Skip to content
Open
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.31112.23
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BoldBI.Embed.Sample", "BoldBI.Embed.Sample\BoldBI.Embed.Sample.csproj", "{6D5CD714-8E10-490B-A604-EC1EAC6207F0}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{6D5CD714-8E10-490B-A604-EC1EAC6207F0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{6D5CD714-8E10-490B-A604-EC1EAC6207F0}.Debug|Any CPU.Build.0 = Debug|Any CPU
{6D5CD714-8E10-490B-A604-EC1EAC6207F0}.Release|Any CPU.ActiveCfg = Release|Any CPU
{6D5CD714-8E10-490B-A604-EC1EAC6207F0}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {17ED8247-4B6E-42E3-930D-F78C333EADE9}
EndGlobalSection
EndGlobal
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<RootNamespace>BoldBI.Embed.Sample</RootNamespace>
</PropertyGroup>

<ItemGroup>
<Compile Remove="wwwroot\lib\**" />
<Content Remove="wwwroot\lib\**" />
<EmbeddedResource Remove="wwwroot\lib\**" />
<None Remove="wwwroot\lib\**" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
using BoldBI.Embed.Sample.Models;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Net.Http;
using System.Security.Cryptography;
using System.Threading.Tasks;

namespace BoldBI.Embed.Sample.Controllers
{
public class HomeController : Controller
{
public IActionResult Index()
{
return View();
}


[HttpGet]
[Route("GetDashboards")]
public string GetDashboards()
{
var token = GetToken();

using (var client = new HttpClient())
{
client.BaseAddress = new Uri(EmbedProperties.RootUrl);
client.DefaultRequestHeaders.Accept.Clear();
client.DefaultRequestHeaders.Add("Authorization", token.TokenType + " " + token.AccessToken);
var result = client.GetAsync(EmbedProperties.RootUrl + "/api/" + EmbedProperties.SiteIdentifier + "/v2.0/items?ItemType=2").Result;
string resultContent = result.Content.ReadAsStringAsync().Result;
return resultContent;
}
}

public Token GetToken()
{
using (var client = new HttpClient())
{
client.BaseAddress = new Uri(EmbedProperties.RootUrl);
client.DefaultRequestHeaders.Accept.Clear();

var content = new FormUrlEncodedContent(new[]
{
new KeyValuePair<string, string>("grant_type", "embed_secret"),
new KeyValuePair<string, string>("Username", EmbedProperties.UserEmail),
new KeyValuePair<string, string>("embed_secret", EmbedProperties.EmbedSecret)
});
var result = client.PostAsync(EmbedProperties.RootUrl + "/api/" + EmbedProperties.SiteIdentifier + "/token", content).Result;
string resultContent = result.Content.ReadAsStringAsync().Result;
var response = JsonConvert.DeserializeObject<Token>(resultContent);
return response;
}
}

[HttpPost]
[Route("GetDetails")]
public string GetDetails([FromBody] object embedQuerString)
{
var embedClass = Newtonsoft.Json.JsonConvert.DeserializeObject<EmbedClass>(embedQuerString.ToString());

var embedQuery = embedClass.embedQuerString;
// User your user-email as embed_user_email
embedQuery += "&embed_user_email=" + EmbedProperties.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())
{
client.BaseAddress = new Uri(embedClass.dashboardServerApiUrl);
client.DefaultRequestHeaders.Accept.Clear();

var result = client.GetAsync(embedClass.dashboardServerApiUrl + embedDetailsUrl).Result;
string resultContent = result.Content.ReadAsStringAsync().Result;
return resultContent;
}

}

public string GetSignatureUrl(string queryString)
{
if (queryString != null)
{
var encoding = new System.Text.UTF8Encoding();
var keyBytes = encoding.GetBytes(EmbedProperties.EmbedSecret);
var messageBytes = encoding.GetBytes(queryString);
using (var hmacsha1 = new HMACSHA256(keyBytes))
{
var hashMessage = hmacsha1.ComputeHash(messageBytes);
return Convert.ToBase64String(hashMessage);
}
}
return string.Empty;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.Threading.Tasks;

namespace BoldBI.Embed.Sample.Models
{
[DataContract]
public class EmbedClass
{
[DataMember]
public string embedQuerString { get; set; }
[DataMember]
public string dashboardServerApiUrl { get; set; }
}

public class TokenObject
{
public string Message { get; set; }

public string Status { get; set; }

public string Token { get; set; }
}

public class Token
{
[JsonProperty("access_token")]
public string AccessToken { get; set; }

[JsonProperty("token_type")]
public string TokenType { get; set; }

[JsonProperty("expires_in")]
public string ExpiresIn { get; set; }

[JsonProperty("email")]
public string Email { get; set; }

public string LoginResult { get; set; }

public string LoginStatusInfo { get; set; }

[JsonProperty(".issued")]
public string Issued { get; set; }

[JsonProperty(".expires")]
public string Expires { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace BoldBI.Embed.Sample.Models
{
public class EmbedProperties
{
//BoldBI server URL (ex: http://localhost:5000/bi, http://demo.boldbi.com/bi)
public static string RootUrl = "http://localhost:54879/bi";

//For Bold BI Enterprise edition, it should be like `site/site1`. For Bold BI Cloud, it should be empty string.
public static string SiteIdentifier = "site/site1";

//Your Bold BI application environment. (If Cloud, you should use `cloud`, if Enterprise, you should use `enterprise`)
public static string Environment = "enterprise";

//Enter dashboard ID which you want to embed
public static string dashboardId = "d64dc9ca-0f96-464d-a117-da3ba0bf161e";

//Enter your BoldBI credentials here.
public static string UserEmail = "abcd@gmail.com";

// Get the embedSecret key from Bold BI, please check this link(https://help.syncfusion.com/bold-bi/on-premise/site-settings/embed-settings)
public static string EmbedSecret = "gds8hsgdfhsuhfhsdbY48zSN3qse7";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using System;

namespace BoldBI.Embed.Sample.Models
{
public class ErrorViewModel
{
public string RequestId { get; set; }

public bool ShowRequestId => !string.IsNullOrEmpty(RequestId);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace BoldBI.Embed.Sample
{
public class Program
{
public static void Main(string[] args)
{
CreateHostBuilder(args).Build().Run();
}

public static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.UseStartup<Startup>();
});
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:61377",
"sslPort": 0
}
},
"profiles": {
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"BoldBI.Embed.Sample": {
"commandName": "Project",
"launchBrowser": true,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
},
"applicationUrl": "https://localhost:5001;http://localhost:5000"
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.HttpsPolicy;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace BoldBI.Embed.Sample
{
public class Startup
{
public Startup(IConfiguration configuration)
{
Configuration = configuration;
}

public IConfiguration Configuration { get; }

// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
services.AddControllersWithViews();
}

// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
else
{
app.UseExceptionHandler("/Home/Error");
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
app.UseHsts();
}
app.UseHttpsRedirection();
app.UseStaticFiles();

app.UseRouting();

app.UseAuthorization();

app.UseEndpoints(endpoints =>
{
endpoints.MapControllerRoute(
name: "default",
pattern: "{controller=Home}/{action=Index}/{id?}");
});
}
}
}
Loading