0
我正在嘗試使用OmniAuth處理小型Sinatra應用程序的OAuth流程。我可以得到37signals Oauth完美的工作,但是我正在嘗試爲Freshbooks Oauth創建一個策略。我如何持久地覆蓋由Rack :: Builder初始化的屬性?
不幸的是,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
忘了提及我必須將:attr_reader中的消費者更改爲omniauth/oauth.rb中的attr_accessor以獲得上述工作。 – 2010-11-06 10:28:08