Created
June 16, 2011 15:21
-
-
Save bjhess/1029468 to your computer and use it in GitHub Desktop.
Getting Xero Partner app to work on a Mac (from Xero)
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
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') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.