【发布时间】:2016-09-21 18:09:40
【问题描述】:
我正在使用带有 oauth 的 rest-client,正在生成 oauth 标头,但 hmac-sha1 签名无效。
服务器不接受签名编码,返回 401 oauth_problem signature_invalid。
oauth_signature="9aOk2oM2%2FczpqHBJ95MhcF%2Bp6XU%3D",
oauth_signature_method="HMAC-SHA1"
在未选中“编码 OAuth 签名”的情况下在 Postman 中运行可以正常工作。 开启此选项后,Postman 给出相同的 401 无效签名。
这是编码问题吗,oauth gem 是否有类似的选项,我该如何设置?
require 'rubygems'
require 'oauth'
require 'rest-client'
# auth keys read in from file
base_uri = 'http://dockerized-magento.local'
base_path = 'api/rest'
base_url = base_uri + '/' + base_path + '/customers' # the fix
@consumer=OAuth::Consumer.new auth['consumer_key'],
auth['consumer_secret'],
{:site => base_url } # the fix
# this was the error
# {:site=> base_uri + base_path}
# Create the access_token for all traffic
access_token = OAuth::AccessToken.new(@consumer,
auth['token'], auth['token_secret'])
RestClient.add_before_execution_proc do |req, params|
access_token.sign! req
end
response = RestClient::Request.execute(method: :get, url: url,
timeout: 60,
headers: {'Cache-Control' => 'no-cache'})
rest-client 2.0 与 oauth gem 0.5.1.,ruby 2.2.2,不使用 ruby-on-rails
【问题讨论】:
标签: ruby oauth rest-client