Skip to content
This repository has been archived by the owner on Apr 24, 2020. It is now read-only.

Commit

Permalink
Support hitting the callback with oauth_token/oauth_token_secret
Browse files Browse the repository at this point in the history
This is useful for situations such as Twitter's reverse auth for iOS.
  • Loading branch information
nevir committed Aug 30, 2012
1 parent 43008e4 commit 966db34
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
5 changes: 5 additions & 0 deletions lib/omniauth/strategies/oauth.rb
Expand Up @@ -43,6 +43,11 @@ def request_phase
end end


def callback_phase def callback_phase
if request['oauth_token'] && request['oauth_token_secret']
@access_token = ::OAuth::AccessToken.from_hash(consumer, Hashie::Mash.new(request.params))
return super
end

raise OmniAuth::NoSessionError.new("Session Expired") if session['oauth'].nil? raise OmniAuth::NoSessionError.new("Session Expired") if session['oauth'].nil?


request_token = ::OAuth::RequestToken.new(consumer, session['oauth'][name.to_s].delete('request_token'), session['oauth'][name.to_s].delete('request_secret')) request_token = ::OAuth::RequestToken.new(consumer, session['oauth'][name.to_s].delete('request_token'), session['oauth'][name.to_s].delete('request_secret'))
Expand Down
14 changes: 14 additions & 0 deletions spec/omniauth/strategies/oauth_spec.rb
Expand Up @@ -144,4 +144,18 @@ def session
last_request.env['omniauth.error.type'] = :session_expired last_request.env['omniauth.error.type'] = :session_expired
end end
end end

describe '/auth/{name}/callback with oauth_token and oauth_token_secret' do
before do
get '/auth/example.org/callback', {:oauth_token => 'yourtoken', :oauth_token_secret => 'soopersekret', :user_id => 123}, {'rack.session' => {}}
end

it 'should succeed' do
last_request.env['omniauth.auth']['credentials']['token'].should == 'yourtoken'
last_request.env['omniauth.auth']['credentials']['secret'].should == 'soopersekret'
last_request.env['omniauth.auth']['provider'].should == 'example.org'
last_request.env['omniauth.auth']['extra']['access_token'].should be_kind_of(OAuth::AccessToken)
last_request.env['omniauth.auth']['extra']['access_token'].params['user_id'].should == '123'
end
end
end end

0 comments on commit 966db34

Please sign in to comment.