In my JavaScript code, I am currently loading an image using the following method:
var img = new Image();
img.onload = function () {
..
};
img.src = src;
However, I have recently realized that I need to secure the images on my server side with OAuth 2, just like the rest of my application. This means that I will receive a 401 Unauthorized error when trying to load the images.
My application is built using Angular and I have an interceptor set up to add the Authorization header to all service requests made through Angular. But in this case, since the image call is not made within an Angular context, the interceptor is not applied.
Does anyone have any suggestions for how I can add the Authorization header to the get request for the image?