Skip to content

Commit 3584f6a

Browse files
authored
Merge pull request #25 from adifsgaid/fix-rack-3-compatibility
2 parents b6cfec0 + b2c5ddb commit 3584f6a

File tree

4 files changed

+42
-2
lines changed

4 files changed

+42
-2
lines changed

lib/omniauth-oauth/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
module OmniAuth
22
module OAuth
3-
VERSION = "1.2.0"
3+
VERSION = "1.2.1"
44
end
55
end

lib/omniauth/strategies/oauth.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ def callback_phase # rubocop:disable MethodLength
4848

4949
opts = {}
5050
if session["oauth"][name.to_s]["callback_confirmed"]
51-
opts[:oauth_verifier] = request["oauth_verifier"]
51+
opts[:oauth_verifier] = request.respond_to?(:params) ? request.params["oauth_verifier"] : request["oauth_verifier"]
5252
else
5353
opts[:oauth_callback] = callback_url
5454
end

omniauth-oauth.gemspec

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ Gem::Specification.new do |gem|
1010

1111
gem.add_dependency "omniauth", ">= 1.0", "< 3"
1212
gem.add_dependency "oauth"
13+
gem.add_dependency "rack", ">= 1.6.2", "< 4"
1314

1415
gem.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) }
1516
gem.files = `git ls-files`.split("\n")

spec/omniauth/strategies/oauth_spec.rb

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,45 @@ def session
132132
end
133133
end
134134

135+
describe "/auth/{name}/callback with Rack 2.x and 3.x" do
136+
before do
137+
stub_request(:post, "https://api.example.org/oauth/access_token").
138+
to_return(:body => "oauth_token=yourtoken&oauth_token_secret=yoursecret")
139+
end
140+
141+
context "Rack 2.x style request" do
142+
before do
143+
get "/auth/example.org/callback", {"oauth_verifier" => "dudeman"}, "rack.session" => {"oauth" => {"example.org" => {"callback_confirmed" => true, "request_token" => "yourtoken", "request_secret" => "yoursecret"}}}
144+
end
145+
146+
it "should exchange the request token for an access token" do
147+
expect(last_request.env["omniauth.auth"]["provider"]).to eq("example.org")
148+
expect(last_request.env["omniauth.auth"]["extra"]["access_token"]).to be_kind_of(OAuth::AccessToken)
149+
end
150+
151+
it "should call through to the master app" do
152+
expect(last_response.body).to eq("true")
153+
end
154+
end
155+
156+
context "Rack 3.x style request" do
157+
before do
158+
# Simulate Rack 3.x behavior by putting oauth_verifier in the params
159+
allow_any_instance_of(Rack::Request).to receive(:params).and_return({"oauth_verifier" => "dudeman"})
160+
get "/auth/example.org/callback", {}, "rack.session" => {"oauth" => {"example.org" => {"callback_confirmed" => true, "request_token" => "yourtoken", "request_secret" => "yoursecret"}}}
161+
end
162+
163+
it "should exchange the request token for an access token" do
164+
expect(last_request.env["omniauth.auth"]["provider"]).to eq("example.org")
165+
expect(last_request.env["omniauth.auth"]["extra"]["access_token"]).to be_kind_of(OAuth::AccessToken)
166+
end
167+
168+
it "should call through to the master app" do
169+
expect(last_response.body).to eq("true")
170+
end
171+
end
172+
end
173+
135174
describe "/auth/{name}/callback with expired session" do
136175
before do
137176
stub_request(:post, "https://api.example.org/oauth/access_token").

0 commit comments

Comments
 (0)