Hi, I have the following problem. Аpparently the web viewer has some underlying network request that it is executing. Right now I have a React application and I have a Hoops viewer component that has a cadData prop. cadData is a url where you can download a scs file. This is my comopnent:
All my requests to the server have an authorization token, but now I notice that apparently the viewer also executes a request that returns me a 401 and means that it does not apply the headers.
Thank you for your reply. I have added the sessionToken to the web viewer config. But still I do not see the Authorization: Bearer ${token} in the headers of the request.
Thanks for providing additional clarification, @dayana
So I don’t think sessionToken is going to help in this scenario. Additionally, the WebViewer class does not have a comparable parameter for requestHeaders: {"Authorization": Bearer ${authToken}.
Indeed a fetch command is used to retrieve the SCS file. The WebViewer class doesn’t have a direct parameter for the authorization token. I’m not 100% on this – but I think you can try implementing a custom HTTP request (perhaps overriding the fetch function) that includes the necessary headers.
Hi @tino ,
Thanks for the quick reply. Yes, I would definitely like to try an override fetch. Do you have something in mind? Could you send me an example or at least the methods of this class bound to requests?
With the help of ChatGPT for prototyping, this is one potential example (but your mileage may vary):
const initViewer = (authToken) => {
// Intercept the original fetch function
const originalFetch = window.fetch;
// Override the fetch function to include authorization header
window.fetch = (url, options) => {
// If the URL matches the one you want to modify, add authorization header
if (url === 'http://localhost:11180/myStreamCacheFile.scs') {
options = options || {};
options.headers = options.headers || new Headers();
options.headers.append('Authorization', `Bearer ${authToken}`);
}
// Call the original fetch function with modified options
return originalFetch(url, options);
};
// Initialize the WebViewer
const hwvInstance = new window.Communicator.WebViewer({
containerId: "myViewer",
endpointUri: `http://localhost:11180/myStreamCacheFile.scs`,
});
// Optionally, restore the original fetch function when done
// window.fetch = originalFetch;
};
Thanks for the example, with a bit of processing on my part I was able to add the headers. However, overriding the fetch in this way should be careful as it may cause problems with other requests.