Module: CanvasDataClient::Helpers::HMACHelper
Instance Method Summary collapse
Methods included from TimeHelper
Instance Method Details
#compute_signature(secret, time, opts = {}) ⇒ Object
6 7 8 9 10 11 |
# File 'lib/canvas_data_client/helpers/hmac_helper.rb', line 6 def compute_signature(secret, time, opts = {}) = (secret, rfc7231(time), opts) digest = OpenSSL::Digest.new('sha256') signature = OpenSSL::HMAC.digest(digest, secret, ) Base64.encode64(signature).strip end |
#headers(key, secret, opts = {}) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/canvas_data_client/helpers/hmac_helper.rb', line 13 def headers(key, secret, opts = {}) raise 'A url must be defined as :path in opts' unless opts[:path] opts[:method] ||= 'get' opts[:content_type] ||= 'application/json' time = Time.now signature = compute_signature(secret, time, opts) { 'Authorization' => "HMACAuth #{key}:#{signature}", 'Date' => rfc7231(time), 'Content-Type' => opts[:content_type] } end |