Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion lib/omniauth/strategies/oauth2.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ def self.inherited(subclass)
option :token_options, []
option :auth_token_params, {}
option :provider_ignores_state, false
option :state_length, 48

attr_accessor :access_token

Expand All @@ -49,7 +50,8 @@ def request_phase
end

def authorize_params
options.authorize_params[:state] = SecureRandom.hex(24)
state_length = options[:state_length]
options.authorize_params[:state] = SecureRandom.hex(state_length / 2 + 1)[0...state_length]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe will be better to use

params = options.authorize_params.merge(options_for("authorize"))

and update

       def options_for(option)
         hash = {}
         options.send(:"#{option}_options").select { |key| options[key] }.each do |key|
           hash[key.to_sym] = options[key].respond_to?(:call) ? options[key].call(env) : options[key]
         end
         hash
       end

so, allow to use a Proc for generation of state

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tyamagu2 , see: #97

example with rails + devise:

  config.omniauth :instagram,
    'client_id',
    'client_secret',
    state:             Proc.new { |env| FooBar.state(env) },
    authorize_options: [:scope, :state]

params = options.authorize_params.merge(options_for("authorize"))
if OmniAuth.config.test_mode
@env ||= {}
Expand Down