Class: Uploadcare::Param::SecureAuthHeader
- Inherits:
-
Object
- Object
- Uploadcare::Param::SecureAuthHeader
- 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( = {}) @method = [:method] @body = [:content] || '' @content_type = [:content_type] @uri = make_uri() @date_for_header = { Date: @date_for_header, Authorization: "Uploadcare #{Uploadcare.config.public_key}:#{signature}" } end |
.signature ⇒ Object
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 |
.timestamp ⇒ Object
33 34 35 |
# File 'lib/uploadcare/param/secure_auth_header.rb', line 33 def Time.now.gmtime.strftime('%a, %d %b %Y %H:%M:%S GMT') end |