/** Angular Imports */ import { Injectable } from '@angular/core' ; import { HttpEvent , HttpInterceptor , HttpHandler , HttpRequest } from '@angular/common/http' ; /** rxjs Imports */ import { Observable } from 'rxjs' ; /** Environment Configuration */ import { environment } from '../../../environments/environment' ; /** Http request options headers. */ const httpOptions = { headers : { 'Fineract-Platform-TenantId' : environment . fineractPlatformTenantId } } ; /** Authorization header. */ const authorizationHeader = 'Authorization' ; /** Two factor access token header. */ const twoFactorAccessTokenHeader = 'Fineract-Platform-TFA-Token' ; /**
 * Http Request interceptor to set the request headers.
 */ @ Injectable ( ) export class AuthenticationInterceptor implements HttpInterceptor { constructor ( ) { } /**
     * Intercepts a Http request and sets the request headers.
     */ intercept ( request , next ) { request = request . clone ( { setHeaders : httpOptions . headers } ) ; return next . handle ( request ) ; } param { string } authenticationKey setAuthorizationToken ( authenticationKey ) { if ( environment . oauth . enabled ) { httpOptions . headers [ authorizationHeader ] = `Bearer ${ authenticationKey }` ; } else { httpOptions . headers [ authorizationHeader ] = `Basic ${ authenticationKey }` ; } } param { string } twoFactorAccessToken setTwoFactorAccessToken ( twoFactorAccessToken ) { httpOptions . headers [ twoFactorAccessTokenHeader ] = twoFactorAccessToken ; } /**
     * Removes the authorization header.
     */ removeAuthorization ( ) { delete httpOptions . headers [ authorizationHeader ] ; } /**
     * Removes the two factor access token header.
     */ removeTwoFactorAuthorization ( ) { delete httpOptions . headers [ twoFactorAccessTokenHeader ] ; } }