Skip to content

Commit dcdf698

Browse files
committed
Use verify_authenticity_token directly
By adding a logger and setting the protection_strategy to raise an exception, we can use verify_authenticity_token directly. The main benefit of this is that we will get a more helpful error message attached to the exception.
1 parent 16d5ec6 commit dcdf698

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

lib/omniauth/rails_csrf_protection/token_verifier.rb

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,22 +28,29 @@ def self.config
2828
# our configuration delegate to `ActionController::Base`.
2929
config.each_key do |key| config.delete(key) end
3030

31+
# OmniAuth expects us to raise an exception on auth failure.
32+
self.forgery_protection_strategy = protection_method_class(:exception)
33+
34+
# Logging from ActionController::RequestForgeryProtection is redundant.
35+
# OmniAuth logs basically the same message (from the exception).
36+
self.log_warning_on_csrf_failure = false
37+
3138
def call(env)
3239
dup._call(env)
3340
end
3441

3542
def _call(env)
3643
@request = ActionDispatch::Request.new(env.dup)
3744

38-
unless verified_request?
39-
raise ActionController::InvalidAuthenticityToken
40-
end
45+
verify_authenticity_token
4146
end
4247

4348
private
4449

4550
attr_reader :request
4651
delegate :params, :session, to: :request
52+
53+
delegate :logger, to: OmniAuth
4754
end
4855
end
4956
end

0 commit comments

Comments
 (0)