Introduction #
Single-page embedding is the recommended method for embedding authenticated SmartChart reports into third-party systems. Using SHA1-encrypted tokens, external systems can generate one-time valid report URLs and embed them directly via iframe — no user login required. Compared to simple embedding, this method allows precise control over which users can access which reports, and supports data permission parameters.
Embed a Report #
Similar to SSO, but specifically for report embedding (requires SmartChart v5.3.11+):
URL: '/echart/?type={reportName}&visitor={visitor}&token={token}&stamp={stamp}'
Parameters:
reportName: Report name or report ID
visitor: Username (managed in SmartChart platform)
stamp: Timestamp (milliseconds since Jan 1, 1970)
token: SHA1 encrypted, token = SHA1(link_key + stamp + visitor + reportName)
Username and key configuration: see Data Service API config
You also need to add the visitor to the report’s view permissions.
Python Example #
import time
import hashlib
import os
SMART_CHART_URL = 'http://127.0.0.1:8000'
reportID = 'reportID'
LOGIN_URL = SMART_CHART_URL + '/echart/?type={reportID}&visitor={visitor}&token={token}&stamp={stamp}'
TOKEN = 'link_key'
def get_smarturl(username, reportName):
stamp = int(time.time() * 1000)
visitor = username
res = TOKEN + str(stamp) + visitor + reportID
token = hashlib.sha1(res.encode('utf-8')).hexdigest()
VISIT_DICT = {
"visitor": id,
"stamp": stamp,
"token": token,
"reportID": reportName
}
visit_url = LOGIN_URL.format(**VISIT_DICT)
return visit_url
Data Permission Encryption #
For data permission control, pass an "id" parameter:
/echart/?type=xxx&visitor=xx&token=xx&stamp=xxxxx&id=xxx
The backend converts this id to "_id" parameter for data permission filtering.
Encryption must include id: token = SHA1(link_key + stamp + visitor + reportName + id)
Full Parameter Encryption #
To include parameters in the authentication, rename "param" to "params":
'/echart/?type={reportName}&visitor={visitor}&token={token}&stamp={stamp}¶ms=xxxx'
Encryption includes params: token = SHA1(link_key + stamp + visitor + reportName + '{"a":"1","b":2"}')