superset/superset-embedded-sdk
dependabot[bot] 87f2b93023
build(deps-dev): bump @babel/traverse from 7.16.10 to 7.23.2 in /superset-embedded-sdk (#25663)
Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2024-01-16 14:21:40 -07:00
..
src fix(embedded sdk): Remove trailing slash from passed superset domain if there is one (#25020) 2023-08-25 09:24:58 -07:00
.gitignore feat: Embedded SDK (#18250) 2022-02-03 14:01:45 -08:00
CONTRIBUTING.md chore(misc): Spelling (#25456) 2023-09-29 09:34:04 -07:00
README.md feat(embedded): provides filter bar visibility setting on embedded dashboard (#21069) (#21070) 2022-09-01 09:50:02 -03:00
babel.config.js feat: Embedded SDK (#18250) 2022-02-03 14:01:45 -08:00
package-lock.json build(deps-dev): bump @babel/traverse from 7.16.10 to 7.23.2 in /superset-embedded-sdk (#25663) 2024-01-16 14:21:40 -07:00
package.json build(deps-dev): bump axios from 0.25.0 to 1.6.0 in /superset-embedded-sdk (#25953) 2023-11-13 12:39:52 -07:00
release-if-necessary.js feat: Introduce a library for embedded iframe <-> host communication (#18652) 2022-02-11 20:29:23 -08:00
tsconfig.json chore: use switchboard as dependency for embedded sdk (#18728) 2022-02-15 11:53:58 -08:00
webpack.config.js feat: Introduce a library for embedded iframe <-> host communication (#18652) 2022-02-11 20:29:23 -08:00

README.md

Superset Embedded SDK

The Embedded SDK allows you to embed dashboards from Superset into your own app, using your app's authentication.

Embedding is done by inserting an iframe, containing a Superset page, into the host application.

Embedding a Dashboard

Using npm:

npm install --save @superset-ui/embedded-sdk
import { embedDashboard } from "@superset-ui/embedded-sdk";

embedDashboard({
  id: "abc123", // given by the Superset embedding UI
  supersetDomain: "https://superset.example.com",
  mountPoint: document.getElementById("my-superset-container"), // any html element that can contain an iframe
  fetchGuestToken: () => fetchGuestTokenFromBackend(),
  dashboardUiConfig: { // dashboard UI config: hideTitle, hideTab, hideChartControls, filters.visible, filters.expanded (optional)
      hideTitle: true,
      filters: {
          expanded: true,
      }
  },
});

You can also load the Embedded SDK from a CDN. The SDK will be available as supersetEmbeddedSdk globally:

<script src="https://unpkg.com/@superset-ui/embedded-sdk"></script>

<script>
  supersetEmbeddedSdk.embedDashboard({
    // ... here you supply the same parameters as in the example above
  });
</script>

Authentication/Authorization with Guest Tokens

Embedded resources use a special auth token called a Guest Token to grant Superset access to your users, without requiring your users to log in to Superset directly. Your backend must create a Guest Token by requesting Superset's POST /security/guest_token endpoint, and pass that guest token to your frontend.

The Embedding SDK takes the guest token and use it to embed a dashboard.

Creating a Guest Token

From the backend, http POST to /security/guest_token with some parameters to define what the guest token will grant access to. Guest tokens can have Row Level Security rules which filter data for the user carrying the token.

The agent making the POST request must be authenticated with the can_grant_guest_token permission.

Example POST /security/guest_token payload:

{
  "user": {
    "username": "stan_lee",
    "first_name": "Stan",
    "last_name": "Lee"
  },
  "resources": [{
    "type": "dashboard",
    "id": "abc123"
  }],
  "rls": [
    { "clause": "publisher = 'Nintendo'" }
  ]
}