使用 oAuth 令牌通过 HTTParty 连接到 Xero API 时出现 Headers 问题

Issue with Headers when using oAuth token to connect to Xero API via HTTParty

我正在尝试通过 Public 应用程序连接到 Xero API,并且我有一个单独的进程执行 oAuth 流程,该流程存储令牌和令牌机密然后我转身在这个脚本中使用。

我的问题是当我在 HTTParty 调用中使用该令牌时,我不断收到 Consumer_key_unknown 错误,我不确定为什么。

脚本;

require 'httparty'

def nonce_generator()
  random = Random.new
  random.rand(100000000000)
end

//statics for testing
XERO_API_URL = 'https://api.xero.com/api.xro/2.0/'
TOKEN = "token received back from initial oauth process"
TOKEN_SECRET = "token secret received back from initial oauth process"
XERO_CONS_KEY = "my cons key per Xero Developer/Applications page"
XERO_CONS_SECRET = "my cons secret per Xero Developer/Applications page"
AUTH = "oauth_consumer_key=#{XERO_CONS_KEY}&
    oauth_token=#{TOKEN}&
    oauth_token_secret=#{TOKEN_SECRET}&
    oauth_signature_method=RSA-SHA1&
    oauth_timestamp=#{Time.now.to_i}&
    oauth_nonce=#{nonce_generator()}"

//test it works
xero_accounts =  HTTParty.get("#{XERO_API_URL}/accounts", :headers => { "Authorization" => AUTH }, "Accept" => "application/json")

注意:为了便于查看,我在这里将 AUTH 分成多行,它们都在我的脚本中的一行中。

我试过将 AUTH 换成两者之一;

AUTH = "Token #{TOKEN}"
AUTH = "Bearer #{TOKEN}"

没有效果。我在 Kounta API 中使用了类似的脚本,它通过 Bearer 令牌工作。

我考虑过使用 Xeroizer/Xero Gateway gem,但两者的构建目的都是为您执行 oAuth 并继续推进,而我已经将其作为一个单独的过程完成。

欢迎大家提出意见!

放弃尝试以这种方式解决问题并筛选 gem 直到我找到一个可以正常工作的访问令牌授权方法;

require 'xeroizer'

client = Xeroizer::PublicApplication.new(XERO_CONS_KEY, XERO_CONS_SECRET)
client.authorize_from_access(TOKEN, TOKEN_SECRET)

puts client.Organisation.all