Created
August 6, 2012 12:32
-
-
Save mariusbalcytis/3274094 to your computer and use it in GitHub Desktop.
This example calculates request MAC according to "HTTP Authentication: MAC Access Authentication (draft 01)" example from webtopay wallet api (version 2)
This file contains 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
# author: Justas Janauskas, Marius Balčytis | |
# Aug 6, 2012 | |
# | |
# This example calculates request MAC according to "HTTP Authentication: MAC Access Authentication (draft 01)" | |
# example from webtopay wallet api | |
# | |
# ref: http://tools.ietf.org/pdf/draft-ietf-oauth-v2-http-mac-01.pdf | |
# ref: https://www.webtopay.com/wallet/ | |
require 'base64' | |
require 'openssl' | |
normalized_request_string = [ | |
'1343818800', | |
'nQnNaSNyubfPErjRO55yaaEYo9YZfKHN', | |
'GET', | |
'/wallet/rest/v1/payment/10145', | |
'www.webtopay.com', | |
443, | |
nil, | |
nil | |
].join("\n") | |
puts normalized_request_string | |
hmac = OpenSSL::HMAC.digest( | |
OpenSSL::Digest::SHA256.new, | |
'IrdTc8uQodU7PRpLzzLTW6wqZAO6tAMU', | |
normalized_request_string | |
) | |
mac = Base64.encode64(hmac).gsub(/\n/, '') | |
puts "I get \"#{mac}\", example has \"xTCR/i6LKbhXoo4Fe77ECowrn+Q6uUdX7yxwS/lhDWU=\"" | |
# output: | |
# I get "xTCR/i6LKbhXoo4Fe77ECowrn+Q6uUdX7yxwS/lhDWU=", example has "xTCR/i6LKbhXoo4Fe77ECowrn+Q6uUdX7yxwS/lhDWU=" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment