mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2026-09-09 18:03:21 +00:00
[AAE-12501] Comment temporary setCsrfToken because is not possible to import app config service from core due to circular dependencies
This commit is contained in:
@@ -42,7 +42,7 @@ import { AlfrescoApiParamEncoder } from './alfresco-api/alfresco-api.param-encod
|
|||||||
import { AlfrescoApiResponseError } from './alfresco-api/alfresco-api.response-error';
|
import { AlfrescoApiResponseError } from './alfresco-api/alfresco-api.response-error';
|
||||||
import { Constructor } from './types';
|
import { Constructor } from './types';
|
||||||
import { RequestOptions, SecurityOptions } from './interfaces';
|
import { RequestOptions, SecurityOptions } from './interfaces';
|
||||||
import { AppConfigService, AppConfigValues } from '../../../src/lib/app-config/app-config.service';
|
// import { AppConfigService, AppConfigValues } from '../../../src/lib/app-config/app-config.service';
|
||||||
import ee, { Emitter } from 'event-emitter';
|
import ee, { Emitter } from 'event-emitter';
|
||||||
|
|
||||||
export interface Emitters {
|
export interface Emitters {
|
||||||
@@ -67,7 +67,9 @@ export class AdfHttpClient implements ee.Emitter,JsApiHttpClient {
|
|||||||
defaultHeaders: {}
|
defaultHeaders: {}
|
||||||
};
|
};
|
||||||
|
|
||||||
constructor(private httpClient: HttpClient, private appConfig: AppConfigService) {
|
constructor(private httpClient: HttpClient
|
||||||
|
// private appConfig: AppConfigService
|
||||||
|
) {
|
||||||
ee(this);
|
ee(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -262,31 +264,31 @@ export class AdfHttpClient implements ee.Emitter,JsApiHttpClient {
|
|||||||
...((options.contentType) && {'Content-Type': options.contentType})
|
...((options.contentType) && {'Content-Type': options.contentType})
|
||||||
};
|
};
|
||||||
|
|
||||||
const disableCsrf = this.appConfig.get<boolean>(AppConfigValues.DISABLECSRF);
|
// const disableCsrf = this.appConfig.get<boolean>(AppConfigValues.DISABLECSRF);
|
||||||
|
|
||||||
if (!disableCsrf) {
|
// if (!disableCsrf) {
|
||||||
this.setCsrfToken(optionsHeaders);
|
// this.setCsrfToken(optionsHeaders);
|
||||||
|
|
||||||
}
|
// }
|
||||||
|
|
||||||
return new HttpHeaders(optionsHeaders);
|
return new HttpHeaders(optionsHeaders);
|
||||||
}
|
}
|
||||||
|
|
||||||
private setCsrfToken(optionsHeaders: any) {
|
// private setCsrfToken(optionsHeaders: any) {
|
||||||
const token = this.createCSRFToken();
|
// const token = this.createCSRFToken();
|
||||||
optionsHeaders['X-CSRF-TOKEN'] = token;
|
// optionsHeaders['X-CSRF-TOKEN'] = token;
|
||||||
|
|
||||||
try {
|
// try {
|
||||||
document.cookie = 'CSRF-TOKEN=' + token + ';path=/';
|
// document.cookie = 'CSRF-TOKEN=' + token + ';path=/';
|
||||||
} catch (err) {
|
// } catch (err) {
|
||||||
/* continue regardless of error */
|
// /* continue regardless of error */
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
|
||||||
private createCSRFToken(a?: any): string {
|
// private createCSRFToken(a?: any): string {
|
||||||
const randomValue = window.crypto.getRandomValues(new Uint32Array(1))[0];
|
// const randomValue = window.crypto.getRandomValues(new Uint32Array(1))[0];
|
||||||
return a ? (a ^ ((randomValue * 16) >> (a / 4))).toString(16) : ([1e16] + (1e16).toString()).replace(/[01]/g, this.createCSRFToken);
|
// return a ? (a ^ ((randomValue * 16) >> (a / 4))).toString(16) : ([1e16] + (1e16).toString()).replace(/[01]/g, this.createCSRFToken);
|
||||||
}
|
// }
|
||||||
|
|
||||||
private static getResponseType(options: RequestOptions): 'blob' | 'json' | 'text' {
|
private static getResponseType(options: RequestOptions): 'blob' | 'json' | 'text' {
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user