Articles in this section
Category / Section

How can the widgets be hidden in the embedded dashboards based on the user logged-in to the embedded application?

Published:

When embedding the dashboard, there may be a situation to show or hide specific widgets based on the user’s role or permissions. This article outlines how to dynamically hide widgets in embedded dashboards using query parameters in JavaScript embedding.

Using the embed_exclude_widgets Query Parameter

To control the visibility of widgets, you can use the embed_exclude_widgets query parameter. This parameter allows you to specify the IDs of the widgets you want to exclude from the dashboard when it is rendered within your application.

Implementing Widget Exclusion in Authorization Server API

The following C# example demonstrates how to append the embed_exclude_widgets parameter to the query string in your Authorization Server REST API:

public string AuthorizationServer([FromBody] object embedQueryString)
{
    var embedClass = Newtonsoft.Json.JsonConvert.DeserializeObject<EmbedClass>(embedQueryString.ToString());
    var embedQuery = embedClass.embedQueryString;

    embedQuery += "&embed_user_email=" + GlobalAppSettings.EmbedDetails.UserEmail;

    double timeStamp = (int)DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1)).TotalSeconds;
    embedQuery += "&embed_server_timestamp=" + timeStamp;

    // Specify the widget IDs to exclude
    embedQuery += "&embed_excluded_widgets=['WidgetID1','WidgetID2','WidgetID3']";

    var embedDetailsUrl = "/embed/authorize?" + embedQuery + "&embed_signature=" + GetSignatureUrl(embedQuery);

    using (var client = new HttpClient())
    {
        client.BaseAddress = new Uri(embedClass.dashboardServerApiUrl);
        client.DefaultRequestHeaders.Accept.Clear();
        var result = client.GetAsync(embedClass.dashboardServerApiUrl + embedDetailsUrl).Result;
        string resultContent = result.Content.ReadAsStringAsync().Result;

        return resultContent;
    }
}

Replace 'WidgetID1', 'WidgetID2', 'WidgetID3' with the actual widget IDs you wish to exclude.

image.png

Obtaining the Widget IDs

You can use the REST API in order to obtain the widget IDs. This API should give you a list of all widgets available on a dashboard. You can then use this information to dynamically set the embed_exclude_widgets parameter based on the user’s login information.

Conclusion

By leveraging the embed_exclude_widgets query parameter and integrating it with your Authorization Server API, you can create a more personalized and secure user experience in your embedded dashboards. Ensure that you have the correct widget IDs and implement the necessary logic to determine which widgets to exclude for each user.

Additional References

Was this article useful?
Like
Dislike
Help us improve this page
Please provide feedback or comments
SM
Written by Soundarya Mani Meharan
Updated
Comments (0)
Please  to leave a comment
Access denied
Access denied