UNPKG

@alfresco/adf-core

Version:
98 lines (92 loc) 4.36 kB
import { HttpContextToken } from '@angular/common/http'; import * as i0 from '@angular/core'; import { Injectable } from '@angular/core'; import { throwError } from 'rxjs'; import { mergeMap, catchError } from 'rxjs/operators'; /*! * @license * Copyright © 2005-2025 Hyland Software, Inc. and its affiliates. All rights reserved. * * 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. */ class Authentication { } /*! * @license * Copyright © 2005-2025 Hyland Software, Inc. and its affiliates. All rights reserved. * * 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. */ const SHOULD_ADD_AUTH_TOKEN = new HttpContextToken(() => false); class AuthenticationInterceptor { constructor(authService) { this.authService = authService; } intercept(req, next) { if (req.context.get(SHOULD_ADD_AUTH_TOKEN)) { return this.authService.addTokenToHeader(req.url, req.headers).pipe(mergeMap((headersWithBearer) => { const headerWithContentType = this.appendJsonContentType(headersWithBearer, req.body); const kcReq = req.clone({ headers: headerWithContentType }); return next.handle(kcReq).pipe(catchError((error) => throwError(error))); })); } return next.handle(req).pipe(catchError((error) => throwError(error))); } appendJsonContentType(headers, reqBody) { // 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') && !(reqBody instanceof FormData)) { return headers.set('Content-Type', 'application/json;charset=UTF-8'); } return headers; } static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.6", ngImport: i0, type: AuthenticationInterceptor, deps: [{ token: Authentication }], target: i0.ɵɵFactoryTarget.Injectable }); } static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "19.2.6", ngImport: i0, type: AuthenticationInterceptor }); } } i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.6", ngImport: i0, type: AuthenticationInterceptor, decorators: [{ type: Injectable }], ctorParameters: () => [{ type: Authentication }] }); /*! * @license * Copyright © 2005-2025 Hyland Software, Inc. and its affiliates. All rights reserved. * * 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. */ /** * Generated bundle index. Do not edit. */ export { Authentication, AuthenticationInterceptor, SHOULD_ADD_AUTH_TOKEN }; //# sourceMappingURL=alfresco-adf-core-auth.mjs.map