diff --git a/demo-shell/src/app/services/app-notifications.service.ts b/demo-shell/src/app/services/app-notifications.service.ts index 56910b5718..e87ddce497 100644 --- a/demo-shell/src/app/services/app-notifications.service.ts +++ b/demo-shell/src/app/services/app-notifications.service.ts @@ -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 { }); }); } - }); - } - }); } diff --git a/lib/core/src/lib/auth/oidc/oidc-authentication.service.ts b/lib/core/src/lib/auth/oidc/oidc-authentication.service.ts index 791b85a758..ca9da6640c 100644 --- a/lib/core/src/lib/auth/oidc/oidc-authentication.service.ts +++ b/lib/core/src/lib/auth/oidc/oidc-authentication.service.ts @@ -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 { + return this.oauthService.events.pipe(filter(_event => _event.type === event)); + } } diff --git a/lib/core/src/lib/auth/services/authentication.service.ts b/lib/core/src/lib/auth/services/authentication.service.ts index 6a7337f350..025f91518e 100644 --- a/lib/core/src/lib/auth/services/authentication.service.ts +++ b/lib/core/src/lib/auth/services/authentication.service.ts @@ -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(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 { + return new Observable((subscriber) => { + this.alfrescoApi.getInstance().once(event, () => subscriber.next()); + }); + } } diff --git a/lib/core/src/lib/services/base-authentication.service.ts b/lib/core/src/lib/services/base-authentication.service.ts index 7bcf0e84ca..dfd22e829a 100644 --- a/lib/core/src/lib/services/base-authentication.service.ts +++ b/lib/core/src/lib/services/base-authentication.service.ts @@ -65,7 +65,10 @@ export abstract class BaseAuthenticationService { abstract logout(): Observable; abstract isEcmLoggedIn(): boolean; abstract isBpmLoggedIn(): boolean; + abstract getEcmUsername(): string; + abstract getBpmUsername(): string; abstract reset(): void; + abstract once(event: string): Observable; 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(); }