Class: AWSRaw::S3::QueryStringSigner
- Defined in:
- lib/awsraw/s3/query_string_signer.rb
Overview
Generates a signed query string to make an authenticated S3 GET request
The Authorization header method is usually preferable, as implemented in AWSRaw::S3::Signer. However, you may have occasions where you need a simple “download URL”, without having to tell your user-agent (browser, curl, wget, etc) about all the special AWS headers. The query string authentication method is useful in those cases.
Instance Method Summary collapse
- #query_string_hash(url, expires) ⇒ Object
- #sign_with_query_string(url, expires) ⇒ Object
- #string_to_sign(url, expires) ⇒ Object
Methods inherited from Signer
#authorization_header_value, #encoded_signature, #initialize
Constructor Details
This class inherits a constructor from AWSRaw::S3::Signer
Instance Method Details
#query_string_hash(url, expires) ⇒ Object
25 26 27 28 29 30 31 32 33 34 |
# File 'lib/awsraw/s3/query_string_signer.rb', line 25 def query_string_hash(url, expires) string_to_sign = string_to_sign(url, expires) signature = encoded_signature(string_to_sign) { "AWSAccessKeyId" => @access_key_id, "Expires" => expires.to_s, "Signature" => CGI.escape(signature) } end |
#sign_with_query_string(url, expires) ⇒ Object
17 18 19 20 21 22 23 |
# File 'lib/awsraw/s3/query_string_signer.rb', line 17 def sign_with_query_string(url, expires) query_string_hash = query_string_hash(url, expires) uri = URI.parse(url) uri.query = query_string_hash.map { |k,v| "#{k}=#{v}" }.join("&") uri.to_s end |
#string_to_sign(url, expires) ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/awsraw/s3/query_string_signer.rb', line 36 def string_to_sign(url, expires) [ "GET", # Assume user-agent won't send Content-MD5 header "", # Assume user-agent won't send Content-Type header "", expires.to_s, # Assume user-agent won't send any amz headers canonicalized_amz_headers({}), canonicalized_resource(URI.parse(url)) ].flatten.join("\n") end |