Package io.ably.lib.rest
Class Auth
java.lang.Object
io.ably.lib.rest.Auth
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.- 
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumAuthentication methodsstatic classPasses authentication-specific properties in authentication requests to Ably.static interfaceAn interface providing update result for onAuthUpdatedstatic interfaceAn interface providing completion callbackk for renewAuthstatic interfaceAn interface implemented by a callback that provides either tokens, or signed token requests, in response to a request with given token params.static classContains an Ably Token and its associated metadata.static classDefines the properties of an Ably Token.static classContains the properties of a request for a token to Ably. - 
Field Summary
FieldsModifier and TypeFieldDescriptionA client ID, used for identifying this client when publishing messages or for presence purposes.static final String - 
Method Summary
Modifier and TypeMethodDescriptionvoidassertAuthorizationHeader(boolean forceRenew) Get the Authorization header, forcing the creation of a new token if requestedauthorise(Auth.TokenParams params, Auth.AuthOptions options) Deprecated.authorize(Auth.TokenParams params, Auth.AuthOptions options) Instructs the library to get a new token immediately.checkClientId(BaseMessage msg, boolean allowNullClientId, boolean connected) Verify that a message, possibly containing a clientId, is compatible with Auth.clientId if it is setvoidFor testing purposes we need method to clear cached timeDeltacreateTokenRequest(Auth.TokenParams params, Auth.AuthOptions options) Creates and signs an AblyAuth.TokenRequestbased on the specified (or if none specified, the client library stored)Auth.TokenParamsandAuth.AuthOptions.Get the authentication method for this library instance.Get (a copy of) auth options currently set in this Auth.Param[]Get query params representing the current authentication method and credentials.Get the credentials for HTTP basic auth, if available.voidonAuthError(ErrorInfo err) renew()Deprecated.Because the method returns early before renew() completes and does not provide a completion handler for callers.voidrenewAuth(Auth.RenewAuthResult result) Renew auth credentials.requestToken(Auth.TokenParams params, Auth.AuthOptions tokenOptions) Calls the requestToken REST API endpoint to obtain an Ably Token according to the specifiedAuth.TokenParamsandAuth.AuthOptions.longUsing time delta obtained before guess current server timevoidsetClientId(String clientId) 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 nullstatic long 
- 
Field Details
- 
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
- See Also:
 
 
 - 
 - 
Method Details
- 
authorize
public Auth.TokenDetails authorize(Auth.TokenParams params, Auth.AuthOptions options) throws AblyException Instructs the library to get a new token immediately. When using the realtime client, it upgrades the current realtime connection to use the new token, or if not connected, initiates a connection to Ably, once the new token has been obtained. Also stores anyAuth.TokenParamsandAuth.AuthOptionspassed in as the new defaults, to be used for all subsequent implicit or explicit token requests. AnyAuth.TokenParamsandAuth.AuthOptionsobjects passed in entirely replace, as opposed to being merged with, the current client library saved values.Spec: RSA10
- Parameters:
 - 
params- AAuth.TokenParamsobject. - 
options- AnAuth.AuthOptionsobject. - Returns:
 - A 
Auth.TokenDetailsobject. - Throws:
 AblyException
 - 
authorise
@Deprecated public Auth.TokenDetails authorise(Auth.TokenParams params, Auth.AuthOptions options) throws AblyException Deprecated.Alias of authorize() (0.9 RSA10l)- Throws:
 AblyException
 - 
requestToken
public Auth.TokenDetails requestToken(Auth.TokenParams params, Auth.AuthOptions tokenOptions) throws AblyException Calls the requestToken REST API endpoint to obtain an Ably Token according to the specifiedAuth.TokenParamsandAuth.AuthOptions. BothAuth.TokenParamsandAuth.AuthOptionsare optional. When omitted or null, the default token parameters and authentication options for the client library are used, as specified in theClientOptionswhen the client library was instantiated, or later updated with an explicit authorize request. Values passed in are used instead of, rather than being merged with, the default values. To understand why an AblyAuth.TokenRequestmay be issued to clients in favor of a token, see Token Authentication explained.Spec: RSA8e
- Parameters:
 - 
params- : AAuth.TokenParamsobject. - 
tokenOptions- : AnAuth.AuthOptionsobject. - Returns:
 - A 
Auth.TokenDetailsobject. - Throws:
 AblyException
 - 
createTokenRequest
public Auth.TokenRequest createTokenRequest(Auth.TokenParams params, Auth.AuthOptions options) throws AblyException Creates and signs an AblyAuth.TokenRequestbased on the specified (or if none specified, the client library stored)Auth.TokenParamsandAuth.AuthOptions. Note this can only be used when the API key value is available locally. Otherwise, the AblyAuth.TokenRequestmust be obtained from the key owner. Use this to generate an AblyAuth.TokenRequestin order to implement an Ably Token request callback for use by other clients. BothAuth.TokenParamsandAuth.AuthOptionsare optional. When omitted or null, the default token parameters and authentication options for the client library are used, as specified in theClientOptionswhen the client library was instantiated, or later updated with an explicit authorize request. Values passed in are used instead of, rather than being merged with, the default values. To understand why an AblyAuth.TokenRequestmay be issued to clients in favor of a token, see Token Authentication explained.Spec: RSA9
- Parameters:
 - 
params- : AAuth.TokenParamsobject. - 
options- : AnAuth.AuthOptionsobject. - Returns:
 - A 
Auth.TokenRequestobject. - Throws:
 AblyException
 - 
getAuthMethod
Get the authentication method for this library instance.- Returns:
 
 - 
getBasicCredentials
Get the credentials for HTTP basic auth, if available.- Returns:
 
 - 
getAuthParams
Get query params representing the current authentication method and credentials.- Returns:
 - Throws:
 AblyException
 - 
getAuthOptions
Get (a copy of) auth options currently set in this Auth. - 
renew
Deprecated.Because the method returns early before renew() completes and does not provide a completion handler for callers. Please userenewAuth(io.ably.lib.rest.Auth.RenewAuthResult)insteadRenew auth credentials. Will obtain a new token, even if we already have an apparently valid one. Authorization will use the parameters supplied on construction.- Throws:
 AblyException
 - 
renewAuth
Renew auth credentials. Will obtain a new token, even if we already have an apparently valid one. Authorization will use the parameters supplied on construction.- Parameters:
 - 
result- Asynchronous result the completion Please note that completion callbackAuth.RenewAuthResult.onCompletion(boolean, TokenDetails, ErrorInfo)is called on a background thread. - Throws:
 AblyException
 - 
onAuthError
 - 
timestamp
public static long timestamp() - 
getTokenDetails
 - 
getEncodedToken
 - 
assertValidToken
- Throws:
 AblyException
 - 
assertAuthorizationHeader
Get the Authorization header, forcing the creation of a new token if requested- Parameters:
 - 
forceRenew- - Throws:
 AblyException
 - 
getAuthorizationHeader
 - 
setClientId
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 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 
 -