Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Refactor request_phase method.

The request params are already accessible in request.params so there is no
need to get them from the session (which is set after the request by omniauth).
https://github.com/intridea/omniauth/blob/deea8f23642734217fc8a91cfe9a09a69595d638/lib/omniauth/strategy.rb#L200

There is also no need to conditionally initialize options[:authorize_params]
and options[:request_params] as these are already set automatically by
omniauth-oauth.
https://github.com/intridea/omniauth-oauth/blob/43008e42b257d9b7c0b98122cf03ce14b021d782/lib/omniauth/strategies/oauth.rb#L16

This refactor will make it really easy to add new params in the future.
  • Loading branch information...
commit 3f8a930acbfc633c0790192c72c26b0826da6634 1 parent ff2546a
@guilhermesimoes guilhermesimoes authored
Showing with 13 additions and 16 deletions.
  1. +13 −16 lib/omniauth/strategies/twitter.rb
View
29 lib/omniauth/strategies/twitter.rb
@@ -5,6 +5,7 @@ module OmniAuth
module Strategies
class Twitter < OmniAuth::Strategies::OAuth
option :name, 'twitter'
+
option :client_options, {:authorize_path => '/oauth/authenticate',
:site => 'https://api.twitter.com',
:proxy => ENV['http_proxy'] ? URI(ENV['http_proxy']) : nil}
@@ -38,26 +39,22 @@ def raw_info
alias :old_request_phase :request_phase
def request_phase
- force_login = session['omniauth.params'] ? session['omniauth.params']['force_login'] : nil
- screen_name = session['omniauth.params'] ? session['omniauth.params']['screen_name'] : nil
- x_auth_access_type = session['omniauth.params'] ? session['omniauth.params']['x_auth_access_type'] : nil
- if force_login && !force_login.empty?
- options[:authorize_params] ||= {}
- options[:authorize_params].merge!(:force_login => 'true')
- end
- if screen_name && !screen_name.empty?
- options[:authorize_params] ||= {}
- options[:authorize_params].merge!(:screen_name => screen_name)
+ %w[force_login screen_name].each do |v|
+ if request.params[v]
+ options[:authorize_params][v.to_sym] = request.params[v]
+ end
end
- if x_auth_access_type
- options[:request_params] ||= {}
- options[:request_params].merge!(:x_auth_access_type => x_auth_access_type)
+
+ %w[x_auth_access_type].each do |v|
+ if request.params[v]
+ options[:request_params][v.to_sym] = request.params[v]
+ end
end
- if session['omniauth.params'] && session['omniauth.params']["use_authorize"] == "true"
- options.client_options.authorize_path = '/oauth/authorize'
+ if request.params['use_authorize'] == 'true'
+ options[:client_options][:authorize_path] = '/oauth/authorize'
else
- options.client_options.authorize_path = '/oauth/authenticate'
+ options[:client_options][:authorize_path] = '/oauth/authenticate'
end
old_request_phase
Please sign in to comment.
Something went wrong with that request. Please try again.