This base provides the necessary for a class to become a context-api controller.

Hierarchy (View Summary, Expand)

Constructors

Properties

isAuthorized: Observable<boolean> = ...

Observable that emits true if the user is authorized, otherwise false.

It will only emit when the authorization state changes.

isInitialized: Observable<void> = ...

Observable that emits true when the auth context is initialized.

It will only emit once and then complete itself.

timeoutSignal: Observable<void> = ...

Observable that acts as a signal and emits when the user has timed out, i.e. the token has expired. This can be used to show a timeout message to the user.

It can emit multiple times if more than one request is made after the token has expired.

Accessors

Methods

  • Appends an event listener for events whose type attribute value is type. The callback argument sets the callback that will be invoked when the event is dispatched.

    The options argument sets listener-specific options. For compatibility this can be a boolean, in which case the method behaves exactly as if the value was specified as options's capture.

    When set to true, options's capture prevents callback from being invoked when the event's eventPhase attribute value is BUBBLING_PHASE. When false (or not present), callback will not be invoked when event's eventPhase attribute value is CAPTURING_PHASE. Either way, callback will be invoked if event's eventPhase attribute value is AT_TARGET.

    When set to true, options's passive indicates that the callback will not cancel the event by invoking preventDefault(). This is used to enable performance optimizations described in ยง 2.8 Observing event listeners.

    When set to true, options's once indicates that the callback will only be invoked once after which the event listener will be removed.

    If an AbortSignal is passed for options's signal, then the event listener will be removed when signal is aborted.

    The event listener is appended to target's event listener list and is not appended if it has the same type, callback, and capture.

    MDN Reference

    Parameters

    • type: string
    • callback: null | EventListenerOrEventListenerObject
    • Optionaloptions: boolean | AddEventListenerOptions

    Returns void

  • Dispatches a synthetic event event to target and returns true if either event's cancelable attribute value is false or its preventDefault() method was not invoked, and false otherwise.

    MDN Reference

    Parameters

    • event: Event

    Returns boolean

  • Checks if the user is authorized. If Authorization is bypassed, the user is always authorized.

    Returns boolean

    True if the user is authorized, otherwise false.

  • 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.

    Returns Promise<string>

    The latest token from the Management API

      const token = await authContext.getLatestToken();
    const result = await fetch('https://my-api.com', { headers: { Authorization: `Bearer ${token}` } });

    UmbAuthContext

  • Get the default OpenAPI configuration, which is set up to communicate with the Management API.

    Returns UmbOpenApiConfiguration

    The default OpenAPI configuration

    This is useful if you want to communicate with your own resources generated by the openapi-typescript-codegen library.

    UmbAuthContext

     	const defaultOpenApi = authContext.getOpenApiConfiguration();
    OpenAPI.BASE = defaultOpenApi.base;
    OpenAPI.WITH_CREDENTIALS = defaultOpenApi.withCredentials;
    OpenAPI.CREDENTIALS = defaultOpenApi.credentials;
    OpenAPI.TOKEN = defaultOpenApi.token;
  • Gets the post logout redirect url.

    Returns string

    The post logout redirect url, which is the backoffice path with the logout path appended.

  • Get the server url to the Management API.

    Returns string

    The server url to the Management API

    UmbAuthContext

    	const serverUrl = authContext.getServerUrl();
    OpenAPI.BASE = serverUrl;
    	const serverUrl = authContext.getServerUrl();
    const token = await authContext.getLatestToken();
    const result = await fetch(`${serverUrl}/umbraco/management/api/v1/my-resource`, { headers: { Authorization: `Bearer ${token}` } });
  • Initiates the login flow.

    Parameters

    • identityProvider: string = 'Umbraco'

      The provider to use for login. Default is 'Umbraco'.

    • Optionalredirect: boolean

      If true, the user will be redirected to the login page.

    • OptionalusernameHint: string

      The username hint to use for login.

    • Optionalmanifest: ManifestAuthProvider

      The manifest for the registered provider.

    Returns Promise<void>

  • Removes the event listener in target's event listener list with the same type, callback, and options.

    MDN Reference

    Parameters

    • type: string
    • callback: null | EventListenerOrEventListenerObject
    • Optionaloptions: boolean | EventListenerOptions

    Returns void

  • Sets the auth context as initialized, which means that the auth context is ready to be used.

    Returns void

    This is used to let the app context know that the core module is ready, which means that the core auth providers are available.

  • Handles the case where the user has timed out, i.e. the token has expired. This will clear the token storage and set the user as unauthorized.

    Returns void

    UmbAuthContext

  • Parameters

    • providerName: string
    • providerKey: string

    Returns Promise<boolean>

    UmbAuthFlow#unlinkLogin

  • Validates the token against the server and returns true if the token is valid.

    Returns Promise<boolean>

    True if the token is valid, otherwise false

    UmbAuthContext

MMNEPVFCICPMFPCPTTAAATR