Setting Report Parameter from JWT Token Value

1 Answer 78 Views
Report Parameters
Jonathan
Top achievements
Rank 1
Jonathan asked on 26 Jun 2023, 02:54 AM

On all of our reports we have a `CustomerId` and `UserId` that are part of our JWT token, this is what our reports controller looks like 


[Route("api/[controller]")]
[Authorize]
[ApiController]
public class ReportsController : ReportsControllerBase
{
    public ReportsController(IReportServiceConfiguration reportServiceConfiguration)
        : base(reportServiceConfiguration)
    {
    }
}

 

So how can we set the CustomerId and UserId on the server side?  We call our client side code like this:


$("#reportViewer1")
                    .telerik_ReportViewer({
                        serviceUrl:  "/api/reports/",
                        authenticationToken: token,
                        viewMode: "PRINT_PREVIEW",
                        
                        reportSource: {                            
                            report: fileName + ".trdp",

                            parameters: postData
                        },
                        //sendEmail: { enabled: true },
                    });


How can we set the token on the server side?

1 Answer, 1 is accepted

Sort by
0
Dimitar
Telerik team
answered on 28 Jun 2023, 01:14 PM

Hello Jonathan,

Thank you for the provided information!

You may override the GetParameters(String, ClientReportSource) endpoint of the reports controller in order to add a new value to the report parameter values dictionary in the second argument of the method, for example:

        public override IActionResult GetParameters(string clientID, [FromBody] ClientReportSource reportSource)
        {
            reportSource.ParameterValues.Add("Parameter1", "Test");
            return base.GetParameters(clientID, reportSource);
        }

Alternatively, you could also create a custom implementation of the IReportSourceResolver interface and in the Resolve method, you may use the dictionary of current parameter values passed as the last argument to add your JWT value to the corresponding report parameter.

For details on how to implement and use custom resolvers, please refer to the Using Custom ReportSource Resolver and Custom ReportDocument Resolver - Telerik Reporting article.

I hope this will help, let me know if you have additional questions.

Regards,
Dimitar
Progress Telerik

Stay tuned by visiting our roadmap and feedback portal pages, enjoy a smooth take-off with our Getting Started resources, or visit the free self-paced technical training at https://learn.telerik.com/.
Tags
Report Parameters
Asked by
Jonathan
Top achievements
Rank 1
Answers by
Dimitar
Telerik team
Share this question
or