-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added metabase dashboard embed API template
- Loading branch information
1 parent
38a0300
commit af452db
Showing
8 changed files
with
183 additions
and
206 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
|
||
<head> | ||
<meta charset="UTF-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<title>TESTING Metabase Dashboard TEMPLATE</title> | ||
<style> | ||
html, | ||
body { | ||
margin: 0; | ||
padding: 0; | ||
height: 100%; | ||
width: 100%; | ||
} | ||
|
||
iframe { | ||
border: none; | ||
width: 100%; | ||
height: 100vh; | ||
position: absolute; | ||
top: 0; | ||
left: 0; | ||
} | ||
</style> | ||
</head> | ||
|
||
<body> | ||
<iframe id="metabase-iframe" src="" allowtransparency></iframe> | ||
<script> | ||
// Set dashboard ID dynamically | ||
var dashboardId = 1; // Replace with dynamic ID if needed | ||
|
||
// Make a request to the PHP server to generate the iframe URL for the selected dashboard ID | ||
fetch('metabase.php?dashboardId=' + dashboardId) | ||
.then(response => response.text()) | ||
.then(iframeUrl => { | ||
document.getElementById('metabase-iframe').src = iframeUrl; | ||
}); | ||
</script> | ||
</body> | ||
<!--If any Questions Please Contact https://github.com/MIKEINTOSHSYSTEMS --> | ||
|
||
</html> |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,14 @@ | ||
<html> | ||
|
||
|
||
<!-- | ||
<iframe | ||
src="https://viz.hispmd.merqconsultancy.org/public/dashboard/d918846e-4cd4-4909-837e-73c99e8f85d8" | ||
frameborder="0" | ||
width="100%" | ||
height="100%" | ||
allowtransparency | ||
></iframe> | ||
</html> | ||
--> | ||
<h1>Analytics Testing</h1> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<?php | ||
require '../../vendor/autoload.php'; | ||
|
||
use Lcobucci\JWT\Configuration; | ||
use Lcobucci\JWT\Signer\Hmac\Sha256; | ||
use Lcobucci\JWT\Signer\Key\InMemory; | ||
|
||
// Metabase parameters | ||
$metabaseSiteUrl = 'https://viz.hispmd.merqconsultancy.org'; //replace with the right metabase url | ||
$metabaseSecretKey = '25893c16e94ac3c193ad2bfa3b2dbdba5ea0e663de266dc7649ffc9216e09865'; // Replace with your Metabase secret key | ||
|
||
// Get the dashboard ID from the query parameter | ||
$dashboardId = isset($_GET['dashboardId']) ? (int)$_GET['dashboardId'] : 0; | ||
|
||
if ($dashboardId <= 0) { | ||
die('Invalid dashboard ID.'); | ||
} | ||
|
||
// Create JWT configuration with HMAC SHA-256 signer | ||
$config = Configuration::forSymmetricSigner( | ||
new Sha256(), | ||
InMemory::plainText($metabaseSecretKey) | ||
); | ||
|
||
// Create the token | ||
$now = new DateTimeImmutable(); | ||
$exp = $now->add(new DateInterval('PT10M')); // Token expires in 10 minutes | ||
|
||
// You can add parameters if needed for filtering or other purposes | ||
$params = (object)[]; | ||
|
||
$token = $config->builder() | ||
->issuedBy($metabaseSiteUrl) // Configures the issuer (iss claim) | ||
->issuedAt($now) // Configures the time that the token was issued (iat claim) | ||
->expiresAt($exp) // Configures the expiration time of the token (exp claim) | ||
->withClaim('resource', ['dashboard' => $dashboardId]) // Add resource claim | ||
->withClaim('params', $params) // Add params claim as an object | ||
->getToken($config->signer(), $config->signingKey()); // Retrieves the generated token | ||
|
||
// Generate iframe URL | ||
$iframeUrl = $metabaseSiteUrl . "/embed/dashboard/" . $token->toString() . "#theme=transparent&bordered=false&titled=true"; | ||
|
||
// Return the iframe URL | ||
echo htmlspecialchars($iframeUrl, ENT_QUOTES, 'UTF-8'); | ||
// If any Questions Please Contact https://github.com/MIKEINTOSHSYSTEMS | ||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<?php | ||
require '../../vendor/autoload.php'; | ||
|
||
use Lcobucci\JWT\Configuration; | ||
use Lcobucci\JWT\Signer\Hmac\Sha256; | ||
use Lcobucci\JWT\Signer\Key\InMemory; | ||
|
||
// Metabase parameters | ||
$metabaseSiteUrl = 'https://viz.hispmd.merqconsultancy.org'; //replace with the right metabase url | ||
$metabaseSecretKey = '25893c16e94ac3c193ad2bfa3b2dbdba5ea0e663de266dc7649ffc9216e09865'; // Replace with your Metabase secret key | ||
|
||
// Get the dashboard ID from the query parameter | ||
$dashboardId = isset($_GET['dashboardId']) ? (int)$_GET['dashboardId'] : 0; | ||
|
||
if ($dashboardId <= 0) { | ||
die('Invalid dashboard ID.'); | ||
} | ||
|
||
// Create JWT configuration with HMAC SHA-256 signer | ||
$config = Configuration::forSymmetricSigner( | ||
new Sha256(), | ||
InMemory::plainText($metabaseSecretKey) | ||
); | ||
|
||
// Create the token | ||
$now = new DateTimeImmutable(); | ||
$exp = $now->add(new DateInterval('PT10M')); // Token expires in 10 minutes | ||
|
||
// You can add parameters if needed for filtering or other purposes | ||
$params = (object)[]; | ||
|
||
$token = $config->builder() | ||
->issuedBy($metabaseSiteUrl) // Configures the issuer (iss claim) | ||
->issuedAt($now) // Configures the time that the token was issued (iat claim) | ||
->expiresAt($exp) // Configures the expiration time of the token (exp claim) | ||
->withClaim('resource', ['dashboard' => $dashboardId]) // Add resource claim | ||
->withClaim('params', $params) // Add params claim as an object | ||
->getToken($config->signer(), $config->signingKey()); // Retrieves the generated token | ||
|
||
// Generate iframe URL | ||
$iframeUrl = $metabaseSiteUrl . "/embed/dashboard/" . $token->toString() . "#theme=transparent&bordered=false&titled=true"; | ||
|
||
// Return the iframe URL | ||
echo htmlspecialchars($iframeUrl, ENT_QUOTES, 'UTF-8'); | ||
// If any Questions Please Contact https://github.com/MIKEINTOSHSYSTEMS | ||
?> |
Oops, something went wrong.