class Ably::Realtime::Auth
Auth
is responsible for authentication with {www.ably.com Ably} using basic or token authentication This {Ably::Realtime::Auth Realtime::Auth
} class wraps the {Ably::Auth Synchronous Ably::Auth
} class in an EventMachine friendly way using Deferrables for all IO. See {Ably::Auth Ably::Auth
} for more information
Find out more about Ably
authentication at: www.ably.com/docs/general/authentication/
@!attribute [r] client_id
(see Ably::Auth#client_id)
@!attribute [r] current_token_details
(see Ably::Auth#current_token_details)
@!attribute [r] token
(see Ably::Auth#token)
@!attribute [r] key
(see Ably::Auth#key)
@!attribute [r] key_name
(see Ably::Auth#key_name)
@!attribute [r] key_secret
(see Ably::Auth#key_secret)
@!attribute [r] options
(see Ably::Auth#options)
@!attribute [r] token_params
(see Ably::Auth#options)
@!attribute [r] using_basic_auth?
(see Ably::Auth#using_basic_auth?)
@!attribute [r] using_token_auth?
(see Ably::Auth#using_token_auth?)
@!attribute [r] token_renewable?
(see Ably::Auth#token_renewable?)
@!attribute [r] authentication_security_requirements_met?
(see Ably::Auth#authentication_security_requirements_met?)
Public Class Methods
Source
# File lib/ably/realtime/auth.rb, line 49 def initialize(client) @client = client @auth_sync = client.rest_client.auth end
Public Instance Methods
Source
# File lib/ably/realtime/auth.rb, line 216 def auth_header(&success_callback) async_wrap(success_callback) do auth_header_sync end end
Auth
header string used in HTTP requests to Ably
Will reauthorize implicitly if required and capable
@return [Ably::Util::SafeDeferrable] @yield [String] HTTP authentication value used in HTTP_AUTHORIZATION header
Source
# File lib/ably/realtime/auth.rb, line 225 def auth_header_sync auth_sync.auth_header end
Synchronous version of {#auth_header}. See {Ably::Auth#auth_header} for method definition @return [String] HTTP authentication value used in HTTP_AUTHORIZATION header
Source
# File lib/ably/realtime/auth.rb, line 239 def auth_params(&success_callback) fail_callback = lambda do |error, deferrable| logger.error { "Failed to authenticate: #{error}" } if error.kind_of?(Ably::Exceptions::BaseAblyException) # Use base exception if it exists carrying forward the status codes deferrable.fail Ably::Exceptions::AuthenticationFailed.new(error.message, nil, nil, error) else deferrable.fail Ably::Exceptions::AuthenticationFailed.new(error.message, 500, Ably::Exceptions::Codes::CLIENT_CONFIGURED_AUTHENTICATION_PROVIDER_REQUEST_FAILED) end end async_wrap(success_callback, fail_callback) do auth_params_sync end end
Auth
params used in URI endpoint for Realtime
connections Will reauthorize implicitly if required and capable
@return [Ably::Util::SafeDeferrable] @yield [Hash] Auth
params for a new Realtime
connection
Source
Source
# File lib/ably/realtime/auth.rb, line 229 def client_id_for_request_sync auth_sync.client_id_for_request end
Source
# File lib/ably/realtime/auth.rb, line 195 def create_token_request(token_params = {}, auth_options = {}, &success_callback) async_wrap(success_callback) do create_token_request_sync(token_params, auth_options) end end
Creates and signs a token request that can then subsequently be used by any client to request a token
@param (see Ably::Auth#create_token_request
) @option (see Ably::Auth#create_token_request
)
@return [Ably::Util::SafeDeferrable] @yield [Models::TokenRequest]
@example
client.auth.create_token_request({ ttl: 3600 }, id: 'asd.asd') do |token_request| token_request #=> Ably::Models::TokenRequest end
Source
# File lib/ably/realtime/auth.rb, line 206 def create_token_request_sync(token_params = {}, auth_options = {}) auth_sync.create_token_request(token_params, auth_options) end
Synchronous version of {#create_token_request}. See {Ably::Auth#create_token_request} for method definition @param (see Ably::Auth#authorize
) @option (see Ably::Auth#authorize
) @return [Ably::Models::TokenRequest]
Source
# File lib/ably/realtime/auth.rb, line 168 def request_token(token_params = {}, auth_options = {}, &success_callback) async_wrap(success_callback) do request_token_sync(token_params, auth_options) end end
Request a {Ably::Models::TokenDetails} which can be used to make authenticated token based requests
@param (see Ably::Auth#request_token
) @option (see Ably::Auth#request_token
)
@return [Ably::Util::SafeDeferrable] @yield [Ably::Models::TokenDetails]
@example
# simple token request using basic auth client = Ably::Rest::Client.new(key: 'key.id:secret') client.auth.request_token do |token_details| token_details #=> Ably::Models::TokenDetails end
Source
# File lib/ably/realtime/auth.rb, line 179 def request_token_sync(token_params = {}, auth_options = {}) auth_sync.request_token(token_params, auth_options) end
Synchronous version of {#request_token}. See {Ably::Auth#request_token} for method definition @param (see Ably::Auth#authorize
) @option (see Ably::Auth#authorize
) @return [Ably::Models::TokenDetails]
Private Instance Methods
Source
Source
# File lib/ably/realtime/auth.rb, line 274 def perform_inline_auth(token) logger.debug { "Performing inline AUTH with Ably using token #{token}" } connection.send_protocol_message( action: Ably::Models::ProtocolMessage::ACTION.Auth.to_i, auth: { access_token: token.token } ) end
Sends an AUTH ProtocolMessage on the existing connection triggering an inline AUTH process, see RTC8a