diff --git a/src/Umbraco.Web.UI.Client/src/shared/auth/auth.context.interface.ts b/src/Umbraco.Web.UI.Client/src/shared/auth/auth.context.interface.ts deleted file mode 100644 index b307a4b7b9..0000000000 --- a/src/Umbraco.Web.UI.Client/src/shared/auth/auth.context.interface.ts +++ /dev/null @@ -1,46 +0,0 @@ -import type { Observable } from '@umbraco-cms/backoffice/external/rxjs'; - -export interface IUmbAuthContext { - isAuthorized: Observable; - - /** - * Initiates the login flow. - */ - login(): void; - - /** - * Initialise the auth flow. - */ - setInitialState(): Promise; - - /** - * Checks if there is a token and it is still valid. - */ - getIsAuthorized(): boolean; - - /** - * Gets the latest token from the Management API. - * If the token is expired, it will be refreshed. - * - * NB! The user may experience being redirected to the login screen if the token is expired. - * - * @example - * ```js - * const token = await authContext.getLatestToken(); - * const result = await fetch('https://my-api.com', { headers: { Authorization: `Bearer ${token}` } }); - * ``` - * - * @returns The latest token from the Management API - */ - getLatestToken(): Promise; - - /** - * Clears the token storage. - */ - clearTokenStorage(): Promise; - - /** - * Signs the user out by removing any tokens from the browser. - */ - signOut(): Promise; -} diff --git a/src/Umbraco.Web.UI.Client/src/shared/auth/auth.context.token.ts b/src/Umbraco.Web.UI.Client/src/shared/auth/auth.context.token.ts index b7c70219f0..4725be3acb 100644 --- a/src/Umbraco.Web.UI.Client/src/shared/auth/auth.context.token.ts +++ b/src/Umbraco.Web.UI.Client/src/shared/auth/auth.context.token.ts @@ -1,4 +1,4 @@ -import type { IUmbAuthContext } from './auth.context.interface.js'; +import type { UmbAuthContext } from './auth.context.js'; import { UmbContextToken } from '@umbraco-cms/backoffice/context-api'; -export const UMB_AUTH_CONTEXT = new UmbContextToken('UmbAuthContext'); +export const UMB_AUTH_CONTEXT = new UmbContextToken('UmbAuthContext'); 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 8a0a298e06..49bf424100 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,11 +1,10 @@ -import type { IUmbAuthContext } from './auth.context.interface.js'; import { UmbAuthFlow } from './auth-flow.js'; import { UMB_AUTH_CONTEXT } from './auth.context.token.js'; import type { UmbControllerHostElement } from '@umbraco-cms/backoffice/controller-api'; import { UmbBaseController } from '@umbraco-cms/backoffice/class-api'; import { UmbBooleanState } from '@umbraco-cms/backoffice/observable-api'; -export class UmbAuthContext extends UmbBaseController implements IUmbAuthContext { +export class UmbAuthContext extends UmbBaseController { #isAuthorized = new UmbBooleanState(false); readonly isAuthorized = this.#isAuthorized.asObservable(); @@ -59,6 +58,13 @@ export class UmbAuthContext extends UmbBaseController implements IUmbAuthContext * * NB! The user may experience being redirected to the login screen if the token is expired. * + * @example + * ```js + * const token = await authContext.getLatestToken(); + * const result = await fetch('https://my-api.com', { headers: { Authorization: `Bearer ${token}` } }); + * ``` + * + * @memberof UmbAuthContext * @returns The latest token from the Management API */ getLatestToken(): Promise { @@ -75,7 +81,6 @@ export class UmbAuthContext extends UmbBaseController implements IUmbAuthContext /** * Signs the user out by removing any tokens from the browser. - * @return {*} {Promise} * @memberof UmbAuthContext */ signOut(): Promise { diff --git a/src/Umbraco.Web.UI.Client/src/shared/auth/index.ts b/src/Umbraco.Web.UI.Client/src/shared/auth/index.ts index f2e7f83bb1..e2633039d7 100644 --- a/src/Umbraco.Web.UI.Client/src/shared/auth/index.ts +++ b/src/Umbraco.Web.UI.Client/src/shared/auth/index.ts @@ -1,3 +1,2 @@ -export * from './auth.context.interface.js'; export * from './auth.context.js'; export * from './auth.context.token.js';