@@ -132,6 +132,45 @@ def session
132
132
end
133
133
end
134
134
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
+
135
174
describe "/auth/{name}/callback with expired session" do
136
175
before do
137
176
stub_request ( :post , "https://api.example.org/oauth/access_token" ) .
0 commit comments