edit: patch XHR Request dengan coverage lebih luas dari monkeyPatchXML
This commit is contained in:
@@ -102,8 +102,20 @@ export const studyDataForOverlayItem = (studyInstanceUID: string) => {
|
|||||||
try {
|
try {
|
||||||
const qidoRootUrl = getQidoRootUrl();
|
const qidoRootUrl = getQidoRootUrl();
|
||||||
|
|
||||||
|
// Get the authentication token from session storage
|
||||||
|
const authToken = window.sessionStorage.getItem('ohif-auth-token');
|
||||||
|
|
||||||
|
// Create request headers with Authorization if token exists
|
||||||
|
const headers: HeadersInit = {};
|
||||||
|
if (authToken) {
|
||||||
|
headers['Authorization'] = `Bearer ${authToken}`;
|
||||||
|
}
|
||||||
|
|
||||||
const response = await fetch(
|
const response = await fetch(
|
||||||
`${qidoRootUrl}/studies?limit=101&offset=0&fuzzymatching=false&includefield=00080050,00081030,00101010,0010004&StudyInstanceUID=${studyInstanceUID}`
|
`${qidoRootUrl}/studies?limit=101&offset=0&fuzzymatching=false&includefield=00080050,00081030,00101010,0010004&StudyInstanceUID=${studyInstanceUID}`,
|
||||||
|
{
|
||||||
|
headers,
|
||||||
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
|
|||||||
@@ -39,6 +39,15 @@ export default function initWADOImageLoader(
|
|||||||
Accept: acceptHeader,
|
Accept: acceptHeader,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// // Patch Mario:
|
||||||
|
const authToken = sessionStorage.getItem('ohif-auth-token');
|
||||||
|
if (!authToken) {
|
||||||
|
window.location.href = '/login';
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
xhrRequestHeaders.Authorization = `Bearer ${authToken}`;
|
||||||
|
|
||||||
if (headers) {
|
if (headers) {
|
||||||
Object.assign(xhrRequestHeaders, headers);
|
Object.assign(xhrRequestHeaders, headers);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -85,6 +85,14 @@ function createDicomWebApi(dicomWebConfig, servicesManager) {
|
|||||||
if (authHeaders && authHeaders.Authorization) {
|
if (authHeaders && authHeaders.Authorization) {
|
||||||
xhrRequestHeaders.Authorization = 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;
|
return xhrRequestHeaders;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ import OpenIdConnectRoutes from './utils/OpenIdConnectRoutes';
|
|||||||
import { ShepherdJourneyProvider } from 'react-shepherd';
|
import { ShepherdJourneyProvider } from 'react-shepherd';
|
||||||
|
|
||||||
function injectAuth() {
|
function injectAuth() {
|
||||||
console.log("---> Inject Auth");
|
console.log('---> Inject Auth');
|
||||||
const originalXHROpen = XMLHttpRequest.prototype.open;
|
const originalXHROpen = XMLHttpRequest.prototype.open;
|
||||||
const originalXHRSend = XMLHttpRequest.prototype.send;
|
const originalXHRSend = XMLHttpRequest.prototype.send;
|
||||||
|
|
||||||
@@ -54,21 +54,22 @@ function injectAuth() {
|
|||||||
XMLHttpRequest.prototype.send = function (body) {
|
XMLHttpRequest.prototype.send = function (body) {
|
||||||
this.setRequestHeader('Authorization', `Bearer ${authToken}`);
|
this.setRequestHeader('Authorization', `Bearer ${authToken}`);
|
||||||
this.addEventListener('readystatechange', function () {
|
this.addEventListener('readystatechange', function () {
|
||||||
if (this.readyState === 4) { // DONE
|
if (this.readyState === 4) {
|
||||||
|
// DONE
|
||||||
try {
|
try {
|
||||||
//check responseType ie json, and then check the auth response status
|
//check responseType ie json, and then check the auth response status
|
||||||
//redirect to custom login page if needed
|
//redirect to custom login page if needed
|
||||||
console.log("response type :", this.responseType);
|
console.log('response type :', this.responseType);
|
||||||
console.log("response :", this.response);
|
console.log('response :', this.response);
|
||||||
console.log("responseText :", this.responseText);
|
console.log('responseText :', this.responseText);
|
||||||
} catch (e) { }
|
} catch (e) {}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
return originalXHRSend.apply(this, arguments);
|
return originalXHRSend.apply(this, arguments);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
injectAuth();
|
// injectAuth();
|
||||||
let commandsManager: CommandsManager,
|
let commandsManager: CommandsManager,
|
||||||
extensionManager: ExtensionManager,
|
extensionManager: ExtensionManager,
|
||||||
servicesManager: AppTypes.ServicesManager,
|
servicesManager: AppTypes.ServicesManager,
|
||||||
|
|||||||
Reference in New Issue
Block a user