Class: Uploadcare::Param::SecureAuthHeader

Inherits:
Object
  • Object
show all
Defined in:
lib/uploadcare/param/secure_auth_header.rb

Overview

This object returns headers needed for authentication This authentication method is more secure, but more tedious

Class Method Summary collapse

Class Method Details

.call(options = {}) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/uploadcare/param/secure_auth_header.rb', line 13

def call(options = {})
  @method = options[:method]
  @body = options[:content] || ''
  @content_type = options[:content_type]
  @uri = make_uri(options)

  @date_for_header = timestamp
  {
    Date: @date_for_header,
    Authorization: "Uploadcare #{Uploadcare.config.public_key}:#{signature}"
  }
end

.signatureObject



26
27
28
29
30
31
# File 'lib/uploadcare/param/secure_auth_header.rb', line 26

def signature
  content_md5 = Digest::MD5.hexdigest(@body)
  sign_string = [@method, content_md5, @content_type, @date_for_header, @uri].join("\n")
  digest = OpenSSL::Digest.new('sha1')
  OpenSSL::HMAC.hexdigest(digest, Uploadcare.config.secret_key, sign_string)
end

.timestampObject



33
34
35
# File 'lib/uploadcare/param/secure_auth_header.rb', line 33

def timestamp
  Time.now.gmtime.strftime('%a, %d %b %Y %H:%M:%S GMT')
end