Pre-call the app on request phase for configuration hook. Closes #62
This commit is contained in:
parent
e72f72accc
commit
889004dbde
|
@ -6,7 +6,7 @@ module OmniAuth
|
|||
|
||||
def self.included(base)
|
||||
base.class_eval do
|
||||
attr_reader :app, :name, :env, :options
|
||||
attr_reader :app, :name, :env, :options, :response
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -23,6 +23,8 @@ module OmniAuth
|
|||
def call!(env)
|
||||
@env = env
|
||||
if request.path == request_path
|
||||
status, headers, body = *call_app!
|
||||
@response = Rack::Response.new(body, status, headers)
|
||||
request_phase
|
||||
elsif request.path == callback_path
|
||||
callback_phase
|
||||
|
|
|
@ -3,7 +3,9 @@ require 'spec_helper'
|
|||
class ExampleStrategy
|
||||
include OmniAuth::Strategy
|
||||
def call(env); self.call!(env) end
|
||||
attr_reader :last_env
|
||||
def request_phase
|
||||
@last_env = env
|
||||
raise "Request Phase"
|
||||
end
|
||||
def callback_phase
|
||||
|
@ -38,6 +40,15 @@ describe OmniAuth::Strategy do
|
|||
end
|
||||
end
|
||||
|
||||
it 'should be able to modify the env on the fly before the request_phase' do
|
||||
app = lambda{|env| env['omniauth.boom'] = true; [404, {}, ['Whatev']] }
|
||||
|
||||
s = ExampleStrategy.new(app, 'test')
|
||||
lambda{ s.call({'PATH_INFO' => '/auth/test'}) }.should raise_error("Request Phase")
|
||||
s.response.status.should == 404
|
||||
s.last_env.should be_key('omniauth.boom')
|
||||
end
|
||||
|
||||
context 'custom paths' do
|
||||
it 'should use a custom request_path if one is provided' do
|
||||
@options = {:request_path => '/awesome'}
|
||||
|
|
Loading…
Reference in New Issue