auth object to request tokens, authorize connections, and manage client identity.
Auth Object
Access theauth object from your Realtime client instance:
Properties
The client ID string configured for this connection. Returns
null if no client ID is set.See identified clients for more information.Methods
authorize
authorize(tokenParams?, authOptions?): Promise<TokenDetails>
Obtain a new token and upgrade the current connection to use it. This method also updates the default tokenParams and authOptions for future token requests.
Optional token parameters to use for the token request:
ttl(integer): Token time-to-live in milliseconds (default: 60 minutes)capability(string): JSON-encoded capability specificationclientId(string): Client ID to associate with the tokentimestamp(integer): Timestamp for the token request
Optional authentication options:
authUrl(string): URL to request token fromauthCallback(function): Callback function to obtain tokenauthMethod(string): HTTP method for authUrl (GETorPOST)authHeaders(object): HTTP headers for authUrl requestauthParams(object): Query parameters for authUrl request
Returns
Returns a Promise that resolves with aTokenDetails object containing:
token(string): The token stringexpires(integer): Expiry time in milliseconds since epochissued(integer): Issue time in milliseconds since epochcapability(string): JSON-encoded capabilityclientId(string): Client ID associated with token
createTokenRequest
createTokenRequest(tokenParams?, authOptions?): Promise<TokenRequest>
Create and sign an Ably TokenRequest for use by other clients. This requires an API key to be configured locally.
Same as
authorize() method.Same as
authorize() method.Returns
Returns a Promise that resolves with aTokenRequest object containing:
keyName(string): API key namettl(integer): Token time-to-livetimestamp(integer): Request timestampcapability(string): Capability specificationclientId(string): Client IDnonce(string): Random noncemac(string): HMAC signature
requestToken
requestToken(tokenParams?, authOptions?): Promise<TokenDetails>
Request an Ably Token from the Ably service. This method issues a new token request to Ably and returns the token.
Same as
authorize() method.Same as
authorize() method.Returns
Returns a Promise that resolves with aTokenDetails object (same as authorize()).
revokeTokens
revokeTokens(specifiers): Promise<void>
Revoke one or more tokens. This is useful for logging out users or revoking compromised tokens.
Array of token specifier objects:
type(string): Specifier type (tokenorclientId)value(string): Token string or client ID to revoke
