From bc6922b7898c72769fad7a3437decc2df8151f32 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Niels=20Lyngs=C3=B8?= Date: Thu, 9 Nov 2023 14:45:47 +0100 Subject: [PATCH] Revert "rename UmbAuth and other fixes" This reverts commit a78c1d1b1400a51efeea57471007142d51870224. --- src/Umbraco.Web.UI.Client/src/apps/app/app.element.ts | 10 ++++------ .../current-user/utils/is-current-user.function.ts | 4 ++-- .../src/shared/auth/auth.context.ts | 8 ++++---- .../src/shared/auth/auth.interface.ts | 5 +++-- .../src/shared/auth/auth.token.ts | 4 ++-- 5 files changed, 15 insertions(+), 16 deletions(-) diff --git a/src/Umbraco.Web.UI.Client/src/apps/app/app.element.ts b/src/Umbraco.Web.UI.Client/src/apps/app/app.element.ts index f95fba3572..4adbcfed32 100644 --- a/src/Umbraco.Web.UI.Client/src/apps/app/app.element.ts +++ b/src/Umbraco.Web.UI.Client/src/apps/app/app.element.ts @@ -186,7 +186,7 @@ export class UmbAppElement extends UmbLitElement { async #setAuthStatus() { if (this.bypassAuth === false) { if (!this.#authContext) { - throw new Error('[Fatal] AuthContext requested before it was initialized'); + throw new Error('[Fatal] AuthContext requested before it was initialised'); } // Get service configuration from authentication server @@ -200,8 +200,6 @@ export class UmbAppElement extends UmbLitElement { // TODO: This feels like an od placement, move this into some method regarding starting the application/not install/... this.#listenForLanguageChange(); - this.#authContext?.checkAuthorization(); - } #redirect() { @@ -241,13 +239,13 @@ export class UmbAppElement extends UmbLitElement { } } - #checkAuthorized(): boolean { - return this.#authContext?.checkAuthorization() ?? false; + #isAuthorized(): boolean { + return this.#authContext?.isAuthorized() ?? false; } #isAuthorizedGuard(): Guard { return () => { - if (this.#checkAuthorized()) { + if (this.#isAuthorized()) { return true; } diff --git a/src/Umbraco.Web.UI.Client/src/packages/user/current-user/utils/is-current-user.function.ts b/src/Umbraco.Web.UI.Client/src/packages/user/current-user/utils/is-current-user.function.ts index ac09b582b1..8b79ad283f 100644 --- a/src/Umbraco.Web.UI.Client/src/packages/user/current-user/utils/is-current-user.function.ts +++ b/src/Umbraco.Web.UI.Client/src/packages/user/current-user/utils/is-current-user.function.ts @@ -1,9 +1,9 @@ -import { UmbAuth, UMB_AUTH_CONTEXT } from '@umbraco-cms/backoffice/auth'; +import { IUmbAuth, UMB_AUTH_CONTEXT } from '@umbraco-cms/backoffice/auth'; import { UmbContextConsumerController } from '@umbraco-cms/backoffice/context-api'; import { UmbControllerHost } from '@umbraco-cms/backoffice/controller-api'; export const isCurrentUser = async (host: UmbControllerHost, userId: string) => { - let authContext: UmbAuth | undefined = undefined; + let authContext: IUmbAuth | undefined = undefined; await new UmbContextConsumerController(host, UMB_AUTH_CONTEXT, (context) => { authContext = context; diff --git a/src/Umbraco.Web.UI.Client/src/shared/auth/auth.context.ts b/src/Umbraco.Web.UI.Client/src/shared/auth/auth.context.ts index a7531bfc85..0e69a50484 100644 --- a/src/Umbraco.Web.UI.Client/src/shared/auth/auth.context.ts +++ b/src/Umbraco.Web.UI.Client/src/shared/auth/auth.context.ts @@ -1,4 +1,4 @@ -import { UmbAuth } from './auth.interface.js'; +import { IUmbAuth } from './auth.interface.js'; import { UmbAuthFlow } from './auth-flow.js'; import { UmbLoggedInUser } from './types.js'; import { UserResource } from '@umbraco-cms/backoffice/backend-api'; @@ -7,7 +7,7 @@ import { UmbBooleanState, UmbObjectState } from '@umbraco-cms/backoffice/observa import { tryExecuteAndNotify } from '@umbraco-cms/backoffice/resources'; import { firstValueFrom } from '@umbraco-cms/backoffice/external/rxjs'; -export class UmbAuthContext extends UmbBaseController implements UmbAuth { +export class UmbAuthContext extends UmbBaseController implements IUmbAuth { #currentUser = new UmbObjectState(undefined); readonly currentUser = this.#currentUser.asObservable(); @@ -47,8 +47,8 @@ export class UmbAuthContext extends UmbBaseController implements UmbAuth { return this.#authFlow?.makeAuthorizationRequest(); } - checkAuthorization() { - return this.#authFlow?.checkAuthorization() ?? true; + isAuthorized() { + return this.#authFlow?.isAuthorized() ?? true; } setInitialState(): Promise { diff --git a/src/Umbraco.Web.UI.Client/src/shared/auth/auth.interface.ts b/src/Umbraco.Web.UI.Client/src/shared/auth/auth.interface.ts index ebf9d8d2ce..cbd3cc2372 100644 --- a/src/Umbraco.Web.UI.Client/src/shared/auth/auth.interface.ts +++ b/src/Umbraco.Web.UI.Client/src/shared/auth/auth.interface.ts @@ -1,7 +1,7 @@ import type { UmbLoggedInUser } from './types.js'; import type { Observable } from '@umbraco-cms/backoffice/external/rxjs'; -export interface UmbAuth { +export interface IUmbAuth { /** * Initiates the login flow. */ @@ -15,7 +15,8 @@ export interface UmbAuth { /** * Checks if there is a token and it is still valid. */ - checkAuthorization(): boolean; + isAuthorized(): boolean; + /** * Gets the latest token from the Management API. * If the token is expired, it will be refreshed. diff --git a/src/Umbraco.Web.UI.Client/src/shared/auth/auth.token.ts b/src/Umbraco.Web.UI.Client/src/shared/auth/auth.token.ts index 47f667e654..5c47874e77 100644 --- a/src/Umbraco.Web.UI.Client/src/shared/auth/auth.token.ts +++ b/src/Umbraco.Web.UI.Client/src/shared/auth/auth.token.ts @@ -1,6 +1,6 @@ -import { UmbAuth } from './auth.interface.js'; +import { IUmbAuth } from './auth.interface.js'; import { UmbContextToken } from '@umbraco-cms/backoffice/context-api'; -export const UMB_AUTH_CONTEXT = new UmbContextToken( +export const UMB_AUTH_CONTEXT = new UmbContextToken( 'UmbAuthContext' );