JWT Token with Iframe
Summary: rudyfranco provided a detailed explanation on embedding a Sisense dashboard into an iFrame using a JWT token for authentication. They described the process of setting the iFrame's source to the instance URL with the JWT token, and ensuring that the dashboard loads after authentication via the OnLoad handler. They also shared a code snippet to generate the JWT token, noting the importance of having documentation for this process. No further responses added additional information on this topic.
Hi Team
I am trying to find out a doc that can explain how JWT token works with iframe?
If there is any code snippet to generate JWT token exists somewhere, please let me know as well
ramansingh89
Posted 2 years ago·Last reply 1 year ago
7 comments
DRay
·1 year agoHello @ramansingh89,
I wanted to follow up to see if any of the solutions offered worked for you.
If so, please click the 'Accept as Solution' button on the appropriate post so other users with the same questions can find the answer. If not, please let us know so that we can continue to help.
Thank you.
DRay
·2 years agoHello @ramansingh89,
I wanted to follow up to see if any of the solutions offered worked for you.
If so, please click the 'Accept as Solution' button on the appropriate post so other users with the same questions can find the answer. If not, please let us know so that we can continue to help.
Thank you.
DRay
·2 years agoHello ramansingh89 ,
I wanted to follow up to see if any of the solutions offered worked for you.
If so, please click the 'Accept as Solution' button on the appropriate post so other users with the same questions can find the answer. If not, please let us know so that we can continue to help.
Thank you.
rudyfranco
·2 years ago · EditedI haven't come across any documentation specific to what you're asking for here. But it would have been nice when I went this route, so there's definitely a need for it.
When I embedded a Sisense dashboard into an iFrame, I first set the iFrames SRC to the instance URL with the JWT token as part of the query string: i.e. https://path.toSisenseInstance.com/jwt?jwt=YOUR_TOKEN_HERE
In the iFrames OnLoad handler, I navigate the frame to the dashboard to be displayed. So essentially what happens is you hit the page, the iFrame makes its first call to the server with your token which authenticates it. Once that page loads, OnLoad is fired, which loads up the dashboard in the iFrame now that you're authenticated.
There's lots of examples for creating a JWT token online but here's a quick one. You'd just take this string value and place it in the query string that you first navigate to.
private string GenerateSisenseAuthToken()
{
string sharedKey = GetSharedSecret(); // This is the shared key configured in Sisense
var securityKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(sharedKey));
var credentials = new SigningCredentials(securityKey, "HS256");
var header = new JwtHeader(credentials);
var user = GetUserName(); // MyUser@example.com
TimeSpan timeSinceEpoch = (_dateTimeProvider.UtcNow - new DateTime(1970, 1, 1));
int secondsSinceEpoch = (int)timeSinceEpoch.TotalSeconds;
var payload = new JwtPayload
{
{ "iat", secondsSinceEpoch},
{ "sub", user },
{ "jti", Guid.NewGuid().ToString() }
};
var secToken = new JwtSecurityToken(header, payload);
var handler = new JwtSecurityTokenHandler();
return handler.WriteToken(secToken);
}