Passes authentication-specific properties in authentication requests to Ably. Properties set using AuthOptions are used instead of the default values set when the client library is instantiated, as opposed to being merged with them.

Hierarchy

Properties

authHeaders?: { [index: string]: string }

A set of key-value pair headers to be added to any request made to the authUrl. Useful when an application requires these to be added to validate the request or implement the response. If the authHeaders object contains an authorization key, then withCredentials is set on the XHR request.

Type declaration

  • [index: string]: string
authMethod?: HTTPMethods

The HTTP verb to use for any request made to the authUrl, either GET or POST. The default value is GET.

Default Value

HTTPMethods.GET

authParams?: { [index: string]: string }

A set of key-value pair params to be added to any request made to the authUrl. When the authMethod is GET, query params are added to the URL, whereas when authMethod is POST, the params are sent as URL encoded form data. Useful when an application requires these to be added to validate the request or implement the response.

Type declaration

  • [index: string]: string
authUrl?: string

A URL that the library may use to obtain a token string (in plain text format), or a signed TokenRequest or TokenDetails (in JSON format) from.

clientId?: string

A client ID, used for identifying this client when publishing messages or for presence purposes. The clientId can be any non-empty string, except it cannot contain a *. This option is primarily intended to be used in situations where the library is instantiated with a key. Note that a clientId may also be implicit in a token used to instantiate the library. An error will be raised if a clientId specified here conflicts with the clientId implicit in the token. Find out more about client identities.

key?: string

The full API key string, as obtained from the Ably dashboard. Use this option if you wish to use Basic authentication, or wish to be able to issue Ably Tokens without needing to defer to a separate entity to sign Ably TokenRequests. Read more about Basic authentication.

queryTime?: boolean

If true, the library queries the Ably servers for the current time when issuing TokenRequests instead of relying on a locally-available time of day. Knowing the time accurately is needed to create valid signed Ably TokenRequests, so this option is useful for library instances on auth servers where for some reason the server clock cannot be kept synchronized through normal means, such as an NTP daemon. The server is queried for the current time once per client library instance (which stores the offset from the local clock), so if using this option you should avoid instancing a new version of the library for each request. The default is false.

Default Value

false

token?: string | TokenDetails

An authenticated token. This can either be a TokenDetails object or token string (obtained from the token property of a TokenDetails component of an Ably TokenRequest response, or a JSON Web Token satisfying the Ably requirements for JWTs). This option is mostly useful for testing: since tokens are short-lived, in production you almost always want to use an authentication method that enables the client library to renew the token automatically when the previous one expires, such as authUrl or authCallback. Read more about Token authentication.

tokenDetails?: TokenDetails

An authenticated TokenDetails object (most commonly obtained from an Ably Token Request response). This option is mostly useful for testing: since tokens are short-lived, in production you almost always want to use an authentication method that enables the client library to renew the token automatically when the previous one expires, such as authUrl or authCallback. Use this option if you wish to use Token authentication. Read more about Token authentication.

useTokenAuth?: boolean

When true, forces token authentication to be used by the library. If a clientId is not specified in the ClientOptions or TokenParams, then the Ably Token issued is anonymous.

Methods

  • Called when a new token is required. The role of the callback is to obtain a fresh token, one of: an Ably Token string (in plain text format); a signed TokenRequest; a TokenDetails (in JSON format); an Ably JWT. See the authentication documentation for details of the Ably TokenRequest format and associated API calls.

    Parameters

    • data: TokenParams

      The parameters that should be used to generate the token.

    • callback: ((error: null | string | Types.ErrorInfo, tokenRequestOrDetails: null | string | TokenDetails | TokenRequest) => void)

      A function which, upon success, the authCallback should call with one of: an Ably Token string (in plain text format); a signed TokenRequest; a TokenDetails (in JSON format); an Ably JWT. Upon failure, the authCallback should call this function with information about the error.

        • (error: null | string | Types.ErrorInfo, tokenRequestOrDetails: null | string | TokenDetails | TokenRequest): void
        • A function which, upon success, the authCallback should call with one of: an Ably Token string (in plain text format); a signed TokenRequest; a TokenDetails (in JSON format); an Ably JWT. Upon failure, the authCallback should call this function with information about the error.

          Parameters

          • error: null | string | Types.ErrorInfo

            Should be null if the auth request completed successfully, or containing details of the error if not.

          • tokenRequestOrDetails: null | string | TokenDetails | TokenRequest

            A valid TokenRequest, TokenDetails or Ably JWT to be used for authentication.

          Returns void

    Returns void

Generated using TypeDoc