KushKD commented on issue #32889:
URL: https://github.com/apache/superset/issues/32889#issuecomment-2907608055
Its working now.
New Config:
# GNU nano 4.8
superset_config.py
# Superset specific config
ROW_LIMIT = 5000
# Flask App Builder configuration
# Your App secret key will be used for securely signing the session cookie
# and encrypting sensitive information on the database
# Make sure you are changing this key for your deployment with a strong key.
# Alternatively you can set it with `SUPERSET_SECRET_KEY` environment
variable.
# You MUST set this for production environments or the server will not refuse
# to start and you will see an error in the logs accordingly.
SECRET_KEY = ''
#SECRET_KEY = 'Qxl+cLlzU4Tf1XJcJ1d8auT+zdsMWioVzafGYZ0lhWeyZAsUNzQnstv6'
# The SQLAlchemy connection string to your database backend
# This connection defines the path to the database that stores your
# superset metadata (slices, connections, tables, dashboards, ...).
# Note that the connection information to connect to the datasources
# you want to explore are managed directly in the web UI
# The check_same_thread=false property ensures the sqlite client does not
attempt
# to enforce single-threaded access, which may be problematic in some edge
cases
#SQLALCHEMY_DATABASE_URI =
'sqlite:////superset_app/superset_one/superset.db?check_same_thread=false'
SQLALCHEMY_DATABASE_URI =
'postgresql+psycopg2://postgres:postgres@localhost:5432/superset_metadata'
#TALISMAN_ENABLED = False
#WTF_CSRF_ENABLED = False
# CORS Enabling
ENABLE_CORS = True
CORS_OPTIONS = {
"supports_credentials": True,
"origins": [
"http://localhost:3000",
"http://localhost:4200"
],
"methods": ["GET", "POST", "OPTIONS", "PUT", "DELETE"],
"allow_headers": "*",
"expose_headers": "*",
"resources": "*"
}
# Dashboard embedding
GUEST_ROLE_NAME = "ChartViewer"
#PUBLIC_ROLE_LIKE = "Public"
#GUEST_ROLE_NAME = "Admin"
GUEST_TOKEN_JWT_SECRET = ""
GUEST_TOKEN_JWT_ALGO = "HS256"
GUEST_TOKEN_HEADER_NAME = "X-GuestToken"
GUEST_TOKEN_JWT_EXP_SECONDS = 300
GUEST_TOKEN_JWT_ISSUER = "superset-embed"
GUEST_TOKEN_JWT_AUDIENCE = "superset"
ENABLE_TEMPLATE_PROCESSING = True
#TALISMAN_ENABLED = False
# Talisman Config
TALISMAN_ENABLED = False
ENABLE_TEMPLATE_PROCESSING = True
# Allow embedding Superset in iframes
WTF_CSRF_ENABLED = False
#ALLOW_IFRAME_EMBEDDING = True
# Set this API key to enable Mapbox visualizations
MAPBOX_API_KEY = ''
#from superset.stats_logger import DummyStatsLogger
#STATS_LOGGER = DummyStatsLogger(r
FEATURE_FLAGS = {
"DASHBOARD_RBAC": True,
"EMBEDDED_SUPERSET": True,
"EMBEDDED_SUPERSET_API": True,
"EMBEDDABLE_DASHBOARDS": True,
"EMBEDDED_SUPERSET_PROD": True,
"GUEST_ROLE": "ChartViewer",
"ALERT_REPORTS": True,
"THUMBNAILS": True,
"THUMBNAILS_SQLA_LISTENERS": True,
'PRESTO_EXPAND_DATA': True,
"DASHBOARD_RBAC": True,
"LISTVIEWS_DEFAULT_CARD_VIEW": True,
"HORIZONTAL_FILTER_BAR": True,
"TAGGING_SYSTEM": True,
"ALLOW_JWT_AUTHENTICATION": True
}
from superset.stats_logger import BaseStatsLogger
import statsd
class StatsdStatsLogger(BaseStatsLogger):
def __init__(self, host='localhost', port=8088, prefix='superset'):
self.client = statsd.StatsClient(host, port, prefix)
def incr(self, stat, count=1):
self.client.incr(stat, count)
def timing(self, stat, timing):
self.client.timing(stat, timing)
STATS_LOGGER = StatsdStatsLogger()
working as a Charm
My React Code:
import React, { useEffect } from 'react';
import axios from 'axios';
import { embedDashboard } from '@superset-ui/embedded-sdk';
const Superset = () => {
const supersetUrl = 'http://localhost:8088';
const dashboardId = 'b4451485-3e76-404a-b2c0-aa467caef263';
//
useEffect(() => {
const getTokenAndEmbed = async () => {
try {
// 1. Login to Superset and get access token
const loginBody = {
username: 'superset',
password: 'superset',
provider: 'db',
refresh: true,
};
const loginResponse = await axios.post(
`${supersetUrl}/api/v1/security/login`,
loginBody,
{ headers: { 'Content-Type': 'application/json' } }
);
const accessToken = loginResponse.data.access_token;
// 2. Generate guest token with required fields
const now = Math.floor(Date.now() / 1000);
const guestTokenBody = {
user: {
username: 'enbed_user',
first_name: 'enbed_user',
last_name: 'enbed_user',
},
resources: [
{
type: 'dashboard',
id: dashboardId,
},
],
rls: [],
roles: ['ChartViewer'], // Must have dashboard access
iat: now,
exp: now + 60 * 60, // 1 hour expiry
aud: 'superset',
iss: 'superset-embed',
};
const guestTokenResponse = await axios.post(
`${supersetUrl}/api/v1/security/guest_token/`,
guestTokenBody,
{
headers: {
'Content-Type': 'application/json',
Authorization: `Bearer ${accessToken}`,
},
}
);
const guestToken = guestTokenResponse.data.token;
// 3. Embed the dashboard
await embedDashboard({
id: dashboardId,
supersetDomain: supersetUrl,
mountPoint: document.getElementById('superset-container'),
fetchGuestToken: () => guestToken,
dashboardUiConfig: { hideTitle: false },
});
// Optional styling
const iframe = document.querySelector('iframe');
if (iframe) {
iframe.style.width = '100%';
iframe.style.minHeight = '100vh';
}
} catch (error) {
console.error('Error embedding Superset dashboard:', error);
}
};
getTokenAndEmbed();
}, []);
return <div id="superset-container"></div>;
};
export default Superset;
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]