|
|
@ -10,21 +10,26 @@ export class OpenProjectHeaderInterceptor implements HttpInterceptor { |
|
|
|
intercept(req:HttpRequest<any>, next:HttpHandler):Observable<HttpEvent<any>> { |
|
|
|
intercept(req:HttpRequest<any>, next:HttpHandler):Observable<HttpEvent<any>> { |
|
|
|
const csrf_token:string|undefined = jQuery('meta[name=csrf-token]').attr('content'); |
|
|
|
const csrf_token:string|undefined = jQuery('meta[name=csrf-token]').attr('content'); |
|
|
|
|
|
|
|
|
|
|
|
let newHeaders = req.headers |
|
|
|
if (req.withCredentials !== false) { |
|
|
|
.set('X-Authentication-Scheme', 'Session') |
|
|
|
|
|
|
|
.set('X-Requested-With', 'XMLHttpRequest'); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (csrf_token) { |
|
|
|
let newHeaders = req.headers |
|
|
|
newHeaders = newHeaders.set('X-CSRF-TOKEN', csrf_token); |
|
|
|
.set('X-Authentication-Scheme', 'Session') |
|
|
|
} |
|
|
|
.set('X-Requested-With', 'XMLHttpRequest'); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (csrf_token) { |
|
|
|
|
|
|
|
newHeaders = newHeaders.set('X-CSRF-TOKEN', csrf_token); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Clone the request to add the new header
|
|
|
|
// Clone the request to add the new header
|
|
|
|
const clonedRequest = req.clone({ |
|
|
|
const clonedRequest = req.clone({ |
|
|
|
withCredentials: true, |
|
|
|
withCredentials: true, |
|
|
|
headers: newHeaders |
|
|
|
headers: newHeaders |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Pass the cloned request instead of the original request to the next handle
|
|
|
|
|
|
|
|
return next.handle(clonedRequest); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Pass the cloned request instead of the original request to the next handle
|
|
|
|
return next.handle(req); |
|
|
|
return next.handle(clonedRequest); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|