-
public class AuthToken-generation and authentication operations for the Ably API. See the Ably Authentication documentation for details of the authentication methods available. Creates Ably TokenRequest objects and obtains Ably Tokens from Ably to subsequently issue to less trusted clients.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description public enumAuth.AuthMethodAuthentication methods
public classAuth.AuthOptionsPasses authentication-specific properties in authentication requests to Ably.Properties set using AuthOptions are used instead of the default values set when the client libraryis instantiated, as opposed to being merged with them.
public classAuth.TokenDetailsContains an Ably Token and its associated metadata.
public classAuth.TokenParamsDefines the properties of an Ably Token.
public classAuth.TokenRequestContains the properties of a request for a token to Ably.Tokens are generated using requestToken.
public interfaceAuth.AuthUpdateResultAn interface providing update result for onAuthUpdated
public interfaceAuth.RenewAuthResultAn interface providing completion callbackk for renewAuth
public interfaceAuth.TokenCallbackAn interface implemented by a callback that provides either tokens,or signed token requests, in response to a request with given token params.
-
Field Summary
Fields Modifier and Type Field Description public StringclientIdprivate Auth.AuthOptionsauthOptionsprivate StringbasicCredentialsprivate Auth.TokenDetailstokenDetailsprivate StringencodedTokenpublic final static StringWILDCARD_CLIENTID
-
Method Summary
Modifier and Type Method Description voidsetClientId(String clientId)Set the clientId, after first initialisation in the construction of the librarytherefore an existing null value is significant - it means that ClientOptions. Auth.AuthOptionsgetAuthOptions()Get (a copy of) auth options currently set in this Auth. StringgetBasicCredentials()Get the credentials for HTTP basic auth, if available. Auth.TokenDetailsgetTokenDetails()voidsetTokenDetails(String token)StringgetEncodedToken()Auth.TokenDetailsauthorize(Auth.TokenParams params, Auth.AuthOptions options)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. Auth.TokenDetailsauthorise(Auth.TokenParams params, Auth.AuthOptions options)Alias of authorize() (0. Auth.TokenDetailsrequestToken(Auth.TokenParams params, Auth.AuthOptions tokenOptions)Calls the requestToken REST API endpoint to obtain an Ably Tokenaccording to the specified TokenParams and AuthOptions. Auth.TokenRequestcreateTokenRequest(Auth.TokenParams params, Auth.AuthOptions options)Creates and signs an Ably TokenRequest based on the specified(or if none specified, the client library stored) TokenParams and AuthOptions.Note this can only be used when the API key value is available locally. Auth.AuthMethodgetAuthMethod()Get the authentication method for this library instance. Array<Param>getAuthParams()Get query params representing the current authentication method and credentials. Auth.TokenDetailsrenew()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. voidrenewAuth(Auth.RenewAuthResult result)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. voidonAuthError(ErrorInfo err)static longtimestamp()Auth.TokenDetailsassertValidToken()voidassertAuthorizationHeader(boolean forceRenew)Get the Authorization header, forcing the creation of a new token if requested StringgetAuthorizationHeader()StringcheckClientId(BaseMessage msg, boolean allowNullClientId, boolean connected)Verify that a message, possibly containing a clientId,is compatible with Auth. longserverTimestamp()Using time delta obtained before guess current server time voidclearCachedServerTime()For testing purposes we need method to clear cached timeDelta -
-
Method Detail
-
setClientId
void setClientId(String clientId)
Set the clientId, after first initialisation in the construction of the librarytherefore an existing null value is significant - it means that ClientOptions.clientIdwas null
-
getAuthOptions
Auth.AuthOptions getAuthOptions()
Get (a copy of) auth options currently set in this Auth.
-
getBasicCredentials
String getBasicCredentials()
Get the credentials for HTTP basic auth, if available.
-
getTokenDetails
Auth.TokenDetails getTokenDetails()
-
setTokenDetails
void setTokenDetails(String token)
-
getEncodedToken
String getEncodedToken()
-
authorize
Auth.TokenDetails authorize(Auth.TokenParams params, Auth.AuthOptions options)
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 any TokenParams and AuthOptions passed in as the new defaults,to be used for all subsequent implicit or explicit token requests.Any TokenParams and AuthOptions objects passed in entirely replace,as opposed to being merged with, the current client library saved values.
Spec: RSA10
- Parameters:
params- A TokenParams object.options- An AuthOptions object.
-
authorise
@Deprecated() Auth.TokenDetails authorise(Auth.TokenParams params, Auth.AuthOptions options)
Alias of authorize() (0.9 RSA10l)
-
requestToken
Auth.TokenDetails requestToken(Auth.TokenParams params, Auth.AuthOptions tokenOptions)
Calls the requestToken REST API endpoint to obtain an Ably Tokenaccording to the specified TokenParams and AuthOptions.Both TokenParams and AuthOptions are optional.When omitted or null, the default token parameters and authentication options for the client library are used,as specified in the ClientOptions when 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 Ably TokenRequest may be issued to clients in favor of a token,see Token Authentication explained.
Spec: RSA8e
- Parameters:
params- : A TokenParams object.tokenOptions- : An AuthOptions object.
-
createTokenRequest
Auth.TokenRequest createTokenRequest(Auth.TokenParams params, Auth.AuthOptions options)
Creates and signs an Ably TokenRequest based on the specified(or if none specified, the client library stored) TokenParams and AuthOptions.Note this can only be used when the API key value is available locally.Otherwise, the Ably TokenRequest must be obtained from the key owner.Use this to generate an Ably TokenRequest in order to implement anAbly Token request callback for use by other clients. Both TokenParams and AuthOptions are optional.When omitted or null, the default token parameters and authentication options for the client library are used,as specified in the ClientOptions when 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 Ably TokenRequest may be issued to clients in favor of a token,see Token Authentication explained.
Spec: RSA9
- Parameters:
params- : A TokenParams object.options- : An AuthOptions object.
-
getAuthMethod
Auth.AuthMethod getAuthMethod()
Get the authentication method for this library instance.
-
getAuthParams
Array<Param> getAuthParams()
Get query params representing the current authentication method and credentials.
-
renew
@Deprecated() Auth.TokenDetails renew()
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.
-
renewAuth
void renewAuth(Auth.RenewAuthResult result)
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 completionPlease note that completion callback onCompletion is called on a background thread.
-
onAuthError
void onAuthError(ErrorInfo err)
-
timestamp
static long timestamp()
-
assertValidToken
Auth.TokenDetails assertValidToken()
-
assertAuthorizationHeader
void assertAuthorizationHeader(boolean forceRenew)
Get the Authorization header, forcing the creation of a new token if requested
-
getAuthorizationHeader
String getAuthorizationHeader()
-
checkClientId
String checkClientId(BaseMessage msg, boolean allowNullClientId, boolean connected)
Verify that a message, possibly containing a clientId,is compatible with Auth.clientId if it is set
- Parameters:
allowNullClientId- true if it is ok for there to be no resolved clientIdconnected- true if connected; if false it is ok for the library to be unidentified
-
serverTimestamp
long serverTimestamp()
Using time delta obtained before guess current server time
-
clearCachedServerTime
void clearCachedServerTime()
For testing purposes we need method to clear cached timeDelta
-
-
-
-