[ADF-3570] ADF Migration - Add the interceptor layer (#3813)

* Enable impliciFlow and add new interceptor

* Fix errors

* add excluded path rules

* Add the needed methods to the AuthenticationService core

* Remove unused library and service
This commit is contained in:
Maurizio Vitale
2018-09-20 22:17:05 +01:00
committed by Eugenio Romano
parent 244d1aae85
commit cfbe3cfd86
5 changed files with 131 additions and 3 deletions

View File

@@ -16,7 +16,7 @@
*/
import { Injectable } from '@angular/core';
import { Observable, Subject, from, throwError } from 'rxjs';
import { Observable, Subject, from, throwError, Observer } from 'rxjs';
import { AlfrescoApiService } from './alfresco-api.service';
import { CookieService } from './cookie.service';
import { LogService } from './log.service';
@@ -24,6 +24,7 @@ import { RedirectionModel } from '../models/redirection.model';
import { AppConfigService, AppConfigValues } from '../app-config/app-config.service';
import { UserRepresentation } from 'alfresco-js-api';
import { map, catchError, tap } from 'rxjs/operators';
import { HttpHeaders } from '@angular/common/http';
const REMEMBER_ME_COOKIE_KEY = 'ALFRESCO_REMEMBER_ME';
const REMEMBER_ME_UNTIL = 1000 * 60 * 60 * 24 * 30 ;
@@ -32,6 +33,8 @@ const REMEMBER_ME_UNTIL = 1000 * 60 * 60 * 24 * 30 ;
export class AuthenticationService {
private redirectUrl: RedirectionModel = null;
private bearerExcludedUrls: string[] = ['auth/realms', 'resources/', 'assets/'];
onLogin: Subject<any> = new Subject<any>();
onLogout: Subject<any> = new Subject<any>();
@@ -271,4 +274,29 @@ export class AuthenticationService {
this.logService.error('Error when logging in', error);
return throwError(error || 'Server error');
}
getBearerExcludedUrls(): string[] {
return this.bearerExcludedUrls;
}
getToken(): string {
return localStorage.getItem('access_token');
}
addTokenToHeader(headersArg?: HttpHeaders): Observable<HttpHeaders> {
return Observable.create(async (observer: Observer<any>) => {
let headers = headersArg;
if (!headers) {
headers = new HttpHeaders();
}
try {
const token: string = this.getToken();
headers = headers.set('Authorization', 'bearer ' + token);
observer.next(headers);
observer.complete();
} catch (error) {
observer.error(error);
}
});
}
}