Is there any way to add token to template resource request?

1 Answer 124 Views
General Discussions
son
Top achievements
Rank 1
Iron
Iron
son asked on 13 Feb 2023, 04:56 AM

I reached that Telerik itself call a request to get template in like (resources/templates/telerikReportViewerTemplate-16.1.22.511.html/), cache it, without attach any token to authen. The problem is, my service required any request to host ServiceUrl must be authen, in that case I must include a token to header.

 

Do you guys have any idea for that thing?

Thanks.

Son Dang

1 Answer, 1 is accepted

Sort by
0
Accepted
Dimitar
Telerik team
answered on 15 Feb 2023, 01:27 PM

Hello Son,

Indeed, by default, the templated is retrieved internally via a request to the service, unless the templateUrl property of the Report Viewer object has been set, you may find more information about this in the Report Viewer Initialization - Telerik Reporting article.

The Report Viewer also has the authenticationToken property which is usually used to pass the authentication token, however, we currently do not pass it for the request about the template. Thus, in order to pass an authentication token with the template request, you have to use a workaround where the authentication header is added 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);
		};

I hope this workaround will help, please do not hesitate to let me know if you have any other questions or if you need further assistance.

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/.
son
Top achievements
Rank 1
Iron
Iron
commented on 27 Mar 2023, 02:29 AM

Thanks for your answer, I have solution for my project, I'm so appreciative.

 

one again, thank you.

Tags
General Discussions
Asked by
son
Top achievements
Rank 1
Iron
Iron
Answers by
Dimitar
Telerik team
Share this question
or