Skip to content

Commit 16d5ec6

Browse files
committed
Inherit config from ActionController::Base
By using an inheritable_copy of the config (rather than just redefining the methods) we gain the ability to _override_ the config locally.
1 parent 8688c86 commit 16d5ec6

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

lib/omniauth/rails_csrf_protection/token_verifier.rb

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,20 @@ module RailsCsrfProtection
1313
# authenticity token, you can find the source code at
1414
# https://github.com/rails/rails/blob/v5.2.2/actionpack/lib/action_controller/metal/request_forgery_protection.rb#L217-L240.
1515
class TokenVerifier
16+
# Inherits config from ActionController::Base.
17+
# Define _before_ including ActionController::RequestForgeryProtection.
18+
def self.config
19+
@_config ||= ActionController::Base.config.inheritable_copy
20+
end
21+
1622
include ActiveSupport::Configurable
1723
include ActionController::RequestForgeryProtection
1824

1925
# `ActionController::RequestForgeryProtection` contains a few
2026
# configurable options. As we want to make sure that our configuration is
2127
# the same as what being set in `ActionController::Base`, we should make
22-
# all out configuration methods to delegate to `ActionController::Base`.
23-
config.each_key do |configuration_name|
24-
undef_method configuration_name
25-
define_method configuration_name do
26-
ActionController::Base.config[configuration_name]
27-
end
28-
end
28+
# our configuration delegate to `ActionController::Base`.
29+
config.each_key do |key| config.delete(key) end
2930

3031
def call(env)
3132
dup._call(env)

0 commit comments

Comments
 (0)