lib/omniauth/strategies/oauth2.rb in oa-oauth-0.1.3 vs lib/omniauth/strategies/oauth2.rb in oa-oauth-0.1.4
- old
+ new
@@ -6,28 +6,42 @@
module OmniAuth
module Strategies
class OAuth2
include OmniAuth::Strategy
+ attr_accessor :options, :client
+
+ class CallbackError < StandardError
+ attr_accessor :error, :error_reason, :error_uri
+
+ def initialize(error, error_reason=nil, error_uri=nil)
+ self.error = error
+ self.error_reason = error_reason
+ self.error_uri = error_uri
+ end
+ end
+
def initialize(app, name, client_id, client_secret, options = {})
super(app, name)
- @options = options
- @client = ::OAuth2::Client.new(client_id, client_secret, options)
+ self.options = options
+ self.client = ::OAuth2::Client.new(client_id, client_secret, options)
end
protected
-
- attr_accessor :client
-
- def request_phase(options = {})
+
+ def request_phase
redirect client.web_server.authorize_url({:redirect_uri => callback_url}.merge(options))
end
def callback_phase
+ if request.params['error']
+ raise CallbackError.new(request.params['error'], request.params['error_description'] || request.params['error_reason'], request.params['error_uri'])
+ end
+
verifier = request.params['code']
@access_token = client.web_server.get_access_token(verifier, :redirect_uri => callback_url)
super
- rescue ::OAuth2::HTTPError, ::OAuth2::AccessDenied => e
+ rescue ::OAuth2::HTTPError, ::OAuth2::AccessDenied, CallbackError => e
fail!(:invalid_credentials, e)
end
def auth_hash
OmniAuth::Utils.deep_merge(super, {