Unplanned
Last Updated: 07 Mar 2023 16:38 by ADMIN
Lukas
Created on: 24 Sep 2020 12:32
Type: Feature Request
12
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.
2 comments
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/.