Forum Discussion

ramansingh89's avatar
04-12-2024

JWT Token with Iframe

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

7 Replies

  • I 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(); // [email protected]

    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);
    }

    • Hi DRay does setting up JWT process requires an active sisense user? example JWT can update or create users in Sisense, but does JWT uses a 'user profile' to make those actions or its all done through the shared secret?

  • Hello 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.

  • Hello @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.

  • Hello @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.