Created
November 20, 2009 20:32
-
-
Save flukeout/239756 to your computer and use it in GitHub Desktop.
Zeep Mobile - Generating the authentication header - Ruby
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby -wKU | |
# Created by Simon Wex ([email protected]) on 2008-07-12 | |
# Copyright (c) 2008. All rights reserved. | |
# Released under MIT License | |
require 'openssl' | |
require 'base64' | |
require 'time' | |
require 'cgi' | |
API_KEY = 'cef7a046258082993759bade995b3ae8' | |
SECRET_ACCESS_KEY = '19c87eb3e3a28404e7ea8197d4401540' | |
# (ex. Sat, 12 Jul 2008 09:04:28 GMT) | |
http_date = Time.now.httpdate | |
parameters = "user_id=1234&body=#{CGI.escape('Art thou not Romeo, and a Montague?')}" | |
# => "user_id=1234&body=Art+thou+not+Romeo%2C+and+a+Montague%3F" | |
canonical_string = "#{API_KEY}#{http_date}#{parameters}" | |
# => "cef7a046258082993759bade995b3ae8Sat, 12 Jul 2008 09:04:55 GMTuser_id=1234&body=Art+thou+not+Romeo%2C+and+a+Montague%3F" | |
digest = OpenSSL::Digest::Digest.new('sha1') | |
b64_mac = Base64.encode64(OpenSSL::HMAC.digest(digest, SECRET_ACCESS_KEY, canonical_string)).strip | |
authentication = "Zeep #{API_KEY}:#{b64_mac}" | |
puts authentication |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment