@umbraco-cms/backoffice
    Preparing search index...

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

    Hierarchy (View Summary)

    Index

    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 will emit once per second, so it can be used to trigger UI updates or other actions when the user has timed out.

    Accessors

    • get authorizationSignal(): Observable<void>

      Observable that acts as a signal for when the authorization state changes.

      Returns Observable<void>

      An observable that emits when the authorization state changes.

      It will emit once per second, so it can be used to trigger UI updates or other actions when the authorization state changes.

    Methods

    • The addEventListener() method of the EventTarget interface sets up a function that will be called whenever the specified event is delivered to the target.

      MDN Reference

      Parameters

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

      Returns void

    • The dispatchEvent() method of the EventTarget sends an Event to the object, (synchronously) invoking the affected event listeners in the appropriate order.

      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 @hey-api/openapi-ts library.

      UmbAuthContext

      const defaultOpenApi = authContext.getOpenApiConfiguration();
      client.setConfig({
      base: defaultOpenApi.base,
      auth: 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>

    • The removeEventListener() method of the EventTarget interface removes an event listener previously registered with EventTarget.addEventListener() from the target.

      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