Unplanned
Last Updated: 13 Mar 2024 13:42 by Radu
Lukas
Created on: 24 Sep 2020 12:32
Type: Feature Request
14
Pass Bearer Token Authentication with Web Report Designer API Requests
Currently, the auth token is not yet passed from the client to the service. For that reason, it would be nice if the bearer token can be passed with the Web Report Designer API Requests.
7 comments
Radu
Posted on: 13 Mar 2024 13:42
Thank you Dimitar,
Your solution worked.
I used 

    $.ajaxSetup({
                headers: { "Authorization": "my token" }
            });
Thank you
ADMIN
Dimitar
Posted on: 12 Mar 2024 13:24

Hello Radu,

Thank you for sharing the solution with appending the Authorization header.

Regarding the 'Preview' mode, when the reports are previewed in the Web Report Designer, that happens through the built-in HTML5 Report Viewer. This report viewer, unlike the Web Report Designer, performs the requests using the jQuery.ajax() function so the solution for the Web Report Designer's requests is not viable for the report viewer.

The HTML5 Report Viewer exposes a property named authenticationToken - HTML5 Report Viewer Options Overview - Telerik Reporting, which you may use to set the token to the report viewer. It will automatically be passed with the requests that the viewer makes. However, with v17.1.23.718, there is no easy way to access the designer's internal report viewer.

My recommendation is to update to the latest version of the product - Telerik Reporting - ProgressĀ® TelerikĀ® Reporting 2024 Q1 (18.0.24.305) where the Web Report Designer now exposes an event through which you may configure the internal viewer's initialization options - viewerInitializing Event. Through this event, the viewer object can be accessed and you can thus set the token to its authenticationToken property, for example:

$(document).ready(function () {
    $("#webReportDesigner").telerik_WebReportDesigner({
        persistSession: false,
        toolboxArea: {
            layout: "list"
        },
        serviceUrl: "api/reportdesigner/",
        report: "Dashboard.trdp",
        // design/preview
        startMode: "design",
        viewerInitializing: onViewerInitializing
    }).data("telerik_WebReportDesigner");
});

function onViewerInitializing(e, args) {
    // e: jQuery event;
    // args: IViewerPreInitEventArgs ->
    //      reportViewerOptions: report viewer's options. All viewer's options available.

    args.reportViewerOptions.authenticationToken = "TOKEN"
}

If you do not wish to upgrade to the latest version and would prefer to use v17.1.23.718 version instead, it is possible to add custom headers, in this case the Authorization header, to each request made with $.ajax by using the $.ajaxSetup() function, e.g:

        $.ajaxSetup({
                headers: { "CustomHeader": "myValue" }
            });

I hope that at least one of the two approaches will work for your needs.

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/.
Radu
Posted on: 10 Mar 2024 13:55
Now the report Design is passing the authorization token to back-end correctly but when I go to the Preview area, it is not working because none of those requests pass through that function  window.fetch.
How can I pass the bearer token on preview - web design report requests ?
Radu
Posted on: 10 Mar 2024 08:25
The solution is to change this if 

else if (args.headers.entries) {
        args.headers.append("Authorization", 'Bearer ' + authData.token)
      }

Use append and it will work.
Radu
Posted on: 09 Mar 2024 15:05
Hi,

I am using Telerik.Reporting version 17.1.23.718
And this work-around doesn't fully work, some requests have Access Token and some don't.
For example 
/api/reportdesigner/reports/folders/contents 
/api/reportdesigner/datasources/folder/contents

doesn't have the Access Token and I have problems retrieving folders
another one that hasn't the access token is 
/api/reportdesigner/designerresources/js/webReportDesigner 
/api/reportdesigner/definitionresources/folder/model

BUT This 2 URL's have the Access token in the headers....
/api/reportdesigner/culturecontext /api/reportdesigner/typeSchemaCollection


At the moment I am desperate, I need to send the token for ALL requests so I can add the [Authorize] attribute to the controller.
I am using Aspn.Net WebApi ( not .net core )
ADMIN
Dimitar
Posted on: 07 Mar 2023 16:38

Hello,

We have received reports that the workaround shared by Eric might not work after upgrading to the Telerik Reporting R1 2023 release.

In order to make that approach work for version R1 2023+(17.0.23.118+), the fetch overriding code needs to be changed to the following:

                                const fetchOverride = window.fetch;
				window.fetch = function (url, args) {
					// Get the parameter in arguments
					if (!args) {
						args = {
							headers: {
								Authorization: 'Bearer ' + authData.token,
							},
						};
					} else if (!args.headers || !args.headers.entries) {
						args.headers = {
							Authorization: 'Bearer ' + authData.token,
						};
					} else if (args.headers.entries) {
						args.headers = { ...args.headers, Authorization: 'Bearer ' + authData.token };
					}
					// Intercept the parameter here
					return fetchOverride(url, args);
				};

Regards,
Dimitar
Progress Telerik

Brand new Telerik Reporting course in Virtual Classroom - the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products. Check it out at https://learn.telerik.com/.
ADMIN
Eric R | Senior Technical Support Engineer
Posted on: 17 Mar 2021 20:15

Hi Lukas,

Until this gets implemented, I wanted to provide your work around for anyone else that may come across the same issue as it has been appearing more often.

The following code will add the authentication header to each request using the jQuery.ajaxPrefilter() event. 

jQuery.ajaxPrefilter(function (options, originalOptions, jqXHR) {
			jqXHR.setRequestHeader('Authorization', 'Bearer ' + authData.token);
		});

		// overload the fetch method
		const fetchOverride = window.fetch;
		window.fetch = function (url, args) {
			// Get the parameter in arguments
			if (!args) {
				args = {
					headers: {
						Authorization: 'Bearer ' + authData.token
					}
				};
			} else if (!args.headers) {
				args.headers = {
					Authorization: 'Bearer ' + authData.token
				};
			} else {
				args.headers.Authorization = 'Bearer ' + authData.token;
			}

			// Intercept the parameter here
			return fetchOverride(url, args);
		};

Thank you for your patience and understanding while we work to implement this.

Regards,


Eric R | Senior Technical Support Engineer
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.