Skip to content

Instantly share code, notes, and snippets.

@flukeout
Created November 20, 2009 20:32
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 flukeout/239756 to your computer and use it in GitHub Desktop.
Save flukeout/239756 to your computer and use it in GitHub Desktop.
Zeep Mobile - Generating the authentication header - Ruby
#!/usr/bin/env ruby -wKU
# Created by Simon Wex (simon@zeepmobile.com) 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