mirror of
https://github.com/omniauth/omniauth.git
synced 2022-11-09 12:31:49 -05:00
Add better fail handling for exceptions, add configure and on_failure methods to Builder.
This commit is contained in:
parent
9164a73067
commit
5e8eb2839f
7 changed files with 19 additions and 10 deletions
|
@ -40,8 +40,8 @@ module OmniAuth
|
|||
@env['PATH_INFO'] = "#{OmniAuth.config.path_prefix}/#{name}/callback"
|
||||
|
||||
@app.call(@env)
|
||||
rescue RestClient::Request::Unauthorized
|
||||
fail!(:invalid_credentials)
|
||||
rescue RestClient::Request::Unauthorized => e
|
||||
fail!(:invalid_credentials, e)
|
||||
end
|
||||
|
||||
def perform_authentication(uri, headers = request_headers)
|
||||
|
|
|
@ -7,6 +7,14 @@ module OmniAuth
|
|||
super(&block)
|
||||
end
|
||||
|
||||
def on_failure(&block)
|
||||
OmniAuth.config.on_failure = block
|
||||
end
|
||||
|
||||
def configure(&block)
|
||||
OmniAuth.configure(&block)
|
||||
end
|
||||
|
||||
def provider(klass, *args, &block)
|
||||
if klass.is_a?(Class)
|
||||
middleware = klass
|
||||
|
|
|
@ -77,7 +77,8 @@ module OmniAuth
|
|||
|
||||
def user_info; {} end
|
||||
|
||||
def fail!(message_key)
|
||||
def fail!(message_key, exception = nil)
|
||||
self.env['rack.auth.error'] = exception
|
||||
OmniAuth.config.on_failure.call(self.env, message_key.to_sym)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -50,8 +50,7 @@ module OmniAuth
|
|||
|
||||
@app.call(@env)
|
||||
rescue Exception => e
|
||||
puts e.message
|
||||
fail!(:invalid_credentials)
|
||||
fail!(:invalid_credentials, e)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -24,8 +24,8 @@ module OmniAuth
|
|||
request_token = ::OAuth::RequestToken.new(consumer, session[:oauth][name.to_sym].delete(:request_token), session[:oauth][name.to_sym].delete(:request_secret))
|
||||
@access_token = request_token.get_access_token(:oauth_verifier => request.params['oauth_verifier'])
|
||||
super
|
||||
rescue ::OAuth::Unauthorized
|
||||
fail!(:invalid_credentials)
|
||||
rescue ::OAuth::Unauthorized => e
|
||||
fail!(:invalid_credentials, e)
|
||||
end
|
||||
|
||||
def auth_hash
|
||||
|
|
|
@ -26,8 +26,8 @@ module OmniAuth
|
|||
verifier = request.params['code']
|
||||
@access_token = client.web_server.get_access_token(verifier, :redirect_uri => callback_url)
|
||||
super
|
||||
rescue ::OAuth2::HTTPError => e
|
||||
fail!(:invalid_credentials)
|
||||
rescue ::OAuth2::HTTPError, ::OAuth2::AccessDenied => e
|
||||
fail!(:invalid_credentials, e)
|
||||
end
|
||||
|
||||
def auth_hash
|
||||
|
|
|
@ -14,7 +14,8 @@ module OmniAuth
|
|||
class Twitter < OmniAuth::Strategies::OAuth
|
||||
def initialize(app, consumer_key, consumer_secret)
|
||||
super(app, :twitter, consumer_key, consumer_secret,
|
||||
:site => 'https://api.twitter.com')
|
||||
:site => 'https://api.twitter.com',
|
||||
:authorize_path => '/oauth/authenticate')
|
||||
end
|
||||
|
||||
def auth_hash
|
||||
|
|
Loading…
Add table
Reference in a new issue