I have integrated Superset dashboards into my application via the embedded sdk following well the whole process to generate the guest token.
However, I’ve noticed that during the access token generation step, I receive a refresh token, but it doesn’t tell me how and when to use this refresh token. This means that if the access token expires, my guest token automatically expires, causing the dashboard to disconnect from my app.
Can anyone give me advice on how to implement refresh token functionality specifically for Superset dashboards ?
/**
* @Route("/guest_token/{id_dashboard}", name="superset_generate_token")
*/
public function generateTokenAction(Request $request, $id = null): Response
{
//Get Login Token//
$baseUrl = 'http://supersetdomain.com:8088/';
//Get Dashboard by id and id_customer into order to get Code Embedded//
$dashboard = $supersetDashboardRepo->find($id);
$dashboard_embeddedCode = $dashboard->getEmbeddedCode();
$urlLogin = $baseUrl . 'api/v1/security/login';
$payloadLogin = [
'username' => username,
'password' => password,
'provider' => 'db',
'refresh' => true
];
$dataLoginToken = $this->curlRequest($urlLogin, ['Content-Type:application/json'], 'POST', $payloadLogin);
$accessToken = $dataLoginToken['access_token'];
//Get CSRF Token//
$urlCsrf = $baseUrl . 'api/v1/security/csrf_token/';
$dataCsrfToken = $this->curlRequest($urlCsrf, ['Authorization: Bearer ' . $accessToken]);
$csrfToken = $dataCsrfToken['result'];
//Get Guest Token//
$urlGuestToken = $baseUrl . 'api/v1/security/guest_token/';
$payloadGuestToken= [
'user' => [
'username' => username,
'first_name' => first_name,
'last_name' => last_name,
],
"resources" => [
[
"type" => "dashboard",
"id" => $dashboard_embeddedCode
]
],
"rls" => []
];
$headersGuestToken = [
'X-CSRF-Token: '. $csrfToken,
'Content-Type: application/json',
'Authorization: Bearer ' . $accessToken
];
$dataGuestToken = $this->curlRequest($urlGuestToken, $headersGuestToken, 'POST', $payloadGuestToken);
$guestToken = $dataGuestToken['token'];
$this->get('session')->set('guest', $guestToken);
$this->get('session')->set('csrf', $csrfToken);
return new Response(json_encode([
'embeddedCode' => $dashboard_embeddedCode,
'guest_token' => $guestToken
]));
}
supersetEmbeddedSdk.embedDashboard({
id: data.embeddedCode, // given by the Superset embedding UI
supersetDomain: "supersetdomain.com:8088/",
mountPoint: containerDashboard, // any html element that can contain an iframe
fetchGuestToken: () => data.guest_token,
dashboardUiConfig: {}, // dashboard UI config: hideTitle, hideTab, hideChartControls (optional)
})
Dashboard run correctly, but after token expire it disconnect.
El Simple is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.