class Roqua::CoreApi::Sessions::HmacAuthRequest
Make a single hmac signed request. HmacAuthRequest.new
(consumer_key
: ‘mykey’, consumer_secret
: ‘…’) HmacAuthRequest.new
(consumer_key
: ‘mykey’, hmac: ‘…’, nonce: ‘…’, timestamp: 1467704698)
Attributes
consumer_key[R]
consumer_secret[R]
nonce[R]
timestamp[R]
Public Class Methods
new(consumer_key: ENV.fetch('CORE_CONSUMER_KEY'), consumer_secret: ENV.fetch('CORE_CONSUMER_SECRET'), timestamp: Time.now.to_i, nonce: SecureRandom.urlsafe_base64(32), hmac: nil, **additional_arguments)
click to toggle source
Calls superclass method
Roqua::CoreApi::Sessions::AuthSession::new
# File lib/roqua/core_api/sessions/hmac_auth_request.rb, line 10 def initialize(consumer_key: ENV.fetch('CORE_CONSUMER_KEY'), consumer_secret: ENV.fetch('CORE_CONSUMER_SECRET'), timestamp: Time.now.to_i, nonce: SecureRandom.urlsafe_base64(32), hmac: nil, **additional_arguments) @consumer_key = consumer_key @consumer_secret = consumer_secret @timestamp = timestamp @nonce = nonce @hmac = hmac super(**additional_arguments) end
Public Instance Methods
access_denied(response)
click to toggle source
handle 401 response.
# File lib/roqua/core_api/sessions/hmac_auth_request.rb, line 29 def access_denied(response) fail Unauthorized, response end
headers(request_method, path, params)
click to toggle source
# File lib/roqua/core_api/sessions/hmac_auth_request.rb, line 24 def headers(request_method, path, params) {'Authorization' => "HMAC #{consumer_key}:#{hmac(request_method, path, params)}:#{nonce}:#{timestamp}"} end
Private Instance Methods
calculate_hmac(request_method, path, params)
click to toggle source
# File lib/roqua/core_api/sessions/hmac_auth_request.rb, line 39 def calculate_hmac(request_method, path, params) checker = Authmac::HmacChecker.new(consumer_secret, digest_function: 'sha256', message_format: :json) params_to_sign = params.merge \ 'request_method' => request_method, 'request_path' => "/api/v1#{path}", 'timestamp' => timestamp.to_s, 'nonce' => nonce, 'consumer_key' => consumer_key checker.sign(params_to_sign.with_indifferent_access) end
hmac(request_method, path, params)
click to toggle source
# File lib/roqua/core_api/sessions/hmac_auth_request.rb, line 35 def hmac(request_method, path, params) @hmac || calculate_hmac(request_method, path, params) end