diff --git a/demo-shell/src/app/app.module.ts b/demo-shell/src/app/app.module.ts index ea808c5f2e..eb4cd99688 100644 --- a/demo-shell/src/app/app.module.ts +++ b/demo-shell/src/app/app.module.ts @@ -23,7 +23,7 @@ import { ChartsModule } from 'ng2-charts'; import { HttpClientModule, HTTP_INTERCEPTORS } from '@angular/common/http'; import { BrowserAnimationsModule, NoopAnimationsModule } from '@angular/platform-browser/animations'; -import { AppConfigService, TRANSLATION_PROVIDER, DebugAppConfigService, CoreModule, CoreAutomationService } from '@alfresco/adf-core'; +import { AppConfigService, TRANSLATION_PROVIDER, DebugAppConfigService, CoreModule, CoreAutomationService, AuthBearerInterceptor } from '@alfresco/adf-core'; import { ExtensionsModule } from '@alfresco/adf-extensions'; import { AppComponent } from './app.component'; import { MaterialModule } from './material.module'; @@ -61,7 +61,6 @@ import { MonacoEditorModule } from 'ngx-monaco-editor'; import { ContentModule } from '@alfresco/adf-content-services'; import { InsightsModule } from '@alfresco/adf-insights'; import { ProcessModule } from '@alfresco/adf-process-services'; -import { AuthBearerInterceptor } from './services'; import { AppExtensionsModule } from './app-extension.module'; import { TreeViewSampleComponent } from './components/tree-view/tree-view-sample.component'; import { CloudLayoutComponent } from './components/cloud/cloud-layout.component'; diff --git a/demo-shell/src/app/services/index.ts b/demo-shell/src/app/services/index.ts deleted file mode 100644 index 1017c7c5af..0000000000 --- a/demo-shell/src/app/services/index.ts +++ /dev/null @@ -1,18 +0,0 @@ -/*! - * @license - * Copyright 2019 Alfresco Software, Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -export * from './auth-bearer.interceptor'; diff --git a/demo-shell/src/app/services/auth-bearer.interceptor.ts b/lib/core/services/auth-bearer.interceptor.ts similarity index 77% rename from demo-shell/src/app/services/auth-bearer.interceptor.ts rename to lib/core/services/auth-bearer.interceptor.ts index 96d8c564cd..19fb4d9be3 100644 --- a/demo-shell/src/app/services/auth-bearer.interceptor.ts +++ b/lib/core/services/auth-bearer.interceptor.ts @@ -15,13 +15,13 @@ * limitations under the License. */ -import { throwError as observableThrowError, Observable } from 'rxjs'; +import { throwError as observableThrowError, Observable, of } from 'rxjs'; import { Injectable, Injector } from '@angular/core'; import { HttpHandler, HttpInterceptor, HttpRequest, - HttpSentEvent, HttpHeaderResponse, HttpProgressEvent, HttpResponse, HttpUserEvent + HttpSentEvent, HttpHeaderResponse, HttpProgressEvent, HttpResponse, HttpUserEvent, HttpHeaders } from '@angular/common/http'; -import { AuthenticationService } from '@alfresco/adf-core'; +import { AuthenticationService } from './authentication.service'; import { catchError, mergeMap } from 'rxjs/operators'; @Injectable() @@ -31,7 +31,7 @@ export class AuthBearerInterceptor implements HttpInterceptor { constructor(private injector: Injector) { } - private loadExcludedUrlsRegex(): void { + private loadExcludedUrlsRegex() { const excludedUrls: string[] = this.authService.getBearerExcludedUrls(); this.excludedUrlsRegex = excludedUrls.map((urlPattern) => new RegExp(urlPattern, 'gi')) || []; @@ -64,14 +64,20 @@ export class AuthBearerInterceptor implements HttpInterceptor { return this.authService.addTokenToHeader(req.headers) .pipe( mergeMap((headersWithBearer) => { - const kcReq = req.clone({ headers: headersWithBearer }); - return next.handle(kcReq) - .pipe( - catchError((error) => { + const headerWithContentType = this.appendJsonContentType(headersWithBearer); + const kcReq = req.clone({ headers: headerWithContentType}); + return next.handle(kcReq) + .pipe( + catchError((error) => { return observableThrowError(error); - }) - ); + }) + ); }) ); } + + private appendJsonContentType(headers: HttpHeaders): HttpHeaders { + return headers.set('Content-Type', 'application/json;charset=UTF-8'); + } + } diff --git a/lib/core/services/public-api.ts b/lib/core/services/public-api.ts index edcde89b34..70907406c4 100644 --- a/lib/core/services/public-api.ts +++ b/lib/core/services/public-api.ts @@ -61,3 +61,4 @@ export * from './ecm-user.service'; export * from './identity-user.service'; export * from './identity-group.service'; export * from './identity-role.service'; +export * from './auth-bearer.interceptor';