Skip to content

Commit

Permalink
Closes omniauth#37. Deprecates using rack.auth in favor of omniauth.auth
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Bleigh committed Oct 10, 2010
1 parent 5e8eb28 commit 49edb68
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 19 deletions.
6 changes: 3 additions & 3 deletions oa-basic/lib/omniauth/strategies/http_basic.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@ def get_credentials

def perform
@response = perform_authentication(endpoint)
@env['rack.auth'] = auth_hash
@env['omniauth.auth'] = auth_hash
@env['REQUEST_METHOD'] = 'GET'
@env['PATH_INFO'] = "#{OmniAuth.config.path_prefix}/#{name}/callback"

@app.call(@env)
call_app!
rescue RestClient::Request::Unauthorized => e
fail!(:invalid_credentials, e)
end
Expand Down
6 changes: 3 additions & 3 deletions oa-core/lib/omniauth/strategies/password.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ def request_phase
return fail!(:password_mismatch) if request[:password_confirmation] && request[:password_confirmation] != '' && request[:password] != request[:password_confirmation]
env['REQUEST_METHOD'] = 'GET'
env['PATH_INFO'] = request.path + '/callback'
env['rack.auth'] = auth_hash(encrypt(request[:identifier], request[:password]))
@app.call(env)
env['omniauth.auth'] = auth_hash(encrypt(request[:identifier], request[:password]))
call_app!
end

def auth_hash(crypted_password)
Expand All @@ -33,7 +33,7 @@ def auth_hash(crypted_password)
end

def callback_phase
@app.call(env)
call_app!
end

def encrypt(identifier, password)
Expand Down
15 changes: 11 additions & 4 deletions oa-core/lib/omniauth/strategy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def call!(env)
if respond_to?(:other_phase)
other_phase
else
@app.call(env)
call_app!
end
end
end
Expand All @@ -39,8 +39,15 @@ def request_phase
end

def callback_phase
env['rack.auth'] = auth_hash
@app.call(env)
env['omniauth.auth'] = auth_hash
call_app!
end

def call_app!
@env['rack.auth'] = env['omniauth.auth'] if env.key?('omniauth.auth')
@env['rack.auth.error'] = env['omniauth.error'] if env.key?('omniauth.error')

@app.call(@env)
end

def auth_hash
Expand Down Expand Up @@ -78,7 +85,7 @@ def redirect(uri)
def user_info; {} end

def fail!(message_key, exception = nil)
self.env['rack.auth.error'] = exception
self.env['omniauth.error'] = exception
OmniAuth.config.on_failure.call(self.env, message_key.to_sym)
end
end
Expand Down
6 changes: 3 additions & 3 deletions oa-core/lib/omniauth/test/strategy_macros.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,19 @@ module StrategyMacros

def sets_an_auth_hash
it 'should set an auth hash' do
last_request.env['rack.auth'].should be_kind_of(Hash)
last_request.env['omniauth.auth'].should be_kind_of(Hash)
end
end

def sets_provider_to(provider)
it "should set the provider to #{provider}" do
(last_request.env['rack.auth'] || {})['provider'].should == provider
(last_request.env['omniauth.auth'] || {})['provider'].should == provider
end
end

def sets_uid_to(uid)
it "should set the UID to #{uid}" do
(last_request.env['rack.auth'] || {})['uid'].should == uid
(last_request.env['omniauth.auth'] || {})['uid'].should == uid
end
end

Expand Down
2 changes: 1 addition & 1 deletion oa-core/spec/omniauth/strategies/password_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def strategy
sets_an_auth_hash
sets_provider_to 'password'
it 'should set the UID to an opaque identifier' do
uid = last_request.env['rack.auth']['uid']
uid = last_request.env['omniauth.auth']['uid']
uid.should_not be_nil
uid.should_not =~ /jerome/
uid.should_not =~ /my password/
Expand Down
3 changes: 1 addition & 2 deletions oa-enterprise/lib/omniauth/strategies/ldap.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,10 @@ def perform
@adaptor.bind(:bind_dn => request.POST['username'], :password => request.POST['password'])
@ldap_user_info = @adaptor.search(:filter => Net::LDAP::Filter.eq(@adaptor.uid, request.POST['username']),:limit => 1)
@user_info = self.class.map_user(@@config, @ldap_user_info)
request.POST['auth'] = auth_hash
@env['REQUEST_METHOD'] = 'GET'
@env['PATH_INFO'] = "#{OmniAuth.config.path_prefix}/#{name}/callback"

@app.call(@env)
call_app!
rescue Exception => e
fail!(:invalid_credentials, e)
end
Expand Down
6 changes: 3 additions & 3 deletions oa-oauth/spec/omniauth/strategies/oauth_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ def app
use OmniAuth::Builder do
provider :oauth, 'example.org', 'abc', 'def', :site => 'https://api.example.org'
end
run lambda { |env| [200, {'Content-Type' => 'text/plain'}, [env.key?('rack.auth').to_s]] }
run lambda { |env| [200, {'Content-Type' => 'text/plain'}, [env.key?('omniauth.auth').to_s]] }
}.to_app
end

Expand Down Expand Up @@ -43,8 +43,8 @@ def session
end

it 'should exchange the request token for an access token' do
last_request.env['rack.auth']['provider'].should == 'example.org'
last_request.env['rack.auth']['extra']['access_token'].should be_kind_of(OAuth::AccessToken)
last_request.env['omniauth.auth']['provider'].should == 'example.org'
last_request.env['omniauth.auth']['extra']['access_token'].should be_kind_of(OAuth::AccessToken)
end

it 'should call through to the master app' do
Expand Down

0 comments on commit 49edb68

Please sign in to comment.