Class Auth


  • public class Auth
    extends java.lang.Object
    Token-generation and authentication operations for the Ably API. See the Ably Authentication documentation for details of the authentication methods available. Creates Ably Auth.TokenRequest objects and obtains Ably Tokens from Ably to subsequently issue to less trusted clients.
    • Field Detail

      • clientId

        public java.lang.String clientId
        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 is raised if a clientId specified here conflicts with the clientId implicit in the token. Find out more about identified clients.

        Spec: RSA7, RSC17, RSA12

      • WILDCARD_CLIENTID

        public static final java.lang.String WILDCARD_CLIENTID
        See Also:
        Constant Field Values
    • Method Detail

      • getAuthMethod

        public Auth.AuthMethod getAuthMethod()
        Get the authentication method for this library instance.
        Returns:
      • getBasicCredentials

        public java.lang.String getBasicCredentials()
        Get the credentials for HTTP basic auth, if available.
        Returns:
      • getAuthParams

        public Param[] getAuthParams()
                              throws AblyException
        Get query params representing the current authentication method and credentials.
        Returns:
        Throws:
        AblyException
      • getAuthOptions

        public Auth.AuthOptions getAuthOptions()
        Get (a copy of) auth options currently set in this Auth.
      • onAuthError

        public void onAuthError​(ErrorInfo err)
      • timestamp

        public static long timestamp()
      • getEncodedToken

        public java.lang.String getEncodedToken()
      • assertAuthorizationHeader

        public void assertAuthorizationHeader​(boolean forceRenew)
                                       throws AblyException
        Get the Authorization header, forcing the creation of a new token if requested
        Parameters:
        forceRenew -
        Throws:
        AblyException
      • getAuthorizationHeader

        public java.lang.String getAuthorizationHeader()
      • setClientId

        public void setClientId​(java.lang.String clientId)
                         throws AblyException
        Set the clientId, after first initialisation in the construction of the library therefore an existing null value is significant - it means that ClientOptions.clientId was null
        Parameters:
        clientId -
        Throws:
        AblyException
      • checkClientId

        public java.lang.String checkClientId​(BaseMessage msg,
                                              boolean allowNullClientId,
                                              boolean connected)
                                       throws AblyException
        Verify that a message, possibly containing a clientId, is compatible with Auth.clientId if it is set
        Parameters:
        msg -
        allowNullClientId - true if it is ok for there to be no resolved clientId
        connected - true if connected; if false it is ok for the library to be unidentified
        Returns:
        the resolved clientId
        Throws:
        AblyException
      • serverTimestamp

        public long serverTimestamp()
        Using time delta obtained before guess current server time
      • clearCachedServerTime

        public void clearCachedServerTime()
        For testing purposes we need method to clear cached timeDelta