mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2026-09-09 18:03:21 +00:00
[AAE-12501] Replace oauth2Auth with authentication service, define get username as abstract
This commit is contained in:
@@ -56,8 +56,7 @@ export class AppNotificationsService {
|
||||
) {
|
||||
this.alfrescoApiService.alfrescoApiInitialized.subscribe(() => {
|
||||
if (this.isProcessServicesEnabled() && this.notificationsEnabled) {
|
||||
this.alfrescoApiService.getInstance().oauth2Auth.once('token_issued', () => {
|
||||
|
||||
this.authenticationService.once('token_received').subscribe(() => {
|
||||
const deployedApps = this.appConfigService.get('alfresco-deployed-apps', []);
|
||||
if (deployedApps?.length) {
|
||||
deployedApps.forEach((app) => {
|
||||
@@ -69,11 +68,8 @@ export class AppNotificationsService {
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -16,9 +16,9 @@
|
||||
*/
|
||||
|
||||
import { Injectable } from '@angular/core';
|
||||
import { OAuthService, OAuthStorage } from 'angular-oauth2-oidc';
|
||||
import { OAuthEvent, OAuthService, OAuthStorage } from 'angular-oauth2-oidc';
|
||||
import { EMPTY, Observable } from 'rxjs';
|
||||
import { catchError, map } from 'rxjs/operators';
|
||||
import { catchError, filter, map } from 'rxjs/operators';
|
||||
import { AppConfigService, AppConfigValues } from '../../app-config/app-config.service';
|
||||
import { OauthConfigModel } from '../models/oauth-config.model';
|
||||
import { AlfrescoApiService } from '../../services/alfresco-api.service';
|
||||
@@ -46,11 +46,6 @@ export class OIDCAuthenticationService extends BaseAuthenticationService {
|
||||
private readonly auth: AuthService
|
||||
) {
|
||||
super(alfrescoApi, appConfig, cookie, logService);
|
||||
this.alfrescoApi.alfrescoApiInitialized.subscribe(() => {
|
||||
this.alfrescoApi.getInstance().reply('logged-in', () => {
|
||||
this.onLogin.next();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
isEcmLoggedIn(): boolean {
|
||||
@@ -97,6 +92,14 @@ export class OIDCAuthenticationService extends BaseAuthenticationService {
|
||||
);
|
||||
}
|
||||
|
||||
getEcmUsername(): string {
|
||||
return (this.oauthService.getIdentityClaims() as any).preferred_username;
|
||||
}
|
||||
|
||||
getBpmUsername(): string {
|
||||
return (this.oauthService.getIdentityClaims() as any).preferred_username;
|
||||
}
|
||||
|
||||
ssoImplicitLogin() {
|
||||
this.oauthService.initLoginFlow();
|
||||
}
|
||||
@@ -127,4 +130,8 @@ export class OIDCAuthenticationService extends BaseAuthenticationService {
|
||||
this.auth.login();
|
||||
}
|
||||
}
|
||||
|
||||
once(event: string): Observable<OAuthEvent> {
|
||||
return this.oauthService.events.pipe(filter(_event => _event.type === event));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -161,6 +161,24 @@ export class AuthenticationService extends BaseAuthenticationService {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the ECM username.
|
||||
*
|
||||
* @returns The ECM username
|
||||
*/
|
||||
getEcmUsername(): string {
|
||||
return this.alfrescoApi.getInstance().getEcmUsername();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the BPM username
|
||||
*
|
||||
* @returns The BPM username
|
||||
*/
|
||||
getBpmUsername(): string {
|
||||
return this.alfrescoApi.getInstance().getBpmUsername();
|
||||
}
|
||||
|
||||
isImplicitFlow(): boolean {
|
||||
const oauth2: OauthConfigModel = Object.assign({}, this.appConfig.get<OauthConfigModel>(AppConfigValues.OAUTHCONFIG, null));
|
||||
return !!oauth2?.implicitFlow;
|
||||
@@ -179,5 +197,11 @@ export class AuthenticationService extends BaseAuthenticationService {
|
||||
return this.storageService.getItem(JwtHelperService.USER_ACCESS_TOKEN);
|
||||
}
|
||||
|
||||
reset() {}
|
||||
reset() { }
|
||||
|
||||
once(event: string): Observable<any> {
|
||||
return new Observable((subscriber) => {
|
||||
this.alfrescoApi.getInstance().once(event, () => subscriber.next());
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -65,7 +65,10 @@ export abstract class BaseAuthenticationService {
|
||||
abstract logout(): Observable<any>;
|
||||
abstract isEcmLoggedIn(): boolean;
|
||||
abstract isBpmLoggedIn(): boolean;
|
||||
abstract getEcmUsername(): string;
|
||||
abstract getBpmUsername(): string;
|
||||
abstract reset(): void;
|
||||
abstract once(event: string): Observable<any>;
|
||||
|
||||
getBearerExcludedUrls(): readonly string[] {
|
||||
return this.bearerExcludedUrls;
|
||||
@@ -127,24 +130,6 @@ export abstract class BaseAuthenticationService {
|
||||
return header.set('Authorization', ticket);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the ECM username.
|
||||
*
|
||||
* @returns The ECM username
|
||||
*/
|
||||
getEcmUsername(): string {
|
||||
return this.alfrescoApi.getInstance().getEcmUsername();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the BPM username
|
||||
*
|
||||
* @returns The BPM username
|
||||
*/
|
||||
getBpmUsername(): string {
|
||||
return this.alfrescoApi.getInstance().getBpmUsername();
|
||||
}
|
||||
|
||||
isPublicUrl(): boolean {
|
||||
return this.alfrescoApi.getInstance().isPublicUrl();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user