edit: patch XHR Request dengan coverage lebih luas dari monkeyPatchXML

This commit is contained in:
mario
2025-05-09 16:40:02 +07:00
parent 86ad0b38dd
commit 8d090fe19f
3 changed files with 25 additions and 7 deletions

View File

@@ -39,6 +39,15 @@ export default function initWADOImageLoader(
Accept: acceptHeader,
};
// // Patch Mario:
const authToken = sessionStorage.getItem('ohif-auth-token');
if (!authToken) {
window.location.href = '/login';
return;
}
xhrRequestHeaders.Authorization = `Bearer ${authToken}`;
if (headers) {
Object.assign(xhrRequestHeaders, headers);
}

View File

@@ -85,6 +85,14 @@ function createDicomWebApi(dicomWebConfig, servicesManager) {
if (authHeaders && authHeaders.Authorization) {
xhrRequestHeaders.Authorization = authHeaders.Authorization;
}
const authToken = sessionStorage.getItem('ohif-auth-token');
if (!authToken) {
window.location.href = '/login';
return;
}
xhrRequestHeaders.Authorization = `Bearer ${authToken}`;
return xhrRequestHeaders;
};

View File

@@ -38,7 +38,7 @@ import OpenIdConnectRoutes from './utils/OpenIdConnectRoutes';
import { ShepherdJourneyProvider } from 'react-shepherd';
function injectAuth() {
console.log("---> Inject Auth");
console.log('---> Inject Auth');
const originalXHROpen = XMLHttpRequest.prototype.open;
const originalXHRSend = XMLHttpRequest.prototype.send;
@@ -54,21 +54,22 @@ function injectAuth() {
XMLHttpRequest.prototype.send = function (body) {
this.setRequestHeader('Authorization', `Bearer ${authToken}`);
this.addEventListener('readystatechange', function () {
if (this.readyState === 4) { // DONE
if (this.readyState === 4) {
// DONE
try {
//check responseType ie json, and then check the auth response status
//redirect to custom login page if needed
console.log("response type :", this.responseType);
console.log("response :", this.response);
console.log("responseText :", this.responseText);
} catch (e) { }
console.log('response type :', this.responseType);
console.log('response :', this.response);
console.log('responseText :', this.responseText);
} catch (e) {}
}
});
return originalXHRSend.apply(this, arguments);
};
}
injectAuth();
// injectAuth();
let commandsManager: CommandsManager,
extensionManager: ExtensionManager,
servicesManager: AppTypes.ServicesManager,