mirror of
https://github.com/omniauth/omniauth.git
synced 2022-11-09 12:31:49 -05:00
Pre-call the app on request phase for configuration hook. Closes #62
This commit is contained in:
parent
e72f72accc
commit
889004dbde
2 changed files with 14 additions and 1 deletions
|
@ -6,7 +6,7 @@ module OmniAuth
|
||||||
|
|
||||||
def self.included(base)
|
def self.included(base)
|
||||||
base.class_eval do
|
base.class_eval do
|
||||||
attr_reader :app, :name, :env, :options
|
attr_reader :app, :name, :env, :options, :response
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -23,6 +23,8 @@ module OmniAuth
|
||||||
def call!(env)
|
def call!(env)
|
||||||
@env = env
|
@env = env
|
||||||
if request.path == request_path
|
if request.path == request_path
|
||||||
|
status, headers, body = *call_app!
|
||||||
|
@response = Rack::Response.new(body, status, headers)
|
||||||
request_phase
|
request_phase
|
||||||
elsif request.path == callback_path
|
elsif request.path == callback_path
|
||||||
callback_phase
|
callback_phase
|
||||||
|
|
|
@ -3,7 +3,9 @@ require 'spec_helper'
|
||||||
class ExampleStrategy
|
class ExampleStrategy
|
||||||
include OmniAuth::Strategy
|
include OmniAuth::Strategy
|
||||||
def call(env); self.call!(env) end
|
def call(env); self.call!(env) end
|
||||||
|
attr_reader :last_env
|
||||||
def request_phase
|
def request_phase
|
||||||
|
@last_env = env
|
||||||
raise "Request Phase"
|
raise "Request Phase"
|
||||||
end
|
end
|
||||||
def callback_phase
|
def callback_phase
|
||||||
|
@ -38,6 +40,15 @@ describe OmniAuth::Strategy do
|
||||||
end
|
end
|
||||||
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
|
context 'custom paths' do
|
||||||
it 'should use a custom request_path if one is provided' do
|
it 'should use a custom request_path if one is provided' do
|
||||||
@options = {:request_path => '/awesome'}
|
@options = {:request_path => '/awesome'}
|
||||||
|
|
Loading…
Reference in a new issue