diff --git a/lib/omniauth/strategies/oauth2.rb b/lib/omniauth/strategies/oauth2.rb index e445214..468f2aa 100644 --- a/lib/omniauth/strategies/oauth2.rb +++ b/lib/omniauth/strategies/oauth2.rb @@ -94,7 +94,7 @@ def callback_phase # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexi end rescue ::OAuth2::Error, CallbackError => e fail!(:invalid_credentials, e) - rescue ::Timeout::Error, ::Errno::ETIMEDOUT => e + rescue ::Timeout::Error, ::Errno::ETIMEDOUT, ::OAuth2::TimeoutError, ::OAuth2::ConnectionError => e fail!(:timeout, e) rescue ::SocketError => e fail!(:failed_to_connect, e) diff --git a/omniauth-oauth2.gemspec b/omniauth-oauth2.gemspec index a3f7407..8a4cf11 100644 --- a/omniauth-oauth2.gemspec +++ b/omniauth-oauth2.gemspec @@ -3,8 +3,8 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) require "omniauth-oauth2/version" Gem::Specification.new do |gem| - gem.add_dependency "oauth2", [">= 1.4", "< 3"] - gem.add_dependency "omniauth", "~> 2.0" + gem.add_dependency "oauth2", [">= 2.0.2", "< 3"] + gem.add_dependency "omniauth", "~> 2.0" gem.add_development_dependency "bundler", "~> 2.0" diff --git a/spec/omniauth/strategies/oauth2_spec.rb b/spec/omniauth/strategies/oauth2_spec.rb index 68b5d62..ff6176c 100644 --- a/spec/omniauth/strategies/oauth2_spec.rb +++ b/spec/omniauth/strategies/oauth2_spec.rb @@ -140,6 +140,33 @@ def app expect(instance).to receive(:fail!).with(:csrf_detected, anything) instance.callback_phase end + + describe 'exception handlings' do + let(:params) do + {"code" => "code", "state" => state} + end + + before do + allow_any_instance_of(OmniAuth::Strategies::OAuth2).to receive(:build_access_token).and_raise(exception) + end + + { + :invalid_credentials => [OAuth2::Error, OmniAuth::Strategies::OAuth2::CallbackError], + :timeout => [Timeout::Error, Errno::ETIMEDOUT, OAuth2::TimeoutError, OAuth2::ConnectionError], + :failed_to_connect => [SocketError] + }.each do |error_type, exceptions| + exceptions.each do |klass| + context "when #{klass}" do + let(:exception) { klass.new 'error' } + + it do + expect(instance).to receive(:fail!).with(error_type, exception) + instance.callback_phase + end + end + end + end + end end end