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

    Class UmbAuthContext

    Hierarchy (View Summary)

    Index
    isAuthorized: Observable<boolean> = ...

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

    It will only emit when the authorization state changes.

    keepUserLoggedIn: boolean

    Whether the server is configured to keep users logged in by auto-refreshing before session expiry. Provided by the backend via the keep-user-logged-in attribute on <umb-app>.

    session$: Observable<UmbAuthSession | undefined> = ...
    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.

    userChanged: Observable<void> = ...

    Emits when the session has passed to a different user than the one the page is bound to (see bindUser()), or to a user who could not be determined. The new session is not applied: the page holds client state that belongs to the previous user, so it has to start over rather than show that state to the user who is signed in now. From then on no session is applied to the page, so the host has to start it over, or the page stays unauthorized. The app shell handles this by reloading the backoffice. A sign-in while the page is still open emits again, so the host can try once more. A user who cannot be determined (every lookup failed) is treated as a different user on purpose, so the page also starts over, and discards unsaved work, when it is in fact the same user.

    • 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: EventListenerOrEventListenerObject | null
      • Optionaloptions: boolean | AddEventListenerOptions

      Returns void

    • Internal

      Binds the page to the user it has loaded client state for. A sign-in that happens after this, in this tab or another one, is held until the user behind it is known: the same user resumes the page as it is, so unsaved work survives; any other user is reported through userChanged instead. Binding a different user later is reported the same way. The app shell calls this with the user it has loaded.

      Parameters

      • unique: string

        The unique of the user the page has loaded.

      Returns void

    • Configures a @hey-api/openapi-ts generated client for authenticated API calls.

      Sets baseUrl and credentials, and binds the default response interceptors (401 retry, problem-details error notifications, etc.) to the client.

      The same auth context owns a single UmbApiInterceptorController for the lifetime of the host (<umb-app>), so it's safe to call this method for multiple clients (the core's umbHttpClient and an extension's own generated client) without registering duplicate auth-signaler contexts.

      Parameters

      • client: UmbApiClient

        A @hey-api/openapi-ts client instance — either umbHttpClient or one regenerated by an extension package against its own OpenAPI document.

      Returns void

      const authContext = await this.getContext(UMB_AUTH_CONTEXT);
      authContext.configureClient(myClient);
      // Now myClient automatically includes auth headers and interceptors
    • The dispatchEvent() method of the EventTarget sends an Event to the object, (synchronously) invoking the affected event listeners in the appropriate order. The normal event processing rules (including the capturing and optional bubbling phase) also apply to events dispatched manually with dispatchEvent().

      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.

    • 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,
      credentials: defaultOpenApi.credentials,
      });
    • Gets the post logout redirect url.

      Returns string

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

    • Extends the current back-office session and returns whether it succeeded. This is the canonical, reusable way to keep a session alive: it pings the server keep-alive endpoint.

      Returns Promise<boolean>

      True if the session was renewed, otherwise false.

    • Links the current user to the specified provider by redirecting to the link endpoint.

      Parameters

      • provider: string

        The provider to link to.

      Returns Promise<void>

    • Initiates login for the given provider.

      The built-in "Umbraco" provider is local username/password login (the server login app); any other provider is challenged via the cookie external-login endpoint.

      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.

      • Optional_usernameHint: string
      • 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. The event listener to be removed is identified using a combination of the event type, the event listener function itself, and various optional options that may affect the matching process; see Matching event listeners for removal.

      MDN Reference

      Parameters

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

      Returns void

    • Sets the initial state of the auth flow. This must be called before any other auth methods are called. It establishes if the user is authorized or not, and sets the session state accordingly.

      Returns Promise<void>

    • Signs the user out by clearing the local session and redirecting to the server sign-out endpoint, which clears the authentication cookie.

      Returns Promise<void>

      UmbAuthContext

    • 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

    • Unlinks the current user from the specified provider.

      Parameters

      • loginProvider: string

        The login provider to unlink from.

      • providerKey: string

        The provider's key for the current user.

      Returns Promise<boolean>

      True if the unlink succeeded.