Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

Version 1 Next »

Example of how to sign a request in Ruby (1.9.x)

Ruby
require 'digest/md5'
require "erb"

include ERB::Util

token = "35f94ba7c9bd4b8887b66baa8b566c28"
puts "Token:\n #{token} \n\n"

secret = "2c9e39f72f434a8"
puts "Secret:\n #{secret} \n\n"

request = "http://temporary.meridix.se/iCentrex36/SSO"
puts "Request:\n #{request} \n\n"

username = "basic@sigtunahem.se"
puts "Username:\n #{username} \n\n"

nonce = Random.new.rand(100000...999999).to_s
puts "Nonce:\n #{nonce} \n\n"

timestamp = Time.now.utc.strftime("%Y%m%d%H%M%S");
puts "Timestamp:\n #{timestamp} \n\n"

parameters = 
[
"auth_nonce=" + nonce,
"auth_timestamp=" + timestamp,
"auth_token=" + token,
"u=" + username 
]
parameters = parameters.sort

requestEncoded = url_encode(request);
puts "RequestEncoded:\n #{requestEncoded} \n\n"

parametersConcated = parameters.join("&")
puts "ParametersConcated:\n #{parametersConcated} \n\n"

parametersConcatedEncoded = url_encode(parametersConcated)
puts "ParametersConcatedEncoded:\n #{parametersConcatedEncoded} \n\n"

verbRequestQuery = "GET&" + requestEncoded + "&" + parametersConcatedEncoded + "&" + secret;
puts "VerbRequestQuery:\n #{verbRequestQuery} \n\n"

signature = Digest::MD5.hexdigest(verbRequestQuery)
puts "Signature:\n #{signature} \n\n"

signedRequest = request + "?" + parametersConcated + "&auth_signature=" + signature
puts "SignedRequest:\n #{signedRequest} \n\n"

 
  • No labels