This is the class used to manage authentication tokens provided by the host application. Be sure to read the docs for each method, as they contain important details about the contract with the host application.

Hierarchy

  • AuthClient

Constructors

  • Creates a new client

    Parameters

    • clientId: string

      A short string identifying your client to the host application

    • host: string = window.location.origin

      The expected origin for the host app. Defaults to the current app's origin

    Returns AuthClient

Methods

  • Gets the current valid auth token for use. As the name implies, the host app may change the token at any time, so the result of this call should not be cached. Instead, call this method each time you need to make an API call. It should almost always resolve immediately. If the promise is ever rejected, that's a fatal error for auth setup, so be sure to catch errors and log and monitor them appropriately.

    Returns

    A promise to the token.

    Parameters

    • timeout: number = 3000

      The time in ms to wait for a token to be provided in the rare event that one is not ready when the client starts.

    Returns Promise<string>

  • Notifies the host app that the client received a 401 from the API. The token that triggered the 401 must be provided so that the client can verify that it is up-to-date before asking the host app to take a potentially destructive action like refreshing the entire app.

    Parameters

    • token: string

      The token value that received a 401

    Returns void

Generated using TypeDoc