Skip to content

Commit f8fb33e

Browse files
committed
Fixing public dashboards
1 parent f36142d commit f8fb33e

File tree

2 files changed

+48
-3
lines changed

2 files changed

+48
-3
lines changed

node/index.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,15 +91,15 @@ app.get("/signed_dashboard/:id", checkAuth, (req, res) => {
9191
app.get("/signed_public_dashboard/", (req, res) => {
9292
const userId = req.session.userId;
9393
const unsignedToken = {
94-
resource: { dashboard: DASHBOARD_ID },
95-
params: { id: userId },
94+
resource: { dashboard: 1 },
95+
params: { },
9696
exp: Math.round(Date.now() / 1000) + (10 * 60) // 10 minute expiration
9797
};
9898
// sign the JWT token with our secret key
9999
const signedToken = jwt.sign(unsignedToken, MB_EMBEDDING_SECRET_KEY);
100100
// construct the URL of the iframe to be displayed
101101
const iframeUrl = `${MB_SITE_URL}/embed/dashboard/${signedToken}`;
102-
res.render("dashboard", { userId: req.params.id, iframeUrl: iframeUrl });
102+
res.render("public_dashboard", { iframeUrl: iframeUrl });
103103
})
104104

105105
app.listen(PORT, () => {

node/views/public_dashboard.pug

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
extends layout.pug
2+
3+
block content
4+
h1 Signed dashboards without parameters</h1>
5+
6+
p
7+
This is an example of a signed embedded dashboard. We haven't signed any parameters, but we have signed the resource id (in this case dashboard 1). This is means that only application with the signing key are allowed to embed a Metabase resource (vs the public link which can be copy/pasted and shared). Signed embeds can also be set to have an expiration time, which further improves security.
8+
9+
p
10+
To embed this dasbhoard in a webpage (as below), you'll need to generate a url on the server by signing a dictionary specifying the resource and it's signed parameters as below
11+
12+
13+
pre.
14+
payload = {
15+
"resource": {"dashboard": 1},
16+
"params": { }
17+
}
18+
19+
token = jwt.encode(payload, METABASE_SECRET_KEY, algorithm="HS256").decode('utf8')
20+
21+
iframeUrl = METABASE_SITE_URL + "/embed/dashboard/" + token + "#bordered=true"
22+
23+
p In the place you wish to embed the chart in your HTML, insert the below:
24+
25+
pre.
26+
&lt;iframe
27+
src="http://{% templatetag openvariable %}iframeUrl{% templatetag closevariable %}"
28+
frameborder="0"
29+
width="800"
30+
height="600"
31+
allowtransparency
32+
&gt;&lt;/iframe&gt;
33+
34+
a(href="/") Go back to a global view
35+
36+
p This results in the below when put together
37+
38+
h2 Global Order Stats
39+
40+
iframe(src=iframeUrl
41+
width="1200"
42+
height="800"
43+
frameborder="0")
44+
45+

0 commit comments

Comments
 (0)