1
0
Fork 0
mirror of https://github.com/omniauth/omniauth.git synced 2022-11-09 12:31:49 -05:00

Adds strategy parameter with the strategy name in the failure end point redirect callback.

This commit is contained in:
slainer68 2012-04-10 20:42:02 +02:00
parent 103256292b
commit a364cf4bea
4 changed files with 33 additions and 28 deletions

View file

@ -22,15 +22,20 @@ module OmniAuth
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 file

@ -4,7 +4,7 @@ describe OmniAuth::FailureEndpoint do
subject{ OmniAuth::FailureEndpoint }
context 'development' do
before do
before do
@rack_env = ENV['RACK_ENV']
ENV['RACK_ENV'] = 'development'
end
@ -24,8 +24,9 @@ describe OmniAuth::FailureEndpoint do
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 @@ describe OmniAuth::FailureEndpoint do
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 file

@ -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 @@ describe OmniAuth::Strategy do
OmniAuth.config.test_mode = false
end
end
end
end

View file

@ -13,3 +13,21 @@ RSpec.configure do |config|
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