remove IUmbAuthContext interface since it was merely put in as a safe-guard in case we had to move the services around
This commit is contained in:
@@ -1,46 +0,0 @@
|
||||
import type { Observable } from '@umbraco-cms/backoffice/external/rxjs';
|
||||
|
||||
export interface IUmbAuthContext {
|
||||
isAuthorized: Observable<boolean>;
|
||||
|
||||
/**
|
||||
* Initiates the login flow.
|
||||
*/
|
||||
login(): void;
|
||||
|
||||
/**
|
||||
* Initialise the auth flow.
|
||||
*/
|
||||
setInitialState(): Promise<void>;
|
||||
|
||||
/**
|
||||
* 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<string>;
|
||||
|
||||
/**
|
||||
* Clears the token storage.
|
||||
*/
|
||||
clearTokenStorage(): Promise<void>;
|
||||
|
||||
/**
|
||||
* Signs the user out by removing any tokens from the browser.
|
||||
*/
|
||||
signOut(): Promise<void>;
|
||||
}
|
||||
@@ -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<IUmbAuthContext>('UmbAuthContext');
|
||||
export const UMB_AUTH_CONTEXT = new UmbContextToken<UmbAuthContext>('UmbAuthContext');
|
||||
|
||||
@@ -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<boolean>(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<string> {
|
||||
@@ -75,7 +81,6 @@ export class UmbAuthContext extends UmbBaseController implements IUmbAuthContext
|
||||
|
||||
/**
|
||||
* Signs the user out by removing any tokens from the browser.
|
||||
* @return {*} {Promise<void>}
|
||||
* @memberof UmbAuthContext
|
||||
*/
|
||||
signOut(): Promise<void> {
|
||||
|
||||
@@ -1,3 +1,2 @@
|
||||
export * from './auth.context.interface.js';
|
||||
export * from './auth.context.js';
|
||||
export * from './auth.context.token.js';
|
||||
|
||||
Reference in New Issue
Block a user