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.
Constant Summary
Constants inherited from Signer
Instance Method Summary collapse
- #query_string_hash(url, expires, headers = {}) ⇒ Object
- #sign_with_query_string(url, expires, headers = {}) ⇒ Object
- #string_to_sign(url, expires, headers) ⇒ 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, headers = {}) ⇒ 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, headers = {}) string_to_sign = string_to_sign(url, expires, headers) 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, headers = {}) ⇒ 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, headers = {}) query_string_hash = query_string_hash(url, expires, headers) uri = URI.parse(url) uri.query = query_string_hash.map { |k,v| "#{k}=#{v}" }.join("&") uri.to_s end |
#string_to_sign(url, expires, headers) ⇒ Object
36 37 38 39 40 41 42 43 44 45 |
# File 'lib/awsraw/s3/query_string_signer.rb', line 36 def string_to_sign(url, expires, headers) [ "GET", headers["Content-MD5"], headers["Content-Type"], expires.to_s, canonicalized_amz_headers(headers), canonicalized_resource(URI.parse(url)) ].flatten.join("\n") end |