diff --git a/demo-shell/src/app/app.module.ts b/demo-shell/src/app/app.module.ts index c736763b8c..63f9ccc4e4 100644 --- a/demo-shell/src/app/app.module.ts +++ b/demo-shell/src/app/app.module.ts @@ -20,7 +20,7 @@ import { APP_INITIALIZER, NgModule } from '@angular/core'; import { FormsModule, ReactiveFormsModule } from '@angular/forms'; import { FlexLayoutModule } from '@angular/flex-layout'; import { ChartsModule } from 'ng2-charts'; -import { HttpClientModule, HTTP_INTERCEPTORS } from '@angular/common/http'; +import { HttpClientModule } from '@angular/common/http'; import { BrowserAnimationsModule, NoopAnimationsModule } from '@angular/platform-browser/animations'; import { TranslateModule } from '@ngx-translate/core'; import { @@ -28,8 +28,7 @@ import { TRANSLATION_PROVIDER, DebugAppConfigService, CoreModule, - CoreAutomationService, - AuthBearerInterceptor + CoreAutomationService } from '@alfresco/adf-core'; import { ExtensionsModule } from '@alfresco/adf-extensions'; import { AppComponent } from './app.component'; @@ -209,10 +208,6 @@ registerLocaleData(localeSv); SearchFilterChipsComponent ], providers: [ - { - provide: HTTP_INTERCEPTORS, useClass: - AuthBearerInterceptor, multi: true - }, { provide: AppConfigService, useClass: DebugAppConfigService }, // not use this service in production { provide: TRANSLATION_PROVIDER, diff --git a/lib/core/src/lib/services/auth-bearer.interceptor.ts b/lib/core/src/lib/services/auth-bearer.interceptor.ts index 9c82c2eecc..3a763cea9c 100644 --- a/lib/core/src/lib/services/auth-bearer.interceptor.ts +++ b/lib/core/src/lib/services/auth-bearer.interceptor.ts @@ -27,14 +27,13 @@ import { catchError, mergeMap } from 'rxjs/operators'; @Injectable() export class AuthBearerInterceptor implements HttpInterceptor { private excludedUrlsRegex: RegExp[]; - private authService: AuthenticationService; - constructor(private injector: Injector) { } + constructor(private injector: Injector, private authService: AuthenticationService) { } private loadExcludedUrlsRegex() { const excludedUrls: string[] = this.authService.getBearerExcludedUrls(); - this.excludedUrlsRegex = excludedUrls.map((urlPattern) => new RegExp(urlPattern, 'gi')) || []; + this.excludedUrlsRegex = [...excludedUrls].map((urlPattern) => new RegExp(urlPattern, 'i')) || []; } intercept(req: HttpRequest, next: HttpHandler): @@ -51,7 +50,7 @@ export class AuthBearerInterceptor implements HttpInterceptor { } const urlRequest = req.url; - const shallPass: boolean = !!this.excludedUrlsRegex.find((regex) => regex.test(urlRequest)); + const shallPass: boolean = this.excludedUrlsRegex.some((regex) => regex.test(urlRequest)); if (shallPass) { return next.handle(req) .pipe( @@ -73,7 +72,19 @@ export class AuthBearerInterceptor implements HttpInterceptor { } private appendJsonContentType(headers: HttpHeaders): HttpHeaders { - return headers.set('Content-Type', 'application/json;charset=UTF-8'); + + // prevent adding any content type, to properly handle formData with boundary browser generated value, + // as adding any Content-Type its going to break the upload functionality + + if (headers.get('Content-Type') === 'multipart/form-data') { + return headers.delete('Content-Type'); + } + + if (!headers.get('Content-Type')) { + return headers.set('Content-Type', 'application/json;charset=UTF-8'); + } + + return headers; } }