我正在尝试使用 OmniAuth 来处理小型 Sinatra 应用程序的 OAuth 流程。我可以让 37signals Oauth 完美运行,但我也在尝试为 Freshbooks Oauth 创建策略。
不幸的是,Freshbooks 需要 OAuth 请求才能转到用户特定的子域。我正在获取子域作为输入,然后我需要对所有请求持续使用客户特定的站点 URL。
这是我到目前为止所尝试的。问题是新站点值在第一个请求之后不会持续存在。
必须有一种简单的方法来实现这一点,但我很难过。
#Here's the setup -
def initialize(app, consumer_key, consumer_secret, subdomain='api')
super(app, :freshbooks, consumer_key, consumer_secret,
:site => "https://"+subdomain+".freshbooks.com",
:signature_method => 'PLAINTEXT',
:request_token_path => "/oauth/oauth_request.php",
:access_token_path => "/oauth/oauth_access.php",
:authorize_path => "/oauth/oauth_authorize.php"
)
end
def request_phase
#Here's the overwrite -
consumer.options[:site] = "https://"+request.env["rack.request.form_hash"]["subdomain"]+".freshbooks.com"
request_token = consumer.get_request_token(:oauth_callback => callback_url)
(session[:oauth]||={})[name.to_sym] = {:callback_confirmed => request_token.callback_confirmed?,
:request_token => request_token.token,
:request_secret => request_token.secret}
r = Rack::Response.new
r.redirect request_token.authorize_url
r.finish
end