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



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

def self.call(options = {})
  @method = options[:method]
  @body = options[:content] || ''
  @content_type = options[:content_type]
  @uri = options[:uri]
  @date_for_header = timestamp
  {
    Date: @date_for_header,
    Authorization: "Uploadcare #{Uploadcare.config.public_key}:#{signature}"
  }
end

.signatureObject



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

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



31
32
33
# File 'lib/uploadcare/param/secure_auth_header.rb', line 31

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