Skip to content
Closed
Show file tree
Hide file tree
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
10 changes: 9 additions & 1 deletion lib/omniauth/strategies/oauth2.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,15 @@ def self.inherited(subclass)
attr_accessor :access_token

def client
::OAuth2::Client.new(options.client_id, options.client_secret, deep_symbolize(options.client_options))
::OAuth2::Client.new(client_id, client_secret, deep_symbolize(options.client_options))
end

def client_id
options.client_id.respond_to?(:call) ? options.client_id.call : options.client_id
end

def client_secret
options.client_secret.respond_to?(:call) ? options.client_secret.call : options.client_secret
end

def callback_url
Expand Down
12 changes: 12 additions & 0 deletions spec/omniauth/strategies/oauth2_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,18 @@ def app
instance = subject.new(app, :client_options => {"ssl" => {"ca_path" => "foo"}})
expect(instance.client.options[:connection_opts][:ssl]).to eq(:ca_path => "foo")
end

it "allows client_id to be passed as a lambda function" do
client_id = proc { "abc" }
instance = subject.new(Object, client_id, "def")
expect(instance.client.id).to eq("abc")
end

it "allows client_secret to be passed as a lambda function" do
client_secret = proc { "def" }
instance = subject.new(Object, "abc", client_secret)
expect(instance.client.secret).to eq("def")
end
end

describe "#authorize_params" do
Expand Down