2020-05-24 23:13:21 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2021-09-30 23:02:18 +05:30
|
|
|
# See https://github.com/omniauth/omniauth-oauth2/blob/v1.7.1/lib/omniauth/strategies/oauth2.rb#L84-L101
|
|
|
|
# for the original version of this code.
|
|
|
|
#
|
|
|
|
# Note: We need to override `callback_phase` directly (instead of using a module with `include` or `prepend`),
|
|
|
|
# because the method has a `super` call which needs to go to the `OmniAuth::Strategy` module,
|
|
|
|
# and it also deletes `omniauth.state` from the session as a side effect.
|
|
|
|
|
2020-05-24 23:13:21 +05:30
|
|
|
module OmniAuth
|
|
|
|
module Strategies
|
|
|
|
class OAuth2
|
2021-12-11 22:18:48 +05:30
|
|
|
alias_method :original_callback_phase, :callback_phase
|
|
|
|
|
2020-05-24 23:13:21 +05:30
|
|
|
def callback_phase
|
2021-12-11 22:18:48 +05:30
|
|
|
original_callback_phase
|
|
|
|
# Monkey patch #1:
|
2021-09-30 23:02:18 +05:30
|
|
|
#
|
|
|
|
# Also catch errors from Faraday.
|
|
|
|
# See https://github.com/omniauth/omniauth-oauth2/pull/129
|
|
|
|
# and https://github.com/oauth-xx/oauth2/issues/152
|
|
|
|
#
|
|
|
|
# This can be removed with https://gitlab.com/gitlab-org/gitlab/-/issues/340933
|
2020-05-24 23:13:21 +05:30
|
|
|
rescue ::Faraday::TimeoutError, ::Faraday::ConnectionFailed => e
|
|
|
|
fail!(:timeout, e)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|