2013-06-23 62 views
2

我想覆蓋在omniauth寶石中設置的默認範圍。我已經嘗試通過初始化設置範圍,並嘗試將範圍留空。我希望能夠做在omniauth寶石中覆蓋默認範圍設置

/auth/<provider>?scope=<scope> 

爲紐帶,在簽署

然而,不管如何我設置在商

config/initializers/omniauth.rb 

前:

Rails.application.config.middleware.use OmniAuth::Builder do 
    provider :<provider>, <app_uid>, <app_secret>, 
    :scope => "", 
    :client_options => { 
    :site   => "https://api.<provider_url>", 
    :authorize_url => "https://api.<provider_url>/oauth/authorize", 
    :token_url  => "https://api.<provider_url>/oauth/token" 
    } 
end 

它仍然嘗試使用

012中的默認範圍設置發送omniauth/oauth-2請求
omniauth-<provider> gem 

如何通過傳遞給傳遞給提供者的url的作用域參數來覆蓋在gem中聲明的默認作用域?

回答

2

我能夠這樣做使用以下初始化程序。

Rails.application.config.middleware.use OmniAuth::Builder do 
    :<provider>, <app_uid>, <app_secret>, 
    :setup => lambda { |env| env["omniauth.strategy"].options[:scope] = env["rack.session"]["omniauth.params"]["scope"]}, 
    :client_options => { 
    :site   => "https://api.<provider_url>", 
    :authorize_url => "https://api.<provider_url>/oauth/authorize", 
    :token_url  => "https://api.<provider_url>/oauth/token" 
    } 

end 
+0

工作就像一個魅力。做得好。 –