Sha256: 31431c8ccff965920a17e2cb8b4f6fa35a1041166da460d9b6426866afc531e9
Contents?: true
Size: 1.14 KB
Versions: 9
Compression:
Stored size: 1.14 KB
Contents
# frozen_string_literal: true require 'digest/md5' module Uploadcare module Param # This object returns headers needed for authentication # This authentication method is more secure, but more tedious class SecureAuthHeader # @see https://uploadcare.com/docs/api_reference/rest/requests_auth/#auth-uploadcare 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 class << self 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 def timestamp Time.now.gmtime.strftime('%a, %d %b %Y %H:%M:%S GMT') end end end end end
Version data entries
9 entries across 9 versions & 1 rubygems