Need a special offer?Find out if your project fits.
+

Authorization headers with AngularJS

Answered
Dominik Crnojevac asked on March 31, 2020

Flexmonster version: 2.8.3
The datasource type is 'microsoft analysis services' which are being proxy handled by our own server in the middle, i.e. client -> server -> cube. The problem that I am having is I cannot successfully place an authorization header to authorize requests the component is making to the server. From what I learned there are 2 ways to acomplish that:

  1. customizeAPIRequest function: I tried setting that trough the directive parameter and through the Flexmonster API and in both cases I debugged the source code and confirmed my function is being passed to Flexmonster. The problem is my function is never being called and thus no headers are modified.
  2. dataSource.requestHeaders: I tried settings this property and this does place the headers on the requests, but the problem with that is that it doubles all headers I define there. For example, if I put headerX in there I get two headerX's with the same value while debugging source code. The result of this doubling is having 'headerX: headerXValue, headerXValue' in the request.

5 answers

Public
Illia Yatsyshyn Illia Yatsyshyn Flexmonster April 1, 2020

Hello, Dominik,
 
Thank you for reaching out to us.
 
We would like to kindly inform you that the customizeAPIRequest method is responsible for the customization of requests when the custom data source API is used and should not be used if the data source is Microsoft Analysis Services.
 
As for doubling of the request header, we have reproduced the issue on our side. Such a behavior is not expected and will be fixed with the nearest minor update ETA Apr 06. We will keep you posted with any updates on this point.
 
However, our team would like to kindly inform you that there is a better approach for the authorization with SSAS XMLA connection. It is due to the fact that starting with version 2.8.3 the withCredentials property is added. It allows passing built-in authorization headers in case the user is logged in using the Basic/Windows authorization.
 
In order to allow using such authorization headers, the value of the mentioned property should be set to true.
 
More information about the dataSource object and its properties (including withCredentials) in our documentation.
 
We hope it helps.
Please contact us in case of additional questions.
 
Best regards,
Illia

Public
Dominik Crnojevac April 1, 2020

Ah I see, thank you for the fast response.
 
Best regards,
Dominik

Public
Illia Yatsyshyn Illia Yatsyshyn Flexmonster April 7, 2020

Hello,
 
We are glad to announce that for SSAS XMLA connection the issue with duplicating `requstHeaders` for the first request was fixed.
 
This is included in the 2.8.4 version of Flexmonster: https://www.flexmonster.com/release-notes/
 
You are welcome to update the component.

Here is our updating to the latest version guide for assistance: https://www.flexmonster.com/doc/updating-to-the-latest-version/ 
 
Please let us know if everything works.
 
Best regards,
Illia

Public
Dominik Crnojevac April 9, 2020

So I updated to new version and the request headers now work. This is all well and good now for reports that I pass to the component from my code. I am having now difficulties when a user loads their own report through the toolbar. In this case I would like to attach some request headers on their loaded report before it starts to load. I tried many events to get to where I want to be, only to find that I can't get the report object, since flexmonster.getReport() returns a null until the data is loaded (as far as I understand). I tried getting calling it from the pivotInstance.getReport(), but I think this may be the same. So my question is, is there any way to modify the loaded report before it starts loading?

Best regards,
Dominik

Public
Illia Yatsyshyn Illia Yatsyshyn Flexmonster April 13, 2020

Hello, Dominik,
 
Thank you for your question.
 
Our team would like to kindly inform you that the report object can not be accessed before it is fully loaded on the page. Therefore, we would like to kindly recommend the following workaround:
 
It is possible to open the local report file or load it from the specified URL to the page using any approach provided by JavaScript. Next, it can be parsed to JSON, modified in the desired way (adding of request headers), and passed to Flexmonster as an inline report object using the setReport() method.
 
We have prepared an example demonstrating the described approach for opening the locally saved report. You are welcome to check it out by the link: https://jsfiddle.net/flexmonster/8mevyjsr/.
 
In case the report needs to be loaded from the remote file, Ajax call can be used in order to load the file on the page. Next, the data can be parsed to JSON and modified in the same way as described above.
 
In case the original "Open" tab of the Toolbar needs to be replaced with newly created controls, we recommend checking out our tutorial dedicated to the Toolbar customization: https://www.flexmonster.com/doc/customizing-toolbar/.
 
Finally, our team would like to kindly draw your attention to the withCredentials property, which allows passing built-in authorization headers in case the user is logged in using the Basic/Windows authorization. The advantage of such an approach is that such property will be saved in the report and included in the object returned by the getReport API.
 
We hope it helps.
Do not hesitate to contact us in case additional questions occur.
 
Best regards,
Illia

Please login or Register to Submit Answer