Skip to content
Browse files

Adds strategy parameter with the strategy name in the failure end poi…

…nt redirect callback.
  • Loading branch information...
1 parent 1032562 commit a364cf4bea31a5c76d9a1b400a56ee5e7a241202 @nicolasblanco nicolasblanco committed
Showing with 33 additions and 28 deletions.
  1. +7 −2 lib/omniauth/failure_endpoint.rb
  2. +6 −5 spec/omniauth/failure_endpoint_spec.rb
  3. +2 −21 spec/omniauth/strategy_spec.rb
  4. +18 −0 spec/spec_helper.rb
View
9 lib/omniauth/failure_endpoint.rb
@@ -22,15 +22,20 @@ def call
end
def raise_out!
- raise env['omniauth.error'] || OmniAuth::Error.new(env['omniauth.error.type'])
+ raise env['omniauth.error'] || OmniAuth::Error.new(env['omniauth.error.type'])
end
def redirect_to_failure
message_key = env['omniauth.error.type']
- new_path = "#{env['SCRIPT_NAME']}#{OmniAuth.config.path_prefix}/failure?message=#{message_key}#{origin_query_param}"
+ new_path = "#{env['SCRIPT_NAME']}#{OmniAuth.config.path_prefix}/failure?message=#{message_key}#{origin_query_param}#{strategy_name_query_param}"
Rack::Response.new(["302 Moved"], 302, 'Location' => new_path).finish
end
+ def strategy_name_query_param
+ return "" unless env['omniauth.error.strategy']
+ "&strategy=#{env['omniauth.error.strategy'].name}"
+ end
+
def origin_query_param
return "" unless env['omniauth.origin']
"&origin=#{CGI.escape(env['omniauth.origin'])}"
View
11 spec/omniauth/failure_endpoint_spec.rb
@@ -4,7 +4,7 @@
subject{ OmniAuth::FailureEndpoint }
context 'development' do
- before do
+ before do
@rack_env = ENV['RACK_ENV']
ENV['RACK_ENV'] = 'development'
end
@@ -24,8 +24,9 @@
end
context 'non-development' do
- let(:env){ {'omniauth.error.type' => 'invalid_request'} }
-
+ let(:env){ {'omniauth.error.type' => 'invalid_request',
+ 'omniauth.error.strategy' => ExampleStrategy.new({}) } }
+
it 'should be a redirect' do
status, head, body = *subject.call(env)
status.should == 302
@@ -33,13 +34,13 @@
it 'should include the SCRIPT_NAME' do
status, head, body = *subject.call(env.merge('SCRIPT_NAME' => '/random'))
- head['Location'].should == '/random/auth/failure?message=invalid_request'
+ head['Location'].should == '/random/auth/failure?message=invalid_request&strategy=test'
end
it 'should respect configured path prefix' do
OmniAuth.config.stub(:path_prefix => '/boo')
status, head, body = *subject.call(env)
- head["Location"].should == '/boo/failure?message=invalid_request'
+ head["Location"].should == '/boo/failure?message=invalid_request&strategy=test'
end
it 'should include the origin (escaped) if one is provided' do
View
23 spec/omniauth/strategy_spec.rb
@@ -1,23 +1,4 @@
-require File.expand_path('../../spec_helper', __FILE__)
-
-class ExampleStrategy
- include OmniAuth::Strategy
- option :name, 'test'
- def call(env); self.call!(env) end
- attr_reader :last_env
- def request_phase
- @fail = fail!(options[:failure]) if options[:failure]
- @last_env = env
- return @fail if @fail
- raise "Request Phase"
- end
- def callback_phase
- @fail = fail!(options[:failure]) if options[:failure]
- @last_env = env
- return @fail if @fail
- raise "Callback Phase"
- end
-end
+require 'spec_helper'
def make_env(path = '/auth/test', props = {})
{
@@ -637,4 +618,4 @@ def make_env(path = '/auth/test', props = {})
OmniAuth.config.test_mode = false
end
end
-end
+end
View
18 spec/spec_helper.rb
@@ -13,3 +13,21 @@
config.extend OmniAuth::Test::StrategyMacros, :type => :strategy
end
+class ExampleStrategy
+ include OmniAuth::Strategy
+ option :name, 'test'
+ def call(env); self.call!(env) end
+ attr_reader :last_env
+ def request_phase
+ @fail = fail!(options[:failure]) if options[:failure]
+ @last_env = env
+ return @fail if @fail
+ raise "Request Phase"
+ end
+ def callback_phase
+ @fail = fail!(options[:failure]) if options[:failure]
+ @last_env = env
+ return @fail if @fail
+ raise "Callback Phase"
+ end
+end

0 comments on commit a364cf4

Please sign in to comment.
Something went wrong with that request. Please try again.