Skip to content

Instantly share code, notes, and snippets.

@bjhess
Created June 16, 2011 15:21
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 bjhess/1029468 to your computer and use it in GitHub Desktop.
Save bjhess/1029468 to your computer and use it in GitHub Desktop.
Getting Xero Partner app to work on a Mac (from Xero)
require 'rubygems'
require 'oauth'
require 'oauth/signature/rsa/sha1'
class SSLConsumer < OAuth::Consumer
def initialize *args
@ssl = {}
super
end
def ssl
@ssl
end
protected
def create_http *args
http = super
http.use_ssl = true
http.cert = @ssl[:cert] if @ssl[:cert]
http.key = @ssl[:key] if @ssl[:key]
http.ca_file = @options[:ca_file]
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
http.verify_depth = 5
http
end
end
ctoken = 'consumer-key-goes-here'
csecret = 'consumer-secret-goes-here'
consumer_options = {
:site => "",
:request_token_path => "https://api-partner2.network.xero.com/oauth/RequestToken",
:access_token_path => "https://api-partner2.network.xero.com/oauth/AccessToken",
:authorize_path => "https://api.xero.com/oauth/Authorize",
:signature_method => 'RSA-SHA1',
:ca_file => File.expand_path(File.join(File.dirname(__FILE__), 'ca-certificates.crt')),
:private_key_file => 'privatekey.pem'
}
consumer = SSLConsumer.new(ctoken, csecret, consumer_options)
def read_file file
File.open(file) { |x| return x.read }
nil
end
consumer.ssl[:cert] = OpenSSL::X509::Certificate.new(read_file('entrust.pem'))
consumer.ssl[:key] = OpenSSL::PKey::RSA.new(read_file('entrust-nopass.pem'))
puts "Getting Request Token..."
request_token = consumer.get_request_token()
puts "Request Token: " + request_token.token.to_s
puts "Request Secret: " + request_token.secret.to_s
puts ""
# This only works on OS X
system("open", request_token.authorize_url)
puts 'Enter the verification code from the API:'
verification_code = (gets.chomp).to_i
puts "Getting Access Token..."
access_token = request_token.get_access_token(:oauth_verifier => verification_code)
puts "Access Token: " + access_token.token.to_s
puts "Access Secret: " + access_token.secret.to_s
puts ""
puts "Calling 'Get Organisation'..."
puts access_token.get('https://api-partner2.network.xero.com/api.xro/2.0/Organisation')
@ronanq
Copy link

ronanq commented Jan 12, 2012

This issue was related to an old OpenSSL library on Mac which was causing problems with our client SSL requirements for api-partner.
Note that latest OS updates and Lion have solved these issues for Mac, so api-partner2.network.xero.com has been taken offline.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment