Skip to content

Instantly share code, notes, and snippets.

@nbibler
Created October 22, 2008 15:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nbibler/18656 to your computer and use it in GitHub Desktop.
Save nbibler/18656 to your computer and use it in GitHub Desktop.
def valid_request?
query = params.except('action', 'controller')
supplied_signature = query.delete('signature')
return false unless supplied_signature
query = query.sort_by { |k,v| k.downcase }
digest = OpenSSL::Digest::Digest.new('sha1')
hmac = OpenSSL::HMAC.digest(digest, AMAZON_SECRET_KEY, query.to_s)
encoded = Base64.encode64(hmac).chomp
encoded == supplied_signature
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment